【发布时间】:2011-01-27 00:42:16
【问题描述】:
有人能发现这个实现的问题吗?我可以在浏览器中打开它,它可以工作,但是来自客户端的调用(同时使用 jquery 和 asp.net ajax 失败)
服务合同
[OperationContract(Name = "GetTestString")]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json
)]
string GetTestString();
在 Web.config 以及其他绑定中,我有一个 webHttp 绑定
<endpoint address="ajax" binding="webHttpBinding" contract="TestService" behaviorConfiguration="AjaxBehavior" />
端点行为
<endpointBehaviors>
<behavior name="AjaxBehavior">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
服务文件
<%@ ServiceHost Service="TestService" %>
客户
var serviceUrl = "http://127.0.0.1/Test.svc/ajax/";
var proxy = new ServiceProxy(serviceUrl);
然后我使用http://www.west-wind.com/weblog/posts/324917.aspx 中的方法 调用服务
【问题讨论】: