关于web service的引用,如何重写web service的引用地址wsdl

charles_cn1 2008-11-19 11:55:00

<?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下,但是不知道如何实现,大家帮忙看下。
...全文
106 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qap22 2008-11-27
  • 打赏
  • 举报
回复
mark
byte377 2008-11-27
  • 打赏
  • 举报
回复
UP

12,165

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧