以下是我的合同和OperationContracts,我的問題是當我將WebGet屬性與所有方法一起使用時,我的服務工作正常,當我將WebGet屬性移除到任何一個OperationContracts即時得到下面的錯誤。WCF Rest服務中的WebGet和非WebGet方法
操作 合同「IDemo」指定多個 請求體參數的「產品詳細」是 串行化而沒有任何包裝 元件。最多可以對一個身體參數 進行序列化,而不包裝 元素。請刪除額外的身體 參數或將 WebGetAttribute/WebInvokeAttribute上的BodyStyle 屬性設置爲 包裝。
這是我的方法
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]
是否必須包括[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]
String ProductDetails(string sName, int cost, int Quntity, string binding);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
}
感謝您的快速回復馬克,我絕對嘗試了上面的實現,你發佈了它的工作良好,欣賞它。 – venkat 2011-05-06 06:22:52
我想你需要接受答案 – Chandermani 2011-05-06 07:14:21
爲什麼MS允許你在同一個項目中混合使用OperationContract和Web [Get | Invoke],但是當你想讓它成爲一個SOAP唯一的方法? (是的,我知道我在向錯誤的人誇獎,但仍然) – thaBadDawg 2012-03-06 17:50:13