Remove xml namespaces from WCF restful response

前端 未结 9 1665
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 11:13

I am using WCF to return a plain old XML (POX) document to the caller. I am using the XML Serializer formatter to turn the objects into XML.

In the returned docum

9条回答
  •  感情败类
    2020-12-05 11:27

    In my RESTful WCF service which I wrote prior to the WCF RESTful starter kit I did the following which gives me nice, clean results.

    First, make sure the webHttp endpoint behavior is set:

      
        
          
        
      
    

    Your endpoint should look something like this (minus the contract for simplicity):

    
    

    My service contract has these operation contracts in it:

        [WebGet(UriTemplate="tasks", ResponseFormat=WebMessageFormat.Xml )]
        [OperationContract]
        Task[] GetTasks();
    
        [WebGet(UriTemplate="tasks/{id}", ResponseFormat=WebMessageFormat.Xml)]
        [OperationContract]
        Task GetTask(string id);
    

    The service implementation itself has nothing special about it. You can try changing up the WebMessageFormat but the only other item in the enumeration is "json".

提交回复
热议问题