gleasonomicon
gleasonomicon

Reputation: 1089

basic wcf message contract soap header question

I have the following operation contract method:

[OperationContract]
MyOutputMessageType DeleteVRequest(DeleteVRequest type);  

[MessageContract]    
public class DeleteVRequest
   {

    [MessageHeader(Name = "UserId")]
    public Guid UserId;

    [MessageHeader(Name = "Password")]
    public String Password;

    [MessageHeader(Name = "Version")]
    public String Version;

    [MessageBodyMember]
    public Guid Id;
}

[MessageContract]
public class MyOutputMessageType
{
    [MessageBodyMember]
    public string Response;
}

My question is how are the soap header values of the contract (userid,password,version) set for the call on the client side? If I write a header value using Add on the outgoingmessageheaders it does not seem to map to the value in the messagecontract. So for instance if I add a UserId value to the headers, it does not seem to see that within the DeleteVRequest method.

Thanks for any help, I've really been struggling with SOAP header reader/writing in SOAP.

Upvotes: 0

Views: 1113

Answers (1)

RMD
RMD

Reputation: 3253

If the client side is using .NET, the service proxy will take in a message contract rather than the data contract, and you can set the header properties as you would any other properties.

Otherwise, you can using the OperationContextScope to set header values manually:

using(OperationContextScope context = new OperationContextScope(proxy.InnerChannel))
{
    OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("HeaderName", "HeaderNamespace", "SomeValue"));

    //Make your proxy calls here
}

Upvotes: 1

Related Questions