I'm actually new in C# and i'm currently building a simple basic Restful WCF webservice which using custom header authorization to proceed request
public void validateHeader(string requestBody)
{
try
{
IncomingWebRequestContext WebReq = WebOperationContext.Current.IncomingRequest;
string requestedURL = WebReq.UriTemplateMatch.RequestUri.OriginalString;
string clientHeader = WebReq.Headers["Authorization"];
if (clientHeader.Substring(0, 3) != "amx")
{
BuildUnauthorizedError("Unknown header");
}
Then i debugged it using Postman , with Authorization Header value added and it works as it should
But the problem is , when i try to debug the WCF using this console app :
try
{
string requestURL = "http://localhost:62146/ORIListenerService.svc/GetDataStatusPembayarans";
var request = (HttpWebRequest)WebRequest.Create(requestURL);
request.Method = "GET";
request.ContentType = "application/json";
request.PreAuthenticate = true;
request.Headers.Add("Authorization","amx 12345");
var response = (HttpWebResponse)request.GetResponse();
the Authorization header is not even received on the WCF
I also tried to fill the header value with random text , and its all received on WCF except the Authorization .. Am i missing something or i just did it all wrong ?
Thanks in advance
i found the solution, it turns out i missed the trailing
/
in my requestURL.My
UriTemplate
in[OperationContract]
is like thisbut i call URL
http://localhost:62146/GetDataStatusPembayarans