开发者

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]
    pu开发者_如何学编程blic 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.


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
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜