更改根节点(响应)wcf 服务

Change root node (response) wcf service

我使用 vs2013 的默认示例创建了一个简单的 wcf 服务。我需要在 GetData

中更改响应 GetDataResponse 的根

我该怎么做?

  
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header />
  <s:Body>
    <**GetDataResponse** xmlns="http://tempuri.org/">
      <GetDataResult>You entered: 0</GetDataResult>
    </GetDataResponse>
  </s:Body>
</s:Envelope>

您需要使用 Messagecontract 来更改(控制)SOAP request/response。对于 example:Create 新的响应 class 并使用 MessageContract 进行装饰,如下所示。

[MessageContract(IsWrapped=true, 
                     WrapperName="GetDataResponse", 
                     WrapperNamespace="http://MyCompany.com/Response")]
    public class GetDataInfo
    {
    }

使用上面的class作为调用WCF服务时的响应对象。 请参阅 http://csharp-video-tutorials.blogspot.in/2013/11/part-10-message-contract-in-wcf_28.html 了解更多详细信息。