1

Problem: Want to send a custom HTTP header from Windows Phone 7.1 app to ASMX service. The ASMX service is developed by different team.

Solutions tried: There are number of questions & answers on net for this, but nothing seem to work in our case.

Refered HttpRequestMessageProperty, and this.

Client Side Code:

 HttpRequestMessageProperty httpProps = new HttpRequestMessageProperty();
 httpProps.SuppressEntityBody = false;
 httpProps.Headers["HeaderKey"] = "HeaderValue";
 OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpProps;

Service Side Code:

 public string GetHeaderValue()
 {
   var properties = OperationContext.Current.IncomingMessageProperties;
   var property = properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
   string headerValue = property.Headers["HeaderKey"];
   return headerValue;
 }

The "HeaderKey" value is not available on service side. Can any one point us in right direction ? Any help will be appreciated.

Thank you.

Community
  • 1
  • 1
DareToExplore
  • 249
  • 4
  • 15

1 Answers1

0

Ok, So after some hits and misses, the below code worked:

HttpContext.Current.Request.Headers.GetValues("HeaderKey")[0];

The issue with using OperationContext was for ASMX the OperationContext.Current was null. In WCF service, the OperationContext.Current is available.

Thanks @user623396 for your time and efforts. Hope this helps someone out.

DareToExplore
  • 249
  • 4
  • 15