【问题标题】:Query Web Service for list of Messages?查询 Web 服务以获取消息列表?
【发布时间】:2008-09-17 20:02:07
【问题描述】:

是否有一种直接的方法来查询 Web 服务以查看它支持哪些消息?我正在处理的 C# .NET 应用程序需要能够处理旧版本的 Web 服务,它没有实现我要发送的消息。 Web 服务不公开版本号,因此 B 方案是查看消息是否已定义。

我假设我可以对 WSDL 发出 HTTP 请求并对其进行解析,但在我走这条路之前,我想确保没有更简单的方法。

更新: 我决定获取 WSDL 并直接获取消息。这是获取所有消息的草稿:

HttpWebRequest webRequest = (HttpWebRequest) WebRequest.Create( "http://your/web/service/here.asmx?WSDL" );
webRequest.PreAuthenticate = // details elided
webRequest.Credentials = // details elided
webRequest.Timeout = // details elided
HttpWebResponse webResponse = (HttpWebResponse) webRequest.GetResponse();

XPathDocument xpathDocument = new XPathDocument( webResponse.GetResponseStream() );
XPathNavigator xpathNavigator = xpathDocument.CreateNavigator();

XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager( new NameTable() );
xmlNamespaceManager.AddNamespace( "wsdl", "http://schemas.xmlsoap.org/wsdl/" );

foreach( XPathNavigator node in xpathNavigator.Select( "//wsdl:message/@name", xmlNamespaceManager ) )
{
    string messageName = node.Value;
}

【问题讨论】:

    标签: c# .net web-services soap


    【解决方案1】:

    解析 WSDL 可能是最简单的方法。使用 WCF,还可以在运行时下载 WSDL,本质上是通过代码在其上运行 svcutil,最后得到一个动态生成的代理,您可以检查其结构。有关运行时生成代理的示例,请参阅 https://docs.microsoft.com/en-us/archive/blogs/vipulmodi/dynamic-programming-with-wcf

    【讨论】:

      【解决方案2】:

      我很确定 WSDL 是做到这一点的方法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-15
        • 2014-08-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多