简体   繁体   English

将呼叫转移到另一个服务?

[英]Forward a call to a webservice to another webservice?

If I have an https webservice behind a firewall on a machine (A) that I cannot access, but access to a machine on the same network (B), from where I can call the webservice on machine A. 如果我在无法访问但可以访问同一网络(B)上的计算机的防火墙(A)上的防火墙后面有一个https webservice,则可以从其中调用计算机A上的webservice。

What is the best way of talking with the webservice on machine A, from the outside via machine B (that I access via VPN)? 从外部通过机器B(我通过VPN访问)与机器A上的Web服务进行通信的最佳方式是什么?

I can obviously create a service with a matching interface on machine B, and call the methods on the webservice on machine A, and return the result. 我显然可以在机器B上创建具有匹配接口的服务,并在机器A上的Web服务上调用方法,然后返回结果。 But I fear for the overhead and maintainability. 但是我担心开销和可维护性。

Is there another way? 还有另外一种方法吗? Can i somehow forward the request? 我可以以某种方式转发请求吗?

Yes, creating a duplicate web service on machine B sounds like a bad idea, both from a maintenance perspective and the potential extra errors it will introduce. 是的,在机器B上创建重复的Web服务听起来是个坏主意,从维护的角度以及可能带来的额外错误来看。

I once solved this problem by installing an Apache web server on machine B, and setting it up as a reverse proxy . 我曾经通过在机器B上安装Apache Web服务器并将其设置为反向代理来解决此问题。 This means that you expose the WSDL that is hosted on machine A via machine B. All web service clients will 'think' that they are talking to machine B, but they are actually talking to machine A. Apache then just stands for forwarding the web service requests from the client to machine A. This behavior is supported by Apache's mod_proxy module, using the ProxyPass and ProxyPassReverse directives. 这意味着您通过机器B公开了在机器A上托管的WSDL。所有Web服务客户端都将“认为”他们正在与机器B进行通信,但实际上是在与机器A进行通信。Apache只是代表转发网络从客户端到计算机A的服务请求。Apache的mod_proxy模块使用ProxyPassProxyPassReverse指令支持此行为。

There is one 'catch' with this solution: you expose the WSDL from machine A via machine B, and a WSDL always contains the hostname of the machine it is hosted on, in your case machine A. So, clients are talking to machine B and all of a sudden they receive a WSDL which contains a hostname that they don't know. 此解决方案有一个“陷阱”:您通过机器B公开了机器A的WSDL,并且WSDL始终包含它所在的机器(在您的情况下为机器A)的主机名。因此,客户端正在与机器B进行通信突然他们收到了一个WSDL,其中包含他们不知道的主机名。

The solution for this: you need to configure the web service on A in such a way that it will contain the hostname of machine B instead. 解决方案:您需要在A上配置Web服务,使其包含机器B的主机名。 I don't know what framework you are using, but in WCF, this can be easily be configured using the WCFExtras project. 我不知道您使用的是什么框架,但是在WCF中,可以使用WCFExtras项目轻松配置

In my opinion you either have to make A accessible or do as you say, create the same methods on B and invoke A from the implementation. 在我看来,您要么必须使A可以访问,要么按照您所说的做,在B上创建相同的方法,然后从实现中调用A。 Automatic redirect or forward of invocations sounds unsupported to me. 我不支持自动重定向或调用转发。

Since a webservice call is "just" a HTTP packet, you should be able to route them somewhere else without "opening" them. 由于Web服务调用只是“ HTTP”数据包,因此您应该能够将它们路由到其他位置而无需“打开”它们。 Do you want to do this in a static way (for a fixed service) or dynamic (for all services on A)? 您要以静态方式(对于固定服务)还是动态方式(对于A上的所有服务)执行此操作? Is the encryption (you mentioned HTTPS) important? 加密(您提到的HTTPS)重要吗?

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

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