Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We are trying to develop a web service which will replace an existing web service consumed by a client of ours. This meant that the SOAP response from the new web service in WCF has to match exactly with the SOAP response from the current web service which was a legacy service written in Java. We are having trouble in making the new service return the same SOAP response as the old one.
Initially, we started with the DataContract as structure for the response but since it was generating some additional tags we switched to MessageContract.

Here is the sample request and response with DataContract as the attribute for request and response. We are facing two of issues with using DataContract –
1. The response is having two additional tags “GetDataUsingDataContractReponse”,”GetDataUsingDataContractResult” which we are not able to remove programmatically.
2. We were not able to get the “BoolValue” property as a XML Attribute, instead it shows up as a XML Element.
We would greatly appreciate if you can share any ideas you have to work around these two issues. Below are the sample request and response using DataContract.

Request with DataContract-
XML
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:mem="http://schemas.datacontract.org/2004/07/MemoPayment">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:GetDataUsingDataContract>
         <!--Optional:-->
         <tem:composite>
            <mem:BoolValue>true</mem:BoolValue>                              à Not able to make this value as XML Attribute. Instead, always shows up as XML Element
            <mem:StringValue>Sam</mem:StringValue>
         </tem:composite>
      </tem:GetDataUsingDataContract>
   </soapenv:Body>
</soapenv:Envelope>
Response with DataContract-
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <GetDataUsingDataContractResponse xmlns="http://tempuri.org/">
         <GetDataUsingDataContractResult xmlns:a="http://schemas.datacontract.org/2004/07/MemoPayment" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">      
à Extra tags showing up. Any way to remove them?
            <a:BoolValue>true</a:BoolValue>
            <a:StringValue>SamSuffix</a:StringValue>
         </GetDataUsingDataContractResult>
      </GetDataUsingDataContractResponse>
   </s:Body>
</s:Envelope>



To have more control on the SOAP message, we have switched from DataContract to MessageContract and now the response is being rendered as expected with XML attributes and XML Elements.
But, the issue with using MessageContract is that all the XML Elements are being coming up as Optional. Example – “StringValue” in the below request. Again, we would greatly appreciate if you can suggest any work around from your experience.

Request with MessageContract-
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:MsgRequest boolVal="true">
         <!--Optional:-->
         <tem:StringValue>Sam</tem:StringValue>                                à Always showing up as Optional. Not able to control from the code. Any way to remove the Optional attribute?
      </tem:MsgRequest>
   </soapenv:Body>
</soapenv:Envelope>


Response with MessageContract-
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <MsgResponse boolVal="true" xmlns="http://tempuri.org/">
         <StringValue>SamSuffix</StringValue>
      </MsgResponse>
   </s:Body>
</s:Envelope>
Posted
Updated 10-Jan-14 5:37am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900