从远程javascript中调用WCF服务javascript、WCF

2023-09-10 18:25:11 作者:丶贴心大叔的霸道范er

我有一个WCF服务(XML + JSON)在 HTTP运行://的ServiceHost:8080 /为myService 。 使用jQuery我的ASP.NET应用程序运行在 HTTP://webapp/Login.aspx

我想jQuery的使用Ajax和调用的URL 的http://的ServiceHost:8080 /为myService 。该浏览器不允许这种跨主机通话,预计。 一些计算器上的帖子建议使用JSONP。这是唯一的选择吗?

有没有一种方法来定义的 HTTP代理服务:// Web应用并有它访问远程WCF服务?

感谢

ABHI

解决方案   

有没有一种方法来定义代理   在的http:// web应用并有   它访问远程WCF服务?

是的,这就是我想要做的。有很多方法可以做到这一点。如果使用负载平衡器或其他前端代理软件,你可以路线那里。此外,您还可以与IIS代理服务器代理

的http://windowsitpro.com/article/articleid/8322/extending-iis-with-proxy-server.html

有第三方和开源替代品(例如Apache可能只是你的代理)

也许,你会想要做这样的事情呢 - 不是每个人都可以打开8080端口(如企业防火墙内)

I have a WCF service (XML+JSON) running on http://servicehost:8080/myService. My ASP.NET application with jQuery is running on http://webapp/Login.aspx

运维与微服务结合 深度解析微服务框架Tars整体解决方案

I want jQuery to use Ajax and call the URL http://servicehost:8080/myService. The browser does not allow this cross-host call, which is expected. Some of the posts on stackoverflow suggested using JSONP. Is that the only option?

Is there a way to define a proxy service on the http://webapp and have it access the remote WCF service?

Thanks

Abhi

解决方案

Is there a way to define a proxy service on the http://webapp and have it access the remote WCF service?

Yes, and that's what I'd do. There are a lot of ways to do it. If you use a load-balancer or other front-end proxy software, you could route there. Also, you could proxy with IIS proxy server

http://windowsitpro.com/article/articleid/8322/extending-iis-with-proxy-server.html

There are third-party and open-source alternatives (e.g. Apache could be just your proxy)

Probably, you'd want to do something like that anyway -- not everyone can open up port 8080 (like inside of corporate firewalls).