简体   繁体   English

如何使用Silverlight在javascript中启用WCF Web服务

[英]how to use silverlight enables wcf web service in javascript

We have a wcf web service which is developed as a silverlight enabled wcf web service for accessing database from silverlight application. 我们有一个wcf Web服务,该服务被开发为支持Silverlight的wcf Web服务,用于从silverlight应用程序访问数据库。 Now we would like to use the same WCF service to be used from JavaScript. 现在,我们希望使用与JavaScript相同的WCF服务。 Is it possible to call silverlight enabled wcf web service in javascript 是否可以在javascript中调用启用了Silverlight的WCF Web服务

Yes it is possible, you just need to add the Json Endpoint to your service contract and convert your method to return Json data, 是的,有可能,您只需要将Json Endpoint添加到服务合同中并转换您的方法即可返回Json数据,

For example, 例如,

    [OperationContract]
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "login/{username}/{password}",BodyStyle = WebMessageBodyStyle.Bare)]

    UserAuth login(string username, string password);

Yes it is possible. 对的,这是可能的。

http://www.bendewey.com/index.php/186/using-jsonp-with-wcf-and-jquery http://www.bendewey.com/index.php/186/using-jsonp-with-wcf-and-jquery

Modify the class definition [ServiceContract] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class CustomersService { ///// } 修改类定义[ServiceContract] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]公共类CustomersService {/////}

Leave silverlight methods as it is and add Json methods like the following. 保持silverlight方法不变,并添加如下所示的Json方法。

[OperationContract] [WebGet(ResponseFormat = WebMessageFormat.Json)] public List GetCustomers(int d) { return List; [OperationContract] [WebGet(ResponseFormat = WebMessageFormat.Json)]公共列表GetCustomers(int d){返回列表; } }

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

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