小编ven*_*kat的帖子

WCF Rest Service中的WebGet和非WebGet方法

以下是我的合同和OperationContracts,我的问题是,当我将WebGet属性用于我的服务正常工作的所有方法时,当我将WebGet属性移除到任何一个OperationContracts时,我会得到以下错误.

合同'IDemo'的操作'ProductDetails'指定要序列化的多个请求体参数,而不包含任何包装元素.最多可以在没有包装元素的情况下序列化一个body参数.删除额外的body参数或将WebGetAttribute/WebInvokeAttribute上的BodyStyle属性设置为Wrapped.

这些是我的方法

string AddNumbers(int x,int y);  --- using [WebGet]

string SubtractNumbers(int x, int y); -- using [WebGet]

String ProductDetails(string sName, int cost, int Quntity, string binding); -- not using using [WebGet]

CompositeType GetDataUsingDataContract(CompositeType composite); -- not using [WebGet]
Run Code Online (Sandbox Code Playgroud)

[WebGet]如果我们去WebHttpbinding,是否必须在所有操作合同中包含属性?

public interface IService1
{
    [OperationContract]        
    string GetData(int value,string binding);

    [OperationContract]
    [WebGet(BodyStyle = WebMessageBodyStyle.Bare,
           ResponseFormat = WebMessageFormat.Xml,
           UriTemplate = "/Add?num1={x}&num2={y}")]
    string AddNumbers(int x,int y);

    [OperationContract]
    [WebGet(BodyStyle = WebMessageBodyStyle.Bare,
           ResponseFormat = WebMessageFormat.Xml,
           UriTemplate = "/Subtract?num1={x}&num2={y}")]
    string SubtractNumbers(int x, int y);

    [OperationContract] …
Run Code Online (Sandbox Code Playgroud)

rest wcf

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

rest ×1

wcf ×1