是否有直接的方式来查询Web服务以查看它支持哪些消息?我正在处理的C#.NET应用程序需要能够处理旧版本的Web服务,该服务没有实现我试图发送的消息。 Web服务不公开版本号,因此计划B将查看消息是否已定义。查询Web服务的消息列表?
我假设我可以为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;
}