首页 新闻 会员 周边

.NET的webservice服务端在什么时候可以获取到生成的WSDL并修改?

0
[待解决问题]
public class OuterPortReflector : SoapExtensionReflector
    {
        private static Dictionary<string, bool> portsName = new Dictionary<string, bool>();

        public override void ReflectMethod()
        {            
        }

        public override void ReflectDescription()
        {
            ServiceDescription description = ReflectionContext.ServiceDescription;
            foreach (Service service in description.Services)
            {
                foreach (Port port in service.Ports)
                {
                    if (!portsName.ContainsKey(port.Binding.Name))
                    {
                        portsName.Add(port.Binding.Name, true);
                    }

                    foreach (ServiceDescriptionFormatExtension extension in port.Extensions)
                    {
                        SoapAddressBinding binding = extension as SoapAddressBinding;
                        if (null != binding)
                        {
                            binding.Location = binding.Location.Replace("http://localhost", "http://I can remove this Port");
                        }
                        else
                        {
                            // 这里在实际调试中并不会进来

                            HttpAddressBinding httpBinding = extension as HttpAddressBinding;
                            if (httpBinding != null)
                            {
                                httpBinding.Location = httpBinding.Location.Replace("http://localhost", "http://I can remove this Port");
                            }
                            else
                            {
                                Soap12AddressBinding soap12Binding = extension as Soap12AddressBinding;
                                if (soap12Binding != null)
                                {
                                    soap12Binding.Location = soap12Binding.Location.Replace("http://localhost", "http://I can remove this Port");
                                }
                            }
                        }
                    }
                }
            }

            // 通过查看生成的webService.wsdl 可以发现 并未有HTTP的port
            description.Write("D:\\Logs\\webService.wsdl");
        }      
    }
View Code

以上代码是通过使用SoapExtensionReflector修改soapAddress,能够成功的修改,并且能够获取到wsdl明细,但其中并不包含http的port,并未修改到httpAddress。

 

想知道有何种方式类似于SoapExtensionReflector一样能修改http port的地址。或者在哪能够获取到完整的WSDL并修改,再发布出去。

使用ProtocolReflector?ServiceDescriptionFormatExtension(这个只是用来添加的啊)?

 

附上WSDL:

  <wsdl:service name="WebService1">
    <wsdl:port name="WebService1Soap" binding="tns:WebService1Soap">
      <!--这个location地址已经被修改到了-->
      <soap:address location="http://I can remove this Port:3821/WebService1.asmx" />
    </wsdl:port>
    <wsdl:port name="WebService1Soap12" binding="tns:WebService1Soap12">
      <!--这个location地址已经被修改到了-->
      <soap12:address location="http://I can remove this Port:3821/WebService1.asmx" />
    </wsdl:port>
    <wsdl:port name="WebService1HttpGet" binding="tns:WebService1HttpGet">
    <!--这个location地址未被修改到!!HttpGet-->
      <http:address location="http://localhost:3821/WebService1.asmx" />
    </wsdl:port>
    <wsdl:port name="WebService1HttpPost" binding="tns:WebService1HttpPost">
      <!--这个location地址未被修改到!!HttpPost-->
      <http:address location="http://localhost:3821/WebService1.asmx" />
    </wsdl:port>
  </wsdl:service>
View Code
子默的主页 子默 | 初学一级 | 园豆:4
提问于:2014-01-08 18:30
< >
分享
所有回答(2)
0

不明白你说的修改是什么意思,我理解两种情况:

1、你想修改WSDL的内容,如果这样,你可以通过直接修改你自己的WebService完成

2、如果你想要修改调用你的Service的代理文件的URL,可以直接重载代理文件方式,更改URL。

不知道你是哪种情况 ?你想要完成什么功能?

LLKey221 | 园豆:172 (初学一级) | 2014-01-08 21:57

问题详细背景: http://q.cnblogs.com/q/58713/

问题详细描述:http://stackoverflow.com/questions/1531448/asp-net-web-service-changes-port-on-invoke 和这个问题完全一样

更接近您所说的第二种情况

 

支持(0) 反对(0) 子默 | 园豆:4 (初学一级) | 2014-01-09 09:42

@子默: 我想确定一个问题,你是否是希望调用的时候更改URL?

支持(0) 反对(0) LLKey221 | 园豆:172 (初学一级) | 2014-01-09 16:14

@LLKey221: 我是希望在客户端拿到WSDL描述的时候 已经是经过我更改过的url,而不是在客户端那边修改。

支持(0) 反对(0) 子默 | 园豆:4 (初学一级) | 2014-01-10 09:01
0

哥们,这个问题你最后是怎么解决的。

我也用的上面的代码,但是我的是成功了的。

你把web.config的文件节点加上下面的试试呢

<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
<add name="HttpSoap"/>
</protocols>

红萦 | 园豆:204 (菜鸟二级) | 2014-09-03 10:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册