2016-02-14 46 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

相关问题