我有一個新的Web服務我試圖實現...當我在調試器中運行時,在服務中調用的函數停止在我設置的斷點處,但我注意到該值null ...我試圖弄清楚這一點的最後一天燒了自己。WCF服務接收空值
我道歉,如果我似乎不集中或沒有給予足夠的信息......我感謝所有幫助
我自己也嘗試從提琴手爲好;它停在像上面那樣的斷點處。
我在想我的JSON可能會扭曲?
從客戶端調用:
var url = "http://localhost:35798/Service.svc/Test;
var json = '{"name": "test"}';
$.ajax({
type: "GET",
url: url,
dataType: "json",
processData: true,
data: json,
contentType: "application/json; charset=utf-8",
success: function (data) {
alert("Passed" + data.CheckFileResult);
},
error: function (data) {
alert(data.d);
}
});
服務:
[OperationContract]
[WebInvoke(Method="GET", ResponseFormat=WebMessageFormat.Json)]
public string Test(string name)
{
return "hi";
}
服務配置:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="Site.Service1AspNetAjaxBehavior">
<enableWebScript />
</behavior>
<behavior name="Site.ServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="Site.Service">
<endpoint address="" behaviorConfiguration="Site.ServiceAspNetAjaxBehavior"
binding="webHttpBinding" contract="Site.Service" />
</service>
</services>
</system.serviceModel>
對不起,我是複製/粘貼速度快;我試圖改變json,但它仍然不起作用。另外我在jsonlint.com上試過你的json例子,它不喜歡它。不過謝謝! – wali 2011-04-08 16:16:16
對不起。你說得對,你的json語法是有效的。 – Damb 2011-04-08 16:22:29