views:

148

answers:

1

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 written 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.

+1  A: 

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;}
  ...
}
Chris Taylor
So, MessageContract is an either or with DataContract? I have a lot of DataContracts already. Do I just convert them to Message contract and say where everything goes? (I hope it is just that simple!)
Vaccano
Could I just set the OtherData to be the DataContract? (Is that poor design?)
Vaccano
@Vaccano, yes you can either use DataContracts or go for the finer graned control over the message structure using MessageContracts. You should be able to just convert to using MessageContracts.
Chris Taylor