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

前端 未结 2 628
攒了一身酷
攒了一身酷 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条回答
  •  萌比男神i
    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):

    
    

    rather than this:

    
      0
      
    
    

    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.

提交回复
热议问题