RESTful web service body format

前端 未结 2 1045
有刺的猬
有刺的猬 2020-11-27 13:30

I am new to WCF. I am doing some simple RESTful WCF operation contracts. And, I have a question about options for property BodyS

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 14:23

    The usage of the wrapped on the operation description simply wraps the request (or the response) in an XML element. For example, in this contract:

    [ServiceContract]
    public interface ITest
    {
        [OperationContract]
        [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare)]
        string Echo(string text);
    
        [OperationContract]
        [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]
        string EchoWrapped(string text);
    
        [OperationContract]
        [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]
        int Divide(int dividend, int divisor, out int reminder);
    }
    

    The input for the Echo operation is simply a element, with the text contained within. Likewise, its response contains a single element with the return of the operation. For the EchoWrapped operation, the input is actually a element, whose child is a element whose child contains the input to the method.

    What a service expects for the Echo operation:

    The input
    

    What a service expects for the EchoWrapped operation:

    Hello wrapped
    

    Source: http://social.msdn.microsoft.com/Forums/vstudio/en-US/9db6793b-8db9-479b-825c-e781d023f6c1/bodystylewebmessagebodystylewrapped-with-requestformatwebmessageformatxml-for-post?forum=wcf

提交回复
热议问题