apache ASP.NET Web 服务在调用时更改端口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1531448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:14:08  来源:igfitidea点击:

ASP.NET Web Service changes port on Invoke

web-servicesapacheiisasmx

提问by David Campos

I have a ASP.NET Web Service on IIS, that is working on port 8080. On port 80 I have Apache, that is redirecting some web sites to IIS.

我在 IIS 上有一个 ASP.NET Web 服务,它在端口 8080 上工作。在端口 80 上我有 Apache,它将一些网站重定向到 IIS。

On this case, I can access the Web Service page (http://example.com/service/), which gives me all the methods available. However, when I try to invoke a method, it goes to a web page like this one: http://example.com:8080/service/Service1.asmx/Method. Of course that a public access can not see any result, the port 8080 is blocked and can not be opened.

在这种情况下,我可以访问 Web 服务页面 ( http://example.com/service/),它为我提供了所有可用的方法。但是,当我尝试调用一个方法时,它会转到这样的网页:http: //example.com: 8080/service/Service1.asmx/Method 。当然那一次公开访问是看不到任何结果的,8080端口被阻塞了,无法打开。

Internally, the Web Service works on port 8080, but the public request need to be done to the port 80.

在内部,Web Service 工作在 8080 端口,但需要对 80 端口进行公共请求。

Anyone knows how can I solve my problem?

有谁知道我该如何解决我的问题?

P.S.: Using IIS 7 and Apache 2.2 under Windows Server 2008

PS:在Windows Server 2008下使用IIS 7和Apache 2.2

采纳答案by Kev

The most likely reason for this is that your web service generated WSDL will define the service endpoint address as:

最可能的原因是您的 Web 服务生成的 WSDL 将服务端点地址定义为:

http://example.com:8080/service/service1.asmx

http://example.com:8080/service/service1.asmx

You could provide a separate static WSDL definition and modify the following section to use port 80:

您可以提供单独的静态 WSDL 定义并修改以下部分以使用端口 80:

<wsdl:service name="Service1"> 
    <wsdl:port name="Service1Soap" binding="tns:Service1Soap"> 
        <soap:address location="http://example.com:8080/service/service1.asmxx" /> 
    </wsdl:port> 
    <wsdl:port name="Service1Soap12" binding="tns:Service1Soap12"> 
        <soap12:address location="http://example.com:8080/service/service1.asmx" /> 
    </wsdl:port> 
</wsdl:service>

This should cause the client to consume the WSDL and generate stub code to bind to the correct port (which is the Apache server acting as a proxy).

这应该会导致客户端使用 WSDL 并生成存根代码以绑定到正确的端口(这是充当代理的 Apache 服务器)。

Another alternative method to force the correct address to appear in the generated WDSL is to use a SoapExtensionReflectorto modify the address locationon the fly:

另一种强制正确地址出现在生成的 WDSL 中的替代方法是使用 a 动态SoapExtensionReflector修改地址location

Modify a Web Service's WSDL Using a SoapExtensionReflector

使用 SoapExtensionReflector 修改 Web 服务的 WSDL

I have used the above method successfully in the past.

我过去曾成功地使用过上述方法。

Alternatively, you could, if the client is .NET based, override the base URL for the service:

或者,如果客户端基于 .NET,您可以覆盖服务的基本 URL:

WebClientProtocol.Url Property (MSDN Library)

WebClientProtocol.Url 属性(MSDN 库)