1
我有一個WCF服務,它將字符串值「name」作爲參數。這種服務接口看起來像這樣...在WCF上暴露的REST服務沒有填充參數值
[ServiceContract(Name = "ContactLookup", Namespace = "Search")]
public interface IAjaxResultSearcherService
{
[OperationContract]
[WebGet(RequestFormat = WebMessageFormat.Json)]
Result[] SearchResultsWithNameLike(string name);
}
服務暴露在使用以下配置...
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<behaviors>
<serviceBehaviors>
<behavior name="AjaxServiceBehavior">
<serviceDebug
includeExceptionDetailInFaults="true"
httpHelpPageEnabled="true"/>
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
<serviceCredentials>
<serviceCertificate findValue="localhost"
storeLocation="LocalMachine"
storeName="My" x509FindType="FindBySubjectName"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="JsonBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="HelloIndigo.AjaxResultSearcherService"
behaviorConfiguration="AjaxServiceBehavior">
<endpoint address="json"
binding="webHttpBinding"
behaviorConfiguration="JsonBehavior"
contract="Contract.IAjaxResultSearcherService" />
</service>
</services>
</system.serviceModel>
我的.svc文件使用WebScriptServiceHostFactory。這似乎工作,這意味着我可以連接到我的jquery客戶端的服務,但即使通過ajax調用設置參數值,當消息到達服務實現時,參數值爲null。
我通過jQuery調用服務是這樣的...
$.ajax({
url: url,
data: { "name":"test" },
type: "GET",
processData: false,
contentType: "application/json",
timeout: 10000,
dataType: "text",
success: function(res) {
alert('function successful! returned: ' + res.toString());
},
error: function(xhr) {
alert('an error occurred: ' + xhr.responseText);
}
});
我沒有得到任何來自服務調用的錯誤,但是當我調試過程中,參數值爲null。爲什麼WCF不會像我期望的那樣傳遞參數值?
感謝您的幫助。