How to modify the response element name in soap message?

If we use data contract in WCF, the default soap message looke like:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header />
  <s:Body>
    <GetDataUsingDataContractResponse xmlns="http://tempuri.org/">
      <GetDataUsingDataContractResult xmlns:a="http://schemas.datacontract.org/2004/07/WcfService10" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:BoolValue>false</a:BoolValue>
        <a:StringValue>test</a:StringValue>
      </GetDataUsingDataContractResult>
    </GetDataUsingDataContractResponse>
  </s:Body>
</s:Envelope>

If we want to use a coustome element name instead of "GetDataUsingDataContractResponse ", "GetDataUsingDataContractResult ", "a:BoolValue"

How can we achieve this?

One possible way would be MessageParameter

[return: System.ServiceModel.MessageParameterAttribute(Name="Output")]

http://msdn.microsoft.com/en-us/library/system.servicemodel.messageparameterattribute.aspx

Or use message contract, the output would be: 

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header />
  <s:Body>
    <CompositeType xmlns="http://tempuri.org/">
      <BoolValue>false</BoolValue>
      <StringValue>test</StringValue>
    </CompositeType>
  </s:Body>
</s:Envelope>

However, this is not excatly what I want. I looking for something like this:

How to: Control Parameter and Return Value Formatting for a Web Service Method

http://msdn.microsoft.com/en-us/library/a561tby9.aspx

There should be a solution which allow us fully control the format of soap message returned by an WCF operation. Still looking for it.......

(it is regret that can't don further rearching before move to a new question)

原文地址:https://www.cnblogs.com/LeoTang/p/2611821.html