简体   繁体   English

使用WebScriptEndpoint使用JavaScript消耗WCF服务

[英]Consuming WCF service using javascript using WebScriptEndpoint

I searched on net but didn't find any suitable article explaining how to consume a WCF service using javascript, and especially a WebScriptEndpoint. 我在网上搜索,但没有找到任何合适的文章来解释如何使用javascript(尤其是WebScriptEndpoint)使用WCF服务。

Can any one give any direction on this? 有人可以为此提供任何指示吗?

Thanks 谢谢

Here is a good article about REST services : http://msdn.microsoft.com/en-us/magazine/dd315413.aspx 这是一篇有关REST服务的好文章: http : //msdn.microsoft.com/zh-cn/magazine/dd315413.aspx

To summarize, you want an endpoint configured with webHttpBinding. 总而言之,您需要一个配置了webHttpBinding的端点。 This endpoint should have a behavior with webHttp enabled : 该端点应该具有启用webHttp的行为:

<services>
  <service name="TestService">
    <endpoint address="test" binding="webHttpBinding"  behaviorConfiguration="restBehavior" contract="ITestService"/>
  </service>
</services>

Behavior : 行为:

<behavior name="restBehavior">
  <webHttp/>
</behavior>

Then in your service interface : 然后在您的服务界面中:

[ServiceContract]
public interface ITestService
{
    [OperationContract]
    [WebGet(UriTemplate = "test?p={p}", ResponseFormat = WebMessageFormat.Json)]
    string Test(string p);
}

You can use WebGet or WebInvoke attribute (depends if you want to GET or POST)... 您可以使用WebGet或WebInvoke属性(取决于您要GET还是POST)...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM