簡體   English   中英

反向代理背后的 WebService

[英]WebService behind reverse proxy

我有一個 Web 服務,它位於這樣的反向代理后面:

反向代理

現在發生的情況是,當我嘗試添加 Web 引用來測試 Web 服務時,它說無法下載 wsdl 文件。 那是因為當請求被發送時它是https://uat.mywebservice.com/Service/Service.asmx但是當它擊中反向代理然后厭倦下載 wsdl 和迪斯科文件時,它會將鏈接更改為http: //myservice.comp.com/Service/Service.asmx?wsdl這不是正確的鏈接,因為myservice.comp.com只是反向代理上的名稱空間。

正在發生的事情是,soap 文件中的標題被更新到這個命名空間,而不是實際的主機名uat.mywebservice.com ,我能夠看到使用 fiddler disco 文件的地址不正確。 我通過使用 wsdl.exe 工具創建一個代理類,然后將該類中的所有錯誤鏈接更新為正確的主機名。

有什么方法可以確保在點擊反向代理時地址保持正確。

不正確: mywebservice.comp.com

<?xml version="1.0" encoding="utf-8" ?> 
<discovery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/disco/"> 
    <contractRef ref="http://mvwebservice.comp.com/Service/Service.asmx?wsdl" docRef="http://mvwebservice.comp.com/Service/Service.asmx" xmlns="http://schemas.xmlsoap.org/disco/scl/" /> 
    <soap address="http://mywebservice.comp.com/Service/Service.asmx" xmlns:q1="http://tempuri.org/" binding="q1:ServiceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" /> 
    <soap address="http://mywebservice.comp.com/Service/Service.asmx" xmlns:q2="http://tempuri.org/" binding="q2:ServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" /> 
</discovery>

正確: uat.mywebservice.com

<?xml version="1.0" encoding="utf-8" ?> 
<discovery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/disco/"> 
    <contractRef ref="https://uat.mvwebservice.com/Service/Service.asmx?wsdl" docRef="https://uat.mvwebservice.com/Service/Service.asmx" xmlns="http://schemas.xmlsoap.org/disco/scl/" /> 
    <soap address="https://uat.mywebservice.com/Service/Service.asmx" xmlns:q1="http://tempuri.org/" binding="q1:ServiceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" /> 
    <soap address="https://uat.mywebservice.com/Service/Service.asmx" xmlns:q2="http://tempuri.org/" binding="q2:ServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" /> 
</discovery>

我為解決類似問題所做的是強制網絡服務發出正確的標頭。

您可以執行以下操作:

  1. App_Code文件夾中創建以下類:

     using System; using System.Web.Services.Description; namespace Msdn.Web.Services.Samples { /// <summary> Summary description for WSDLReflector </summary> public class WSDLReflector : SoapExtensionReflector { public override void ReflectMethod() { //no-op } public override void ReflectDescription() { ServiceDescription description = ReflectionContext.ServiceDescription; foreach (Service service in description.Services) { foreach (Port port in service.Ports) { foreach (ServiceDescriptionFormatExtension extension in port.Extensions) { SoapAddressBinding binding = extension as SoapAddressBinding; if (null != binding) { binding.Location = binding.Location.Replace("http://mywebservice.comp.com", "https://uat.mywebservice.com"); } } } } } } }
  2. 並將其添加到web.config

     <webServices> <diagnostics suppressReturningExceptions="true" /> <soapExtensionReflectorTypes> <add type="Msdn.Web.Services.Samples.WSDLReflector,App_Code"/> </soapExtensionReflectorTypes> </webServices>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM