[英]How to get the binding address from a WSDL file
I generated a proxy class given a URL to a WSDL. 我生成了给定WSDL URL的代理类。
I need to let the end-user change the service's URL to his specific URL, like this: 我需要让最终用户将服务的URL更改为其特定的URL,如下所示:
ServiceProxy.Url = [URL set by end-user];
The issue is that this URL should not point to the WSDL, it should be the binding address which is found within the WSDL (wsdl:service -> wsdl:port -> wsdl:address) (this is a SAP web service, I understand that is why I must use the binding address). 问题在于此URL不应指向WSDL,它应该是在WSDL中找到的绑定地址(wsdl:service-> wsdl:port-> wsdl:address)(这是SAP Web服务,我了解这就是为什么我必须使用绑定地址)。
I am thinking of using the XDocument class to get that value, but I am wondering if there is any "built-in" functionality in WCF or web services to get the binding address. 我正在考虑使用XDocument类来获取该值,但是我想知道WCF或Web服务中是否有任何“内置”功能来获取绑定地址。 Thank you.
谢谢。
I did a small function in VB.NET (sorry!) based on code at Parse Complex WSDL Parameter Information . 我在VB.NET中做了一个小功能(很抱歉!),它基于Parse Complex WSDL Parameter Information中的代码。 Hope it helps.
希望能帮助到你。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.