0

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

Community
  • 1
  • 1
Kalpesh Rajai
  • 2,040
  • 27
  • 39
  • The xml doesn't deserialize probably because all the namespaces in the XML do not match what is expected by the types. You might want to create a simple service operation that returns a response of type 'RequestBody', return a hand built boject of type 'RequestBody' and check out the XML that it gets serialized into. – Parag Patil Oct 05 '16 at 18:57
  • @ParagPatil, Yes ti works if I return the hand built object to the client, But my client will be send the request with the same SOAP XML which I posted above and It will not work. And I am unable to change the client's code because My client is third party WCF. Is there any way to desalinize properly ? Thanks – Kalpesh Rajai Oct 06 '16 at 08:48
  • There is no need to create the hand built object and send to the client. If I remove the tag prefix from the client request than it works properly. – Kalpesh Rajai Oct 06 '16 at 08:52

0 Answers0