【问题标题】:How to get the binding address from a WSDL file如何从 WSDL 文件中获取绑定地址
【发布时间】:2012-11-08 05:14:56
【问题描述】:

在给定 WSDL 的 URL 的情况下,我生成了一个代理类。

我需要让最终用户将服务的 URL 更改为他的特定 URL,如下所示:

ServiceProxy.Url = [URL set by end-user];

问题是这个 URL 不应该指向 WSDL,它应该是在 WSDL 中找到的绑定地址(wsdl:service -> wsdl:port -> wsdl:address)(这是一个 SAP Web 服务,我明白这就是为什么我必须使用绑定地址)。

我正在考虑使用 XDocument 类来获取该值,但我想知道 WCF 或 Web 服务中是否有任何“内置”功能来获取绑定地址。谢谢。

【问题讨论】:

    标签: asp.net .net wcf web-services


    【解决方案1】:

    我根据Parse Complex WSDL Parameter Information 的代码在 VB.NET 中做了一个小功能(对不起!)。希望对您有所帮助。

    Public Function GetURLFromWSDL(ByVal wsdl As String) As String
        Dim request As HttpWebRequest = WebRequest.Create(wsdl)
        request.ContentType = "text/xml;charset=""utf-8"""
        request.Method = "GET"
        request.Accept = "text/xml"
    
        Using response As WebResponse = request.GetResponse()
            Using stream As Stream = response.GetResponseStream()
                Dim service As ServiceDescription = ServiceDescription.Read(stream)
                Dim binding As SoapAddressBinding = service.Services(0).Ports(0).Extensions(0)
                Return binding.Location
            End Using
        End Using
    End Function
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-24
      • 1970-01-01
      • 1970-01-01
      • 2014-12-29
      相关资源
      最近更新 更多