javascript – 如何使用jQuery或简单的js调用简单的WCF服务
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 如何使用jQuery或简单的js调用简单的WCF服务,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2950字,纯文字阅读大概需要5分钟。
内容图文
![javascript – 如何使用jQuery或简单的js调用简单的WCF服务](/upload/InfoBanner/zyjiaocheng/825/4afb85baa93b42bb93a922e1f4530376.jpg)
我有一个非常简单的hello world WCF服务,如下所示.当我通过添加Web服务引用通过asp.net项目调用它时,它工作得很好.但是当我使用jQuery或标准js ajax调用(使用XMLHttpRequest)调用它时,它会调用success函数但返回null数据.
当我尝试使用以下地址通过firefox浏览器访问它时:http:// localhost:8282 / Test / TestService.svc / HelloWorld
它返回错误,代码为“a:ActionNotSupported”,错误详情为
The message with Action ” cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).
如果我更改绑定到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>
解决方法:
使用上面的代码服务只允许soap请求,以便允许获取http请求,我们必须修改代码,如下所示:
在界面中:
[WebGet(UriTemplate="helloworld")]
[OperationContract]
string HelloWorld();
在web配置中:
>添加behaviorConfiguration:
<endpoint address="" binding="webHttpBinding" contract="radMLRPC.Test.ITestService" behaviorConfiguration="webBehav">
>然后在行为中添加以下标记:
< endpointBehaviors>
< behavior name =“webBehav”>
< webHttp />
< / behavior>
< / endpointBehaviors>
“请从上面删除多余的空格.它没有显示标签没有额外的空格”
查看一些资源:
使用WCF的RESTful服务简介
http://msdn.microsoft.com/en-us/magazine/dd315413.aspx
Endpoint.TV截屏:
>使用WCF构建RESTful服务(第1部分)
http://channel9.msdn.com/shows/Endpoint/endpointtv-Screencast-Building-RESTful-Services-with-WCF/
>使用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/
对于WCF和WCF REST来说,Endpoint.TV一般都有很好的覆盖范围.
http://channel9.msdn.com/shows/Endpoint/
内容总结
以上是互联网集市为您收集整理的javascript – 如何使用jQuery或简单的js调用简单的WCF服务全部内容,希望文章能够帮你解决javascript – 如何使用jQuery或简单的js调用简单的WCF服务所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。