WCF service, response in SOAP or plain XML, how?

前端 未结 2 599
攒了一身酷
攒了一身酷 2021-02-03 11:09

I am struggling few hours with this and can\'t find a solution to the communication problem. My service need to communicate with clients via SOAP or plain XML

My service

相关标签:
2条回答
  • 2021-02-03 11:27

    The service you have here will return a SOAP message - which will contain the "CompositeType" as its "payload".

    WCF by default uses SOAP - any of the basicHttpBinding, wsHttpBinding, netTcpBinding etc. all work with SOAP as their basis.

    If you want to return straight XML, you need to check out the REST capabilities of WCF - this works with the webHttpBinding (and only that binding).

    Also, how to produce an XML like this (based on data contract):

    <CompositeType BoolValue = 0 StringValue = "">
    

    rather than this:

    <CompositeType>
      <BoolValue>0</BoolValue>
      <StringValue></StringValue>
    </CompositeType>
    

    This is a limitation of the WCF DataContract serializer. For performance reasons, it does not support attributes, e.g. you cannot create the first fragment of XML that you want.

    If you absolutely must have the first XML, you'll need to use the XmlSerializer instead (which has its own set of limitations / problems).

    Marc

    UPDATE: if you just want to return a given XML, then you're probably better off with the REST approach.

    Check out the Pluralsight website for an excellent series of screencasts on using REST and in particular, one screencast on how to create a plain-old XML (POX) REST service.

    0 讨论(0)
  • 2021-02-03 11:35

    Take a look at Enunciate. I've used it before to create a REST (XML && JSON) interface as well as a SOAP interface. It might give you exactly what you're looking for and it's pretty easy to work with. The lead developer is also quite active on the mailing list so if you have questions just send the group a message and you'll usually get a response very quickly.

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