开发者

WCF response customization

开发者 https://www.devze.com 2023-03-15 22:25 出处:网络
I have developed a WCF service whose response is like this - <s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">

I have developed a WCF service whose response is like this -

  <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.开发者_JAVA百科org/2001/XMLSchema">
        <getNameResponse xmlns="http://tempuri.com/">
            <name>4</name>
        </getNameResponse>
    </s:Body>
  </s:Envelope>

But I need response in the following format-

<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">
<a:getNameResponse xmlns:a="http://tempuri.com/">
<name>4</name>
</a:getNameResponse>
</s:Body>
</s:Envelope>

Is it possible to configure WCF service to achieve this behavior?


Yes, you can do this - I've posted about customizing prefixes for WCF services at http://blogs.msdn.com/b/carlosfigueira/archive/2010/06/13/changing-prefixes-in-xml-responses.aspx. However, notice that the two responses you have are not equivalent - in the first one, the <name> element is on the namespace "http://tempuri.org/", while on the second one, it's on the empty ("") namespace. If that's really what you need, you may want to consider using a message contract to change the namespace of the body elements.

0

精彩评论

暂无评论...
验证码 换一张
取 消