2016-02-14 48 views
0

我在使用IIS Express的Windows 10上運行WCF服務。我從嵌入式設備發送消息,並在嵌入式代碼中手動形成POST請求和XML。我已經能夠發送簡單的「單一部分」消息並獲得成功的迴應。來自嵌入式設備的WCF MIME消息是「格式錯誤」 - 爲什麼?

現在,我正在嘗試發送一個MIME多部分消息。我能夠用Windows客戶端成功完成此任務,並使用Wireshark捕獲消息文本。我正嘗試從嵌入式設備發送相同的文本。看起來這應該工作,但是服務器返回一個錯誤:

HTTP/1.1 400 Bad Request 
Cache-Control: private 
Server: Microsoft-IIS/10.0 
MIME-Version: 1.0 
X-AspNet-Version: 4.0.30319 
X-Powered-By: ASP.NET 
Date: Sun, 14 Feb 2016 01:45:36 GMT 
Connection: close 
Content-Length: 0 

我能夠使WCF跟蹤和查明原因被認爲是消息「畸形」,如下面的消息日誌記錄:

<MessageLogTraceRecord Time="2016-02-13T19:45:36.7215337-06:00" Source="Malformed" xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace"><![CDATA[--uuid:34450500-f156-44c4-9029-39b25c2794d5+id=2 
Content-ID: <http://tempuri.org/0> 
Content-Transfer-Encoding: 8bit 
Content-Type: application/xop+xml;charset=utf-8;type="application/soap+xml" 

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://tempuri.org/IService1/StoreData</a:Action><a:MessageID>urn:uuid:c6cb5104-adfd-4040-a2eb-a2cb659e8f2a</a:MessageID><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">http://192.168.0.10:8080/Service1.svc</a:To></s:Header><s:Body><StoreData xmlns="http://tempuri.org/"><device>22222</device><time>2016-01-10T14:34:54.2151851-06:00</time><data>AwIB</data></StoreData></s:Body></s:Envelope> 
--uuid:34450500-f156-44c4-9029-39b25c2794d5+id=2--]]></MessageLogTraceRecord> 

我挖進一步發現在svclog以下堆棧跟蹤:

<Exception><ExceptionType>System.ServiceModel.CommunicationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Error creating a reader for the MTOM message</Message><StackTrace> at System.ServiceModel.Channels.MtomMessageEncoder.MtomBufferedMessageData.TakeXmlReader() 
at System.ServiceModel.Channels.BufferedMessageData.GetMessageReader() 
at ... 
at System.ServiceModel.Channels.MtomMessageEncoder.MtomBufferedMessageData.TakeXmlReader() 
--- End of inner exception stack trace ---</ExceptionString><InnerException><ExceptionType>System.FormatException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType><Message>Unexpected end of file.</Message><StackTrace> at System.Xml.MimeReader.ReadNextPart() 
at System.Xml.XmlMtomReader.ReadMimePart(String uri) 
at ... 
at System.ServiceModel.Channels.MtomMessageEncoder.MtomBufferedMessageData.TakeXmlReader()</ExceptionString></InnerException></Exception> 

文本文件的意外結束錯誤突出,所以我想也許我的長度設置不正確。這是計算,但我試圖添加許多額外的\ n沒有幫助。

我不確定的一件事是預計什麼類型的行結束。我假設只有0xA(LF)而不是0xD(CR),但我不知道行結束是否導致計數不正確。

爲什麼這封郵件被拒絕的任何想法?

回答

1

是的,問題與行結束有關。 Windows WCF服務器期望在每行結束時使用CR + LF。我的嵌入式客戶端只發送LF。不幸的是,這在消息轉儲或錯誤消息中並不明顯。比較Wireshark 二進制捕獲來看看區別。

+0

一個SOAP的MIME/MTOM消息驗證器肯定會得心應手,但我找不到一個。我有人知道任何? – mek363

相關問題