如何对托管在其他域上的WCF服务进行JavaScript调用?

时间:2022-12-03 22:42:11

We are designing a web application using ASP.NET and AJAX and we want to host our WCF Service Layer on a different website and make JavaScript calls to the Service Layer from our client pages. We understand that the browser will not allow AJAX calls to a different port or domain. What is the best way to architect a solution? We are considering using a proxy layer with services hosted on the same domain as the client which has a web reference to the service layer. Is there a better solution?

我们正在使用ASP.NET和AJAX设计Web应用程序,我们希望在不同的网站上托管我们的WCF服务层,并从我们的客户端页面调用服务层。我们知道浏览器不允许对不同的端口或域进行AJAX调用。构建解决方案的最佳方法是什么?我们正在考虑将代理层与托管在同一域上的服务一起使用,该客户端具有对服务层的Web引用。有更好的解决方案吗?

5 个解决方案

#1


6  

It's generally best to limit the number of domains accessed by your page. A server-side proxy is really a good way to go.

通常最好限制页面访问的域数。服务器端代理确实是一个很好的方法。

#2


1  

i think the best way is to call a local Page which call remote resource and returns result. in this way, you avoid cross domains problems

我认为最好的方法是调用一个调用远程资源并返回结果的本地页面。通过这种方式,您可以避免跨域问题

#3


0  

  • You can do virtual hosting of the service and website under same domain but different folder.
  • 您可以在同一个域但不同的文件夹下虚拟托管服务和网站。

  • define the services in different dlls and create svc files in your websites and point the svc files to the dll which has the services
  • 定义不同dll中的服务并在您的网站中创建svc文件并将svc文件指向具有服务的dll

  • server side proxy.
  • 服务器端代理。

#4


0  

Your load balancer could send all request to /service to your service server.

您的负载均衡器可以将所有请求发送到/服务到您的服务服务器。

If you don't have a load balancer, you can have your webserver act as a reverse proxy to your service server. If you are using IIS7, you can do this with the Application Request Routing module.

如果您没有负载均衡器,则可以将Web服务器充当服务服务器的反向代理。如果您使用的是IIS7,则可以使用“应用程序请求路由”模块执行此操作。

#5


0  

Prototype has a plug in for this. The issue is on the client not the server. www.mellowmorning.com/2007/10/25/introducing-a-cross-site-ajax-plugin-for-prototype/

Prototype有一个插件。问题出在客户端而不是服务器上。 www.mellowmorning.com/2007/10/25/introducing-a-cross-site-ajax-plugin-for-prototype/

#1


6  

It's generally best to limit the number of domains accessed by your page. A server-side proxy is really a good way to go.

通常最好限制页面访问的域数。服务器端代理确实是一个很好的方法。

#2


1  

i think the best way is to call a local Page which call remote resource and returns result. in this way, you avoid cross domains problems

我认为最好的方法是调用一个调用远程资源并返回结果的本地页面。通过这种方式,您可以避免跨域问题

#3


0  

  • You can do virtual hosting of the service and website under same domain but different folder.
  • 您可以在同一个域但不同的文件夹下虚拟托管服务和网站。

  • define the services in different dlls and create svc files in your websites and point the svc files to the dll which has the services
  • 定义不同dll中的服务并在您的网站中创建svc文件并将svc文件指向具有服务的dll

  • server side proxy.
  • 服务器端代理。

#4


0  

Your load balancer could send all request to /service to your service server.

您的负载均衡器可以将所有请求发送到/服务到您的服务服务器。

If you don't have a load balancer, you can have your webserver act as a reverse proxy to your service server. If you are using IIS7, you can do this with the Application Request Routing module.

如果您没有负载均衡器,则可以将Web服务器充当服务服务器的反向代理。如果您使用的是IIS7,则可以使用“应用程序请求路由”模块执行此操作。

#5


0  

Prototype has a plug in for this. The issue is on the client not the server. www.mellowmorning.com/2007/10/25/introducing-a-cross-site-ajax-plugin-for-prototype/

Prototype有一个插件。问题出在客户端而不是服务器上。 www.mellowmorning.com/2007/10/25/introducing-a-cross-site-ajax-plugin-for-prototype/