WCF:“为MTOM消息创建阅读器时出错"; [英] WCF: "Error creating reader for MTOM message"

查看:194
本文介绍了WCF:“为MTOM消息创建阅读器时出错";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图使MTOM在WCF客户端中工作.我尝试使用的特定功能发送了PDF文档的MTOM编码的字节数组.使用SoapUI通过WSDL测试API效果很好;但是,当我尝试在客户端中执行相同的操作时,出现以下错误:

Trying to get MTOM working in a WCF client. The particular function I'm trying to consume sends an MTOM-encoded byte array of a PDF document. Using SoapUI to test the API using the WSDL works fine; however, when I try to do the same thing in the client, I get the following error:

Error creating a reader for the MTOM message
System.Xml.XmlException: MTOM messages must have type 'application/xop+xml'.
   at System.Xml.XmlMtomReader.ReadMessageContentTypeHeader(ContentTypeHeader he
ader, String& boundary, String& start, String& startInfo)
   at System.Xml.XmlMtomReader.Initialize(Stream stream, String contentType, Xml
DictionaryReaderQuotas quotas, Int32 maxBufferSize)
   at System.Xml.XmlMtomReader.SetInput(Stream stream, Encoding[] encodings, Str
ing contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDic
tionaryReaderClose onClose)
   at System.Xml.XmlMtomReader.SetInput(Byte[] buffer, Int32 offset, Int32 count
, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, In
t32 maxBufferSize, OnXmlDictionaryReaderClose onClose)
   at System.Xml.XmlDictionaryReader.CreateMtomReader(Byte[] buffer, Int32 offse
t, Int32 count, Encoding[] encodings, String contentType, XmlDictionaryReaderQuo
tas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose)
   at System.ServiceModel.Channels.MtomMessageEncoder.MtomBufferedMessageData.Ta
keXmlReader()

Server stack trace:
   at System.ServiceModel.Channels.MtomMessageEncoder.MtomBufferedMessageData.Ta
keXmlReader()
   at System.ServiceModel.Channels.BufferedMessageData.DoTakeXmlReader()
   at System.ServiceModel.Channels.BufferedMessageData.GetMessageReader()
   at System.ServiceModel.Channels.BufferedMessage..ctor(IBufferedMessageData me
ssageData, RecycledMessageState recycledMessageState, Boolean[] understoodHeader
s, Boolean understoodHeadersModified)
   at System.ServiceModel.Channels.BufferedMessage..ctor(IBufferedMessageData me
ssageData, RecycledMessageState recycledMessageState)
   at System.ServiceModel.Channels.MtomMessageEncoder.ReadMessage(ArraySegment`1
 buffer, BufferManager bufferManager, String contentType)
   at System.ServiceModel.Channels.MessageEncoder.ReadMessage(Stream stream, Buf
ferManager bufferManager, Int32 maxBufferSize, String contentType)
   at System.ServiceModel.Channels.HttpInput.ReadChunkedBufferedMessage(Stream i
nputStream)
   at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception& req
uestException)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpCha
nnelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeS
pan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message messag
e, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean on
eway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan tim
eout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean on
eway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCall
Message methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
   at WsApiServicePortType.getDoc(getDocRequest request)
   at WsApiServicePortTypeClient.WsApiServicePortType.getDoc(getDocReq
uest request) in C:\Users\ant\documents\visual studio 2010\Projects\Client\Cl
ient\WsApiService.cs:line 3927
   at WsApiServicePortTypeClient.getDoc(String username, String ID) in C
:\Users\ant\documents\visual studio 2010\Projects\Client\Client\WsApiServic
e.cs:line 3935
   at Client.Program.Main(String[] args) in C:\Users\ant\documents\visual stu
dio 2010\Projects\Client\Client\Program.cs:line 18

现在,我已经进行了全面搜索,除了也许之外,找不到与此错误相关的内容:

Now, I've searched all over and can't find much of relevance to this error except maybe this: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/73039d75-e078-436b-a8ab-d8c7197a976b

不过,该链接中的建议对我来说毫无意义.我在代码中的任何地方都看不到响应消息作为对象进行修改的对象.所以...我在这里.我拥有的客户端非常简单:它由svcutil生成的代理类(大约)组成.进行调用的10行代码以及app.config文件.我已经将证书信息添加到配置文件中,并将messageEncoding更改为Mtom,但除此之外,它们全部由svcutil生成.

The recommendation in that link, though, make no sense to me. I can't see anywhere in my code where the response message exists as an object where I could modify it. So...here I am. The client that I have is extremely simple: it consists of the svcutil-generated proxy class, approx. 10 lines of code to make the call, and the app.config file. I've added certificate information to the config file and changed the messageEncoding to Mtom, but beyond that, it's all as-generated by svcutil.

这是客户端代码的样子(非常简单,如您所见):

Here's what the client code looks like (very simple, as you can see):

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.ServiceModel;
using System.Text;

namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                WsApiServicePortTypeClient client = new WsApiServicePortTypeClient();
                byte[] doc = client.getRecordDoc("username0000", "1234567");
                File.WriteAllBytes(@"C:\TestRecords\wcf-test.pdf", doc);
                Console.WriteLine("Ok, check it now.");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message + Environment.NewLine
                    + ex.GetBaseException().ToString() + Environment.NewLine
                    + ex.StackTrace + Environment.NewLine);
                Console.ReadLine();
            }
        }
    }
}

来自代理类:

[assembly: System.Runtime.Serialization.ContractNamespaceAttribute("http://www.<redacted>.com/ws/schemas", ClrNamespace="www.<redacted>.com.ws.schemas")]



[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://www.<redacted>.com/ws/definitions", ConfigurationName="WsApiServicePortType")]
public interface WsApiServicePortType
{
...    
    // CODEGEN: Generating message contract since the wrapper namespace (http://www.<redacted>.com/ws/schemas) of message getRecordDocRequest does not match the default value (http://www.<redacted>.com/ws/definitions)
    [System.ServiceModel.OperationContractAttribute(Action="http://localhost:8080/getRecordDoc", ReplyAction="http://www.<redacted>.com/ws/definitions/WsApiServicePortType/getRecordDocResponse")]
    [System.ServiceModel.FaultContractAttribute(typeof(www.<redacted>.com.ws.schemas.fault), Action="http://www.<redacted>.com/ws/definitions/WsApiServicePortType/getRecordDoc/Fault/wsFault", Name="fault", Namespace="http://www.<redacted>.com/ws/schemas")]
    [System.ServiceModel.XmlSerializerFormatAttribute()]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(wsError))]
    getRecordDocResponse getRecordDoc(getRecordDocRequest request);
...    
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class WsApiServicePortTypeClient : System.ServiceModel.ClientBase<WsApiServicePortType>, WsApiServicePortType
{

    public WsApiServicePortTypeClient()
    {
    }

    public WsApiServicePortTypeClient(string endpointConfigurationName) : 
            base(endpointConfigurationName)
    {
    }

    public WsApiServicePortTypeClient(string endpointConfigurationName, string remoteAddress) : 
            base(endpointConfigurationName, remoteAddress)
    {
    }

    public WsApiServicePortTypeClient(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(endpointConfigurationName, remoteAddress)
    {
    }

    public WsApiServicePortTypeClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : 
            base(binding, remoteAddress)
    {
    }

...
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    getRecordDocResponse WsApiServicePortType.getRecordDoc(getRecordDocRequest request)
    {
        return base.Channel.getRecordDoc(request);
    }

    public byte[] getRecordDoc(string username, string ID)
    {
        getRecordDocRequest inValue = new getRecordDocRequest();
        inValue.username = username;
        inValue.ID = ID;
        getRecordDocResponse retVal = ((WsApiServicePortType)(this)).getRecordDoc(inValue);
        return retVal.doc;
    }
...    
}

并且来自app.config:

And from app.config:

<?xml version="1.0"?>
<configuration>
    <system.serviceModel>
        <behaviors>
            <endpointBehaviors>
                <behavior name="NewBehavior0">
                    <clientCredentials>
                        <clientCertificate findValue="xxxxxxxx"
                            storeName="My" x509FindType="FindBySerialNumber" />
                    </clientCredentials>
                </behavior>
            </endpointBehaviors>
        </behaviors>
        <bindings>
            <basicHttpBinding>
                <binding name="WsApiServiceSoapBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Mtom" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
                    <security mode="Transport">
                        <transport clientCredentialType="Certificate" proxyCredentialType="None" realm=""/>
                        <message clientCredentialType="Certificate" algorithmSuite="Default"/>
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://wisp.<redacted>.com/services/WsApiService/"
                behaviorConfiguration="NewBehavior0" binding="basicHttpBinding"
                bindingConfiguration="WsApiServiceSoapBinding" contract="WsApiServicePortType"
                name="WsApiServicePort" />
        </client>
    </system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

此外,尽管我在粘贴之前将其从配置文件中剪切掉,但我已将其配置为用于消息跟踪和日志记录,以下是记录的内容:

Also, though I cut it out of the config file before pasting, I've configured it for message tracing and logging, and here's what gets logged:

出站:

<MessageLogTraceRecord>
<HttpRequest xmlns="http://schemas.microsoft.com/2004/06/ServiceModel/Management/MessageTrace">
<Method>POST</Method>
<QueryString></QueryString>
<WebHeaders>
<VsDebuggerCausalityData>gibberish</VsDebuggerCausalityData>
</WebHeaders>
</HttpRequest>
<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://localhost:8080/getRecordDoc</a:Action>
<a:MessageID>urn:uuid:19966f2b-b5ed-4e30-8bd9-9180fbf527bf</a:MessageID>
<ActivityId CorrelationId="9e356eb4-cbdc-407d-991b-49ed1b831037" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">95e158bd-51e7-4fe6-900b-642728f0653e</ActivityId>
<a:ReplyTo>
<a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
</a:ReplyTo>
<a:To s:mustUnderstand="1">https://www.<redacted>.com/services/WsApiService/</a:To>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<getRecordDoc xmlns="http://www.<redacted>.com/ws/schemas">
<username xmlns="">username0000</username>
<ID xmlns="">1234567</ID>
</getRecordDoc>
</s:Body>
</s:Envelope>
</MessageLogTraceRecord>

这是回应:

<MessageLogTraceRecord><![CDATA[

--MIMEBoundaryurn_uuid_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-ID: <0.urn:uuid:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@apache.org>

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns1:getRecordDocResponse xmlns:ns1="http://www.<redacted>.com/ws/schemas"><doc><xop:Include href="cid:1.urn:uuid:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@apache.org" xmlns:xop="http://www.w3.org/2004/08/xop/include"/></doc></ns1:getRecordDocResponse></soapenv:Body></soapenv:Envelope>
--MIMEBoundaryurn_uuid_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <1.urn:uuid:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@apache.org>

%PDF-1.5
(blah blah blah Wingdings!)

--MIMEBoundaryurn_uuid_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx--
]]></MessageLogTraceRecord>

跟踪日志显示"Construct ChannelFactory"和"Open ClientBase"步骤已成功完成,但是当它尝试处理操作http://localhost:8080/getRecordDoc时,启动活动边界如下所示失败:

The trace log shows that the "Construct ChannelFactory" and "Open ClientBase" steps complete successfully, but when it tries "Process action http://localhost:8080/getRecordDoc, it fails after starting the activity boundary as follows:

<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>131075</EventID>
<Type>3</Type>
<SubType Name="Error">0</SubType>
<Level>2</Level>
<TimeCreated SystemTime="2013-06-17T19:10:31.2623643Z" />
<Source Name="System.ServiceModel" />
<Correlation ActivityID="{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}" />
<Execution ProcessName="Client.vshost" ProcessID="12040" ThreadID="10" />
<Channel />
<Computer>computer</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Error">
<TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Diagnostics.ThrowingException.aspx</TraceIdentifier>
<Description>Throwing an exception.</Description>
<AppDomain>Client.vshost.exe</AppDomain>
<Exception>
<ExceptionType>System.ServiceModel.CommunicationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=publickeytokeninfo</ExceptionType>
<Message>Error creating a reader for the MTOM message</Message>
<StackTrace>
at System.ServiceModel.Channels.MtomMessageEncoder.MtomBufferedMessageData.TakeXmlReader()
at System.ServiceModel.Channels.BufferedMessageData.DoTakeXmlReader()
at System.ServiceModel.Channels.BufferedMessageData.GetMessageReader()
at System.ServiceModel.Channels.BufferedMessage..ctor(IBufferedMessageData messageData, RecycledMessageState recycledMessageState, Boolean[] understoodHeaders, Boolean understoodHeadersModified)
at System.ServiceModel.Channels.BufferedMessage..ctor(IBufferedMessageData messageData, RecycledMessageState recycledMessageState)
at System.ServiceModel.Channels.MtomMessageEncoder.ReadMessage(ArraySegment`1 buffer, BufferManager bufferManager, String contentType)
at System.ServiceModel.Channels.MessageEncoder.ReadMessage(Stream stream, BufferManager bufferManager, Int32 maxBufferSize, String contentType)
at System.ServiceModel.Channels.HttpInput.ReadChunkedBufferedMessage(Stream inputStream)
at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(Exception&amp; requestException)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
at WsApiServicePortType.getRecordDoc(getRecordDocRequest request)
at WsApiServicePortTypeClient.WsApiServicePortType.getRecordDoc(getRecordDocRequest request)
at WsApiServicePortTypeClient.getRecordDoc(String username, String stiId)
at Client.Program.Main(String[] args)
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
</StackTrace>
<ExceptionString>System.ServiceModel.CommunicationException: Error creating a reader for the MTOM message ---&gt; System.Xml.XmlException: MTOM messages must have type 'application/xop+xml'.
   at System.Xml.XmlMtomReader.ReadMessageContentTypeHeader(ContentTypeHeader header, String&amp; boundary, String&amp; start, String&amp; startInfo)
   at System.Xml.XmlMtomReader.Initialize(Stream stream, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize)
   at System.Xml.XmlMtomReader.SetInput(Stream stream, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose)
   at System.Xml.XmlMtomReader.SetInput(Byte[] buffer, Int32 offset, Int32 count, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose)
   at System.Xml.XmlDictionaryReader.CreateMtomReader(Byte[] buffer, Int32 offset, Int32 count, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose)
   at System.ServiceModel.Channels.MtomMessageEncoder.MtomBufferedMessageData.TakeXmlReader()
   --- End of inner exception stack trace ---</ExceptionString>
<InnerException>
<ExceptionType>System.Xml.XmlException, System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=publickeytokeninfo</ExceptionType>
<Message>MTOM messages must have type 'application/xop+xml'.</Message>
<StackTrace>
at System.Xml.XmlMtomReader.ReadMessageContentTypeHeader(ContentTypeHeader header, String&amp; boundary, String&amp; start, String&amp; startInfo)
at System.Xml.XmlMtomReader.Initialize(Stream stream, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize)
at System.Xml.XmlMtomReader.SetInput(Stream stream, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose)
at System.Xml.XmlMtomReader.SetInput(Byte[] buffer, Int32 offset, Int32 count, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose)
at System.Xml.XmlDictionaryReader.CreateMtomReader(Byte[] buffer, Int32 offset, Int32 count, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose)
at System.ServiceModel.Channels.MtomMessageEncoder.MtomBufferedMessageData.TakeXmlReader()
</StackTrace>
<ExceptionString>System.Xml.XmlException: MTOM messages must have type 'application/xop+xml'.
   at System.Xml.XmlMtomReader.ReadMessageContentTypeHeader(ContentTypeHeader header, String&amp; boundary, String&amp; start, String&amp; startInfo)
   at System.Xml.XmlMtomReader.Initialize(Stream stream, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize)
   at System.Xml.XmlMtomReader.SetInput(Stream stream, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose)
   at System.Xml.XmlMtomReader.SetInput(Byte[] buffer, Int32 offset, Int32 count, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose)
   at System.Xml.XmlDictionaryReader.CreateMtomReader(Byte[] buffer, Int32 offset, Int32 count, Encoding[] encodings, String contentType, XmlDictionaryReaderQuotas quotas, Int32 maxBufferSize, OnXmlDictionaryReaderClose onClose)
   at System.ServiceModel.Channels.MtomMessageEncoder.MtomBufferedMessageData.TakeXmlReader()</ExceptionString>
</InnerException>
</Exception>
</TraceRecord>
</DataItem>
</TraceData>
</ApplicationData>
</E2ETraceEvent>

我认为这与合同包装有关,如代理类文件中的CODEGEN消息所示.我找不到关于该消息的任何信息,这可以证实这一点.

I'm thinking that this has something to do with the contract wrapper as indicated by the CODEGEN messages in the proxy class file. I can't find anything about that message, though, that would confirm that.

非常感谢您的帮助.

推荐答案

更新:正如@Tone在评论中提到的那样,下面最初接受的答案是错误的.实际上,MTOM HTTP响应标头的外部Content-Type具有值"multipart/related"是有效的(并且是必需的).这是原始海报收到的标题:

UPDATE: As @Tone mentions in the comments, the original accepted answer below is wrong. It is actually valid (and required) for the outer Content-Type of an MTOM HTTP response header to have the value "multipart/related". This is the header the original poster received:

Content-Type    multipart/related; boundary="MIMEBoundaryurn_uuid_xxxxxxxxxxxxxxxxxxxxxxxxxxxx"; start-info="text/xml"; type="text/xml"; start="<0.urn:uuid:xxxxxxxxxxxxxxxxxxxxxxxxxxxx@apache.org>" 

真正的问题似乎是"type"属性是"text/xml"而不是"application/xop + xml".

The real problem seems that the "type" attribute is "text/xml" and not "application/xop+xml".

=============================================

==============================================

原始答案:

这里的Content-Type标头是多部分/相关的".这不是要发送MTOM响应的正确标题,所以我认为这是服务器错误.作为例外,"MTOM消息必须具有(内容)类型'application/xop + xml'".尝试在服务器上对其进行硬编码,或者临时在某些代理中对其进行更改,以查看wcf是否可以工作(您也可以尝试使用wcf自定义消息编码器,应重写一个属性-ContentType-以返回正确的类型).请注意,有二进制有效负载(文件附件)标准允许内容类型为"multipart/related",但wcf不支持它们.但是,这里的消息有效负载使用标记,因此我相信服务器确实意味着发送mtom,但没有使用正确的内容类型标头.

The Content-Type header here is "multipart/related". This is not the right header to send for MTOM response, so I believe this is as server error. As the exception mentions, "MTOM messages must have (content) type 'application/xop+xml'". Try to hard code it on the server, or temporaly change it in some proxy to see that wcf will work (you could also try a wcf custom message encoder, should override one property - ContentType - to return right type). Note there are binary payload (file attachment) standards that allow content type of "multipart/related" but wcf does not support them. However here the message payload uses the tag so I beleive the server does mean to send mtom but does not use the right content-type header.

BTW 这是我为wcf提到的其他附件标准的实现.可能对您有用,pdf文件将在某些属性中提供.但另一方面,由于xml使用它可能无效,因此无论如何您都可能需要在编码器中对其进行调整.因此最好的办法是解决服务器中的根本问题.

BTW here is an implementaion for the other attachment standard I mentioned for wcf. it may work for you, the pdf will be available in some property. but on the other hand since the xml uses it might not be valid so you might need to tweak it in an encoder anyway. so the best is to solve the root problem in the server.

这篇关于WCF:“为MTOM消息创建阅读器时出错";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆