关于web service的引用,如何重写web service的引用地址wsdl
<?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://localhost:13214/KingKong.WebSite/WebService.asmx?wsdl" docRef="http://localhost:13214/KingKong.WebSite/WebService.asmx" xmlns="http://schemas.xmlsoap.org/disco/scl/" />
<soap address="https://localhost:13214/KingKong.WebSite/WebService.asmx" xmlns:q1="http://webservice.enterprise.com/provisioning/" binding="q1:WebServiceSoap" xmlns="http://schemas.xmlsoap.org/disco/soap/" />
<soap address="https://localhost:13214/KingKong.WebSite/WebService.asmx" xmlns:q2="http://webservice.enterprise.com/provisioning/" binding="q2:WebServiceSoap12" xmlns="http://schemas.xmlsoap.org/disco/soap/" />
</discovery>
上面这段是引用webservice之后自动生成的,大家仔细看下,节点soap里的address值是以https开头的,而contractRef里的ref和docRef值都是以http开头的,这是如何做的呢?看下面的代码:
using System;
using System.Web.Services.Description;
namespace ***
{
/// <summary>
/// Summary description for HttpsReflector
/// </summary>
public class HttpsReflector : SoapExtensionReflector
{
public HttpsReflector()
{
//
// TODO: Add constructor logic here
//
}
public override void ReflectMethod()
{
//throw new NotImplementedException();
}
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 soapAddressBinding = extension as SoapAddressBinding;
if (soapAddressBinding != null)
{
soapAddressBinding.Location = soapAddressBinding.Location.Replace("http://", "https://");
}
}
}
}
}
}
}
然后在web.config文件里配置如下:
<webServices>
<soapExtensionReflectorTypes>
<clear/>
<add type="***.HttpsReflector, ***"/>
</soapExtensionReflectorTypes>
</webServices>
***是HttpsReflector类的命名空间。这样就会实现上面的情况,但是,现在的问题是,如何将contractRef节点里的ref和docRef值都改为https开头,我查了msdn,貌似只有一个ContractReference类于此相关,在System.Web.Services.Discovery下,但是不知道如何实现,大家帮忙看下。 --------------------编程问答-------------------- UP --------------------编程问答-------------------- mark
补充:.NET技术 , Web Services