简体   繁体   中英

What is the purpose of the IsWrapped property in WCF

What is the purpose of the "IsWrapped" property in WCF. In which situation should I use this property and why?

Unwrapped Messages (MSDN) :

By default, the message body is formatted such that the parameters to a service operation are wrapped.

And

MessageContractAttribute.IsWrapped Property (MSDN) :

Set the value of IsWrapped to false to suppress the wrapper element into which the message body is serialized.

So, consider this (trimmed) message:

<s:Envelope>
  <s:Body>
    <Add>
      <n1>100</n1>
      <n2>15.99</n2>
    </Add>
  </s:Body>
</s:Envelope>

When you set IsWrapped to false , the message body won't be wrapped in an element with the action name ( Add in this case):

<s:Envelope>
  <s:Body>
    <n1>100</n1>
    <n2>15.99</n2>
  </s:Body>
</s:Envelope>

Properties like these are meant for interoperability, for example when writing a client to consume a service which doesn't expect messages to be wrapped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM