【发布时间】:2015-08-26 16:53:35
【问题描述】:
我正在尝试与之通信的第 3 方 WCF 服务。我无法获取它的 WSDL,或使用服务引用连接它。
我使用 Fiddler 来监控和模拟流量,并且效果很好,但我不确定如何将 application/msbin1 格式解码为可用格式(我希望它在解码结束时应该是 XML)。我已经安装了 WCF 二进制插件。原始文本是(缩短和审查):
@getAllEntriesResponsehttp://tempuri.org/@getAllEntriesResult a
DomainServices i)http://www.w3.org/2001/XMLSchema-instance^TotalCount ^
RootResults b6http://schemas.datacontract.org/...
同时 WCF 二进制文件看起来像(xml 树):
getAllEntriesResponse xmlns="http://tempuri.org/"
-- getAllEntriesResult xmlns:a="DomainServices" xmlns:i="http://www.w3.org/2001/XMLSchema-instance
---- a:TotalCount
...
到目前为止,我为模拟这个而编写的代码是:
IWebProxy proxy = new WebProxy("127.0.0.1",8888);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("<url>.sc/binary/getAllEntries?elementID=0");
request.Method = "GET";
request.ContentType = "application/msbin1";
request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
request.Proxy = proxy;
//request.GetRequestStream().Write(b, 0, b.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
byte[] b = new byte[response.ContentLength];
response.GetResponseStream().Read(b, 0, b.Length);
XmlReader binaryreader = XmlDictionaryReader.CreateBinaryReader(b, 0, b.Length, dictionary, XmlDictionaryReaderQuotas.Max);
XmlDocument xdoc = new XmlDocument();
xdoc.Load(binaryreader);
return xdoc;
我确实得到了 Fiddler 得到的同样的东西,所以我的请求按预期工作(据我所知)。我认为出错的是字节(b)的格式是我前面提到的,所以当它传递给 XML 时它会出错(无论如何它看起来不像 XML,我不确定是否它可以读取这个“二进制 xml”)。
我得到的异常是 xdoc.Load(binaryreader) 处的“输入源格式不正确”,带有堆栈跟踪:
at System.Xml.XmlExceptionHelper.ThrowXmlException(XmlDictionaryReader reader, String res, String arg1, String arg2, String arg3)
at System.Xml.XmlBufferReader.ReadValue(XmlBinaryNodeType nodeType, ValueHandle value)
at System.Xml.XmlBinaryReader.ReadNode()
at System.Xml.XmlBinaryReader.Read()
at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
...
注意:字典中填充了 485 个条目,这些条目(据我所知)是已知的重复出现字符串的速记列表,用于减少传输大小。我的清单示例如下:
dictionary.Add("mustUnderstand");
dictionary.Add("Envelope");
dictionary.Add("http://www.w3.org/2003/05/soap-envelope");
dictionary.Add("http://www.w3.org/2005/08/addressing");
dictionary.Add("Header");
dictionary.Add("Action");
dictionary.Add("To");
dictionary.Add("Body");
...
dictionary.Add("Detail");
我不确定我现在缺少什么。我敢肯定它很小,但我对这些东西还不够熟悉,无法让它正常工作。
感谢任何帮助,谢谢!
【问题讨论】:
-
只是出于好奇,您为什么不能获得 WSDL?第三方不愿意给吗?听起来可能会禁用元数据发布,但在这种情况下,他们应该为您提供 WSDL。
-
一个公平的问题。我没有要求 WSDL。当我使用 ?WSDL 查询服务时,它不会自动提供。这是我作为用户的服务,我正在尝试为它构建更好的用户界面。
-
如果元数据发布被禁用(听起来好像是这样),那么使用
?WSDL查询服务不会得到任何东西。我会联系服务的所有者并索要 WSDL。它会为您节省大量时间和麻烦 :) -
我会考虑这样做的。我知道如果该服务被禁用,他们可能不希望人们这样做。这引起了人们对在线提供帮助的担忧。我的部分兴趣是作为一种爱好,我最近做了一些类似的事情来学习 JSON。不管我是否获得了 WDSL,我仍然对它在底层是如何工作的以及这种格式是什么感兴趣(从我收集的二进制 XML 中,但我找不到太多关于它的信息)。
标签: c# xml web-services wcf soap