反向代理后面的WebService

问题描述:

enter image description here反向代理后面的WebService

我有一个位于反向代理后面的web服务。现在发生了什么是当我尝试添加Web引用来测试Web服务,然后它说它无法下载wsdl文件。这是因为当请求被发送时它是https://uat.mywebservice.com/Service/Service.asmx,但是当它遇到反向代理并且然后轮胎下载wsdl和disco文件时,它将链接改变为http://myservice.comp.com/Service/Service.asmx?wsdl,并且这不是正确的链接,因为myservice.comp.com是只是反向代理上的名称空间。发生了什么是肥皂文件中的标题正在更新到这个命名空间,而不是实际的主机名是uat.mywebservice.com,我能够看到这使用fiddler迪斯科文件有不正确的地址。我通过使用wsdl.exe工具创建了一个代理类,然后将该类中的所有不正确链接更新为正确的主机名。

有没有什么办法可以确保地址在点击反向代理时保持正确。

错误:

<?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> 

正确

<?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> 
+0

这是什么excatly我问题是http://blog.graffen.dk/post/Accessing-a-NET-Web-Service-located-behind-a-proxy.aspx我已经尝试过这里提出的解决方案。它适用于.Net环境。我不确定不同平台上的客户如何使其工作 – Pinu 2012-04-18 19:24:54

我做的事解决了类似的问题是强制web服务发出正确的头。

  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>