【发布时间】:2010-07-19 10:11:05
【问题描述】:
我有一个非常简单的 hello world WCF 服务,如下所示。当我通过添加 Web 服务引用通过 asp.net 项目调用它时,它工作得非常好。但是当我使用 jQuery 或标准 js ajax 调用(使用XMLHttpRequest)调用它时,它会回调成功函数但返回 null 数据。
当我尝试使用这个地址通过 Firefox 浏览器访问它时:http://localhost:8282/Test/TestService.svc/HelloWorld
它返回一个错误,代码为“a:ActionNotSupported”,错误详情为
由于 EndpointDispatcher 的 ContractFilter 不匹配,接收方无法处理带有 Action '' 的消息。这可能是因为合约不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)。
如果我将绑定更改为wsHttpBinding,那么即使在 Firefox 中它也不会返回任何内容。
代码如下:
文件“Test/ITestService.svc”:
[ServiceContract(Namespace = "http://localhost:8282/")]
public interface ITestService
{
[OperationContract]
string HelloWorld();
}
文件“Test/TestService.svc”:
public class TestService : ITestService
{
public string HelloWorld()
{
return "This is echo from server. Hello World";
}
}
文件“web.config”
<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>
【问题讨论】:
标签: javascript jquery wcf