我有一个反向代理服务器后面的Web服务。现在发生的事情是,当我尝试添加Web引用来测试Web服务时,它说它无法下载wsdl文件。这是因为当请求被发送时它是https://uat.mywebservice.com/Service/Service.asmx但是当它命中反向代理然后轮胎下载wsdl和disco文件时它将链接更改为http://myservice.comp.com/Service/Service.asmx?wsdl并且这不是正确的链接为myservice.comp.com只是反向代理上的名称空间。发生的事情是soap文件中的头文件正在更新到这个命名空间而不是实际的主机名是uat.mywebservice.com,我能够看到这个使用fiddler disco文件的地址不正确。我通过使用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 :(得分:1)
我为解决类似问题所做的是强制webservice发出正确的标题。这是通过以下方式完成的:
在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");
}
}
}
}
}
}
}
并将其添加到web.config
<webServices>
<diagnostics suppressReturningExceptions="true" />
<soapExtensionReflectorTypes>
<add type="Msdn.Web.Services.Samples.WSDLReflector,App_Code"/>
</soapExtensionReflectorTypes>
</webServices>