Javascript 如何使用jQuery或SimpleJS调用简单WCF服务
我有一个非常简单的hello world WCF服务,如下所示。当我通过asp.net项目通过添加web服务引用调用它时,它工作得非常好。但当我使用jQuery或标准js ajax调用(使用Javascript 如何使用jQuery或SimpleJS调用简单WCF服务,javascript,jquery,wcf,Javascript,Jquery,Wcf,我有一个非常简单的hello world WCF服务,如下所示。当我通过asp.net项目通过添加web服务引用调用它时,它工作得非常好。但当我使用jQuery或标准js ajax调用(使用XMLHttpRequest)调用它时,它会回调success函数,但返回空数据 当我尝试使用以下地址通过firefox浏览器访问它时:http://localhost:8282/Test/TestService.svc/HelloWorld 它返回了一个错误,代码为“a:ActionNotSupported
XMLHttpRequest
)调用它时,它会回调success函数,但返回空数据
当我尝试使用以下地址通过firefox浏览器访问它时:http://localhost:8282/Test/TestService.svc/HelloWorld
它返回了一个错误,代码为“a:ActionNotSupported”,错误详细信息为
由于EndpointDispatcher上的ContractFilter不匹配,无法在接收器上处理具有操作“”的消息。这可能是因为合同不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)
如果我将绑定更改为wsHttpBinding
,那么即使在Firefox中也不会返回任何内容
代码如下:
文件“Test/ITestService.svc”:
文件“Test/TestService.svc”:
文件“web.config”
使用上面的代码,服务只允许soap请求,所以为了允许Get http请求,我们必须修改代码,如下所示:
在接口中:
在web配置中:
- 添加行为配置:
<endpoint address="" binding="webHttpBinding" contract="radMLRPC.Test.ITestService" behaviorConfiguration="webBehav">
- 然后在行为中添加以下标记:
“请删除上面的多余空格。没有多余空格的标签不会显示”
请查看一些相关资源:
使用WCF的RESTful服务简介
http://msdn.microsoft.com/en-us/magazine/dd315413.aspx
Endpoint.TV屏幕广播:
- 使用WCF构建RESTful服务(第1部分)
- 使用WCF构建RESTful服务(第2部分)
http://channel9.msdn.com/shows/Endpoint/endpointtv-Screencast-Building-RESTful-Services-with-WCF-Part-2/
- 在WCF中调用RESTful服务
http://channel9.msdn.com/shows/Endpoint/endpointtv-Screencast-Calling-RESTful-Services-in-WCF/
一般来说,Endpoint.TV对WCF和WCF REST的覆盖率非常高。
http://channel9.msdn.com/shows/Endpoint/
对于webHttp和客户端脚本,mex绑定没有用处。暂时放下它
这个身份可能会给你带来一些悲伤,暂时放下它吧
您的地址是HelloWorld,为了调用服务上的HelloWorld方法,您需要调用。放下它
<services>
<service name="radMLRPC.Test.TestService" behaviorConfiguration="radMLRPC.Test.TestServiceBehavior"
<endpoint address="" binding="webHttpBinding" contract="radMLRPC.Test.ITestService"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="radMLRPC.Test.TestServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
你好像弄错了。该链接提供了有关执行您希望执行的操作的明确指导。您显示的配置有一些问题,也许我们可以解决。请参阅编辑后的回答我无法解决问题,因为我没有使用dotnet scriptmanager for client,而是使用它的简单html应用程序,没有任何服务器技术。为此,我需要我的服务将其方法公开给http web。如果我弄错了,请告诉我
<system.serviceModel>
<services>
<service name="radMLRPC.Test.TestService" behaviorConfiguration="radMLRPC.Test.TestServiceBehavior"
<endpoint address="HelloWorld" binding="webHttpBinding" contract="radMLRPC.Test.ITestService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="radMLRPC.Test.TestServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
[WebGet(UriTemplate="helloworld")]
[OperationContract]
string HelloWorld();
<endpoint address="" binding="webHttpBinding" contract="radMLRPC.Test.ITestService" behaviorConfiguration="webBehav">
<services>
<service name="radMLRPC.Test.TestService" behaviorConfiguration="radMLRPC.Test.TestServiceBehavior"
<endpoint address="" binding="webHttpBinding" contract="radMLRPC.Test.ITestService"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="radMLRPC.Test.TestServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="AjaxEndpointBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="ClientScriptServices.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ClientScriptServices.Service1Behavior" name="ClientScriptServices.Service1">
<endpoint behaviorConfiguration="AjaxEndpointBehavior" binding="webHttpBinding" contract="ClientScriptServices.Service1" />
</service>
</services>
</system.serviceModel>