问题描述
我有一个反向代理后面的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工具创建了一个代理类,然后将该类中的所有不正确链接更新为正确的主机名,从而得出结论.
I have a web service which is behind a reverse proxy. Now what is happening is when I try to add a web reference to test the web service then it says that it is unable to download the wsdl file. That is because when the request is sent it it is https://uat.mywebservice.com/Service/Service.asmx but when it hits the reverse proxy and then tires to download the wsdl and disco files it changes the link to http://myservice.comp.com/Service/Service.asmx?wsdl and it this is not the right link as myservice.comp.com is just a name space on reverse proxy. What is happening is headers in the soap file are getting updated to this namespace instead of the actual host name which is uat.mywebservice.com , I was able to see this using fiddler disco file has incorrect address. I had a worked out by creating a proxy class using wsdl.exe tool and then updated all the incorrect links in that class to right host name.
有什么方法可以确保在击中反向代理时地址仍然正确.
Is there any way that I can make sure the address remains correct when hitting the reverse proxy.
错误:
<?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>
推荐答案
我解决类似问题的方法是强制Web服务发出正确的标头.这是通过以下方式完成的:
What I did to solve a similar problem was to force the webservice to emit the correct headers. This was done by:
-
在App_Code文件夹中创建以下类:
creating the following class in the App_Code folder:
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
and adding this to web.config
<webServices>
<diagnostics suppressReturningExceptions="true" />
<soapExtensionReflectorTypes>
<add type="Msdn.Web.Services.Samples.WSDLReflector,App_Code"/>
</soapExtensionReflectorTypes>
</webServices>
这篇关于反向代理背后的WebService的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!