开发者

WCF: Use a Message Contract to make a Soap Header

I need to add a soap header to my web service. I plan to use this to validate my clients (Windows Mobile Devices).

I found this link: http://www.c-sharpcorner.com/UploadFile/rog_21/soapheaders05172007120046PM/soapheaders.aspx

Which is exactly what I want to do. But it is not writte开发者_如何学JAVAn for WCF.

I have done some research and I seem to be paralyzed by the number of options.

I basically want to add a simple header to my soap object that will be a user name and password. The client does not use WCF, so the soap header needs to just be a normal soap header.

Any Sample code or shoves in the right direction would be appreciated.


Rather than define a DataContract, use MessageContract

[MessageContract]
public class YourMessageType
{
  // This is in the SOAP Header
  [MessageHeader] public string UserName {get;set;}
  [MessageHeader] public string Password {get;set;}

  // This is in the SOAP body
  [MessageBodyMember] public string OtherData {get;set;}
  ...
}


You can also use UsernameToken in SOAP header if you have to pass only username paaword and use custom UserNamePasswordValidator as a pluggable service behaviour. http://msdn.microsoft.com/en-us/library/aa702565.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜