Add custom SOAP headers to Service Reference in Windows Phone 7
in my windows phone 7 app i added a Web Service with "Add service reference". The webservice i want to use excepts some custom soap he开发者_如何学Caders.
How can i add custom headers to to this Service reference?
The WCF Client API is limited on WP7 and I had to go the manual way: Create the HttpWebRequest by hand, set my headers and do all the SOAP stuff on my own.
Custom SOAP headers can be added using the OperationContextScope as follows:
var client = new MySerivceClient();
using (OperationContextScope contextScope = new OperationContextScope(client.InnerChannel))
{
OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("MyHeader",
"", new MyHeader()
{
Value = "ABCDEFG"
}));
client.DoSomeAction();
}
See http://cisforcoder.wordpress.com/2010/12/01/how-to-implement-basic-http-authentication-in-wcf-on-windows-phone-7/ for an example.
精彩评论