我已經設置了以下接口和類爲我的WCF Web服務,但我有一個問題,當我張貼JSON它,發佈XML工作正常。WCF方法不示數,但不接受我的JSON
[ServiceContract]
public interface IWebService {
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "xml/post")]
[return: MessageParameter(Name = "data")]
int Test(int x, int y);
}
public class WebService : IWebService {
public int Test(int x, int y) {
return x + y;
}
}
如果我發佈此XML:
<Test xmlns="http://tempuri.org/"><x>10</x><y>10</y></Test>
我得到這樣的這種反應(如預期):
<TestResponse xmlns="http://tempuri.org/"><data>20</data></TestResponse>
但如果我發佈此JSON:
{"Test":{"x":10,"y":10}}
我收到此回覆:
<TestResponse xmlns="http://tempuri.org/"><data>0</data></TestResponse>
當我把一個斷點的方法我看到x和y參數均爲0
我已經試過張貼幾個不同的版本我的JSON的,但所有經過爲零。奇怪的是,如果我從JSON刪除「X」和「Y」的屬性我送(如{"Test":{}}
),它實際上並沒有錯誤,但很明顯的參數仍然爲零,不知道這是否涉及雖然:)
'WebMessageBodyStyle.Wrapped'但您的ServiceContract沒有看到接受任何。 –