I am developing the the SOAP based web services in the WCF.
My client sending the request to the WCF services with the following SOAP request xml:
<e:Envelope xmlns:e="http://schemas.xmlsoap.org/soap/envelope/" e:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<e:Header>
<me:RequestHead xmlns:me="http://www.my-namespace.org/header/abc" >
<ID>0</ID>
<Green>
<a>101</a>
<b>0</b>
</Green>
<Time>1</Tim>
</me:RequestHead>
</e:Header>
<e:Body>
<m:RequestBody xmlns:m="http://www.my-namespace.org/service/abc">
<Time>
<hh>23</hh>
<mm>59</mm>
<ss>59</ss>
</Time>
</m:RequestBody>
</e:Body>
</e:Envelope>
I created the MessageContract
class to pass the value to client or get the value from the client.
In MessageContract
class there is multiple MessageHeader
attribute property, but when request send to the server the property with MessageHeader
attribute is not deserialize and it is always null.
In RequestHead
tag there is prefix me
, I think its create the problem to deserialize the XML request to the object at the WCF services
But in RequestBody
tag there is also prefix m
but it deserialize successfully.
When I remove the prefix me
from the RequestHead
tag than it worked successfully. and I got the value of the MessageHeader
attribute property.
<e:Envelope xmlns:e="http://schemas.xmlsoap.org/soap/envelope/" e:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<e:Header>
<RequestHead xmlns="http://www.my-namespace.org/header/abc" >
<ID>0</ID>
<Green>
<a>101</a>
<b>0</b>
</Green>
<Time>1</Tim>
</RequestHead>
</e:Header>
<e:Body>
<m:RequestBody xmlns:m="http://www.my-namespace.org/service/abc">
<hh>23</hh>
<mm>59</mm>
<ss>59</ss>
</m:RequestBody>
</e:Body>
</e:Envelope>
My Classes:
[MessageContract]
class Green
{
[MessageHeader(Namespace = "")]
public string a { get; set; }
[MessageHeader(Namespace = "")]
public string b { get; set; }
}
[MessageContract]
class RequestHead
{
[MessageHeader(Namespace = "")]
public int id { get; set; }
[MessageHeader(Namespace = "")]
public Green green { get; set; }
[MessageHeader(Namespace = "")]
public int Time { get; set; }
}
[MessageContract]
class Head
{
[MessageHeader(Namespace = "http://www.my-namespace.org/header/abc")]
public RequestHead RequestHead { get; set; }
}
[MessageContract(Namespace = "http://www.my-namespace.org/service/abc")]
class RequestBody : Head
{
[MessageBodyMember(Order = 1)]
public int hh { get; set; }
[MessageBodyMember(Order = 1)]
public int mm { get; set; }
[MessageBodyMember(Order = 1)]
public int ss { get; set; }
}
And my action method in the WCF services is look like this:
public RequestBody CheckTime(RequestBody objBody)
{
}
When I checked the request SOAP XML using the following code:
OperationContext.Current.RequestContext.RequestMessage.ToString();
It give me the full request SOAP XML with the header value also but does not deserialize it to the object.
I does not understand where I am going wrong or I am missing something.
Here is the same question asked but till now it is does not get any answered: How can I deserialize a custom SOAP header in WCF?
Thanks for help...