【发布时间】:2009-01-22 00:40:13
【问题描述】:
我有一个 WCF 服务,它将字符串值“名称”作为参数。这个服务接口长这样……
[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 不会像我预期的那样传递参数值?
感谢您的帮助。
【问题讨论】: