Click here to Skip to main content
15,797,984 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-
<soapenv:Envelope xmlns:soapenv="" xmlns:tem="" xmlns:mem="">
            <mem:BoolValue>true</mem:BoolValue>                              à Not able to make this value as XML Attribute. Instead, always shows up as XML Element
Response with DataContract-
<s:Envelope xmlns:s="">
      <GetDataUsingDataContractResponse xmlns="">
         <GetDataUsingDataContractResult xmlns:a="" xmlns:i="">      
à Extra tags showing up. Any way to remove them?

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="" xmlns:tem="">
      <tem:MsgRequest boolVal="true">
         <tem:StringValue>Sam</tem:StringValue>                                à Always showing up as Optional. Not able to control from the code. Any way to remove the Optional attribute?

Response with MessageContract-
<s:Envelope xmlns:s="">
   <s:Body xmlns:xsi="" xmlns:xsd="">
      <MsgResponse boolVal="true" xmlns="">
Updated 10-Jan-14 6:37am

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