Why does WCF wrap request/response types in another XML element, and how to prevent this?

后端 未结 2 1513
孤街浪徒
孤街浪徒 2021-01-03 03:59

I have a simple echo service where I\'ve defined one operation method and a pair of types for request/response:

[ServiceContract(Name = \"EchoService\", 
            


        
相关标签:
2条回答
  • 2021-01-03 04:04

    IIRC, WCF by default uses the 'Wrapped' message style. If you want to be able to control how messages are serialized, you can define explicit messages by decorating with the MessageContractAttribute. With explicit message contracts, you can set the IsWrapped property to false.

    In your case I think that EchoRequest and EchoResponse shouldn't be DataContracts at all, but rather MessageContracts. They look a lot like MessageContracts to me.

    0 讨论(0)
  • 2021-01-03 04:16

    I eventually switched over to use Message Contracts using a TypedMessageConverter which I was introduced to via this question's answer. That was the missing piece here.

    0 讨论(0)
提交回复
热议问题