Xml字典读取器错误"MTOM messages must have media type 'multipart' and media subtype 'related'."



我正在尝试使用XcmlDictionaryReader阅读c#的MTOM附件。

using (Porsche_KPM.CertificateWebClient client = new Porsche_KPM.CertificateWebClient(aCertificate))
{
Session.FormMain.ProgressStart($"Downloading Attachment {aDefectID}/{aAttachmentID}");
try
{
byte[] postArray = Encoding.UTF8.GetBytes($"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:v3='http://xmldefs.volkswagenag.com/PP/QM/GroupProblemManagementService/V3'><soapenv:Header><To xmlns='http://www.w3.org/2005/08/addressing'>ws://volkswagenag.com/PP/QM/GroupProblemManagementService/V3</To><Action xmlns='http://www.w3.org/2005/08/addressing'>http://xmldefs.volkswagenag.com/PP/QM/GroupProblemManagementService/V3/KpmService/GetDocumentRequest</Action><MessageID xmlns='http://www.w3.org/2005/08/addressing'>${{= "urn:uuid:" + UUID.randomUUID()}}</MessageID></soapenv:Header><soapenv:Body><v3:GetDocument><UserAuthentification><UserId>{aUsername}</UserId></UserAuthentification><ProblemNumber>{aDefectID}</ProblemNumber><DocumentId>{aAttachmentID}</DocumentId></v3:GetDocument></soapenv:Body></soapenv:Envelope>");
Console.WriteLine($"GetLocalFilename from URL {aURL} of Attachment {aAttachmentID} belonging to Defect {aDefectID}");
byte[] result = client.UploadData(aURL, postArray);
byte[] pattern = Encoding.UTF8.GetBytes("Content-Type:");
XmlDictionaryReader reader = XmlDictionaryReader.CreateMtomReader(result, Search(result, pattern), result.Length - Search(result, pattern), Encoding.UTF8, XmlDictionaryReaderQuotas.Max);
....
}

不幸的是,这不起作用,因为我在尝试这样做时得到以下错误消息:

MTOM消息必须具有媒体类型'multipart'和媒体子类型'related'。

来自服务器的响应如下所示:

--uuid:97e24f5e-b21a-4bf8-be36-d704e558b1b9
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><wsu:Timestamp wsu:Id="7a9caa9d-c095-4128-8151-ae5735d624db" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsu:Created>2023-04-04T11:39:53Z</wsu:Created><wsu:Expires>2023-04-04T11:44:53Z</wsu:Expires></wsu:Timestamp><saml2:Assertion ID="daedbfbc-9cf1-4b15-9d67-826790268915" IssueInstant="2023-04-04T11:39:53Z" Version="2.0" xmlns:vwsu="http://xmldefs.volkswagenag.com/Technical/Security/UsernameToken/V1" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion"><saml2:Issuer>https://ws-gateway.volkswagenag.com</saml2:Issuer><saml2:Subject><saml2:NameID Format="urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified" NameQualifier="http://xmldefs.volkswagenag.com/Technical/Security/NameQualifier/V1#Anonymous">UNKNOWN</saml2:NameID><saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:sender-vouches"/></saml2:Subject><saml2:Conditions NotBefore="2023-04-04T11:38:53Z" NotOnOrAfter="2023-04-04T11:44:53Z"/><saml2:Advice><saml2:Assertion ID="227d6d16-48ca-4139-9b4b-82679026e2e5" IssueInstant="2023-04-04T11:39:53Z" Version="2.0"><saml2:Issuer>https://ws-gateway.volkswagenag.com</saml2:Issuer><saml2:Subject><saml2:NameID Format="urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified" NameQualifier="http://xmldefs.volkswagenag.com/Technical/Security/NameQualifier/V1#UMSGlobalUserID">DUONZQM</saml2:NameID><saml2:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:sender-vouches"/></saml2:Subject><saml2:Conditions NotBefore="2023-04-04T11:38:53Z" NotOnOrAfter="2023-04-04T11:44:53Z"/><saml2:AuthnStatement AuthnInstant="2023-04-04T11:39:53Z"><saml2:AuthnContext><saml2:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:TLSClient</saml2:AuthnContextClassRef></saml2:AuthnContext></saml2:AuthnStatement><saml2:AttributeStatement><saml2:Attribute Name="ValidationType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><saml2:AttributeValue>sc:no-credential-validation-type</saml2:AttributeValue></saml2:Attribute></saml2:AttributeStatement></saml2:Assertion></saml2:Advice></saml2:Assertion></wsse:Security><To wsu:Id="51b6df08-ce37-4b04-93bf-ae5735d6dbf8" xmlns="http://www.w3.org/2005/08/addressing" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">ws://volkswagenag.com/PP/QM/GroupProblemManagementService/V3</To><Action wsu:Id="6706359a-da0a-4521-af5e-ae5735d615b9" xmlns="http://www.w3.org/2005/08/addressing" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">http://xmldefs.volkswagenag.com/PP/QM/GroupProblemManagementService/V3/KpmService/GetDocumentResponse</Action><MessageID wsu:Id="89bf4712-f8c7-4fbc-acfe-ae5735d67e0b" xmlns="http://www.w3.org/2005/08/addressing" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">}</MessageID><wsa:RelatesTo xmlns:wsa="http://www.w3.org/2005/08/addressing">}</wsa:RelatesTo></soap:Header><soap:Body><ns2:GetDocumentResponse xmlns:ns2="http://xmldefs.volkswagenag.com/PP/QM/GroupProblemManagementService/V3"><GetDocumentResponseInternal><ResponseMessage><MessageId>INFO_001</MessageId><MessageType>MT_INFO</MessageType><MessageText>Method completed successfully</MessageText><SessionKey>de.volkswagen.kpm.backend.command.KPMSessionImpl@bb1e645d</SessionKey><VersionId>release_17.3.2</VersionId><VersionDate>Fri Mar 17 11:33:58 CET 2023</VersionDate></ResponseMessage><Document><Name>Pound_layer_cake</Name><Suffix>jpg</Suffix><Description>Uploaded 20230216_10-13-37</Description><AccessRight>0</AccessRight><FileType>01</FileType><Data><xop:Include href="cid:899e472a-53ee-40ad-bfbf-f9518c10696a-40295@cxf.apache.org" xmlns:xop="http://www.w3.org/2004/08/xop/include"/></Data></Document></GetDocumentResponseInternal></ns2:GetDocumentResponse></soap:Body></soap:Envelope>
--uuid:97e24f5e-b21a-4bf8-be36-d704e558b1b9
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
Content-ID: <899e472a-53ee-40ad-bfbf-f9518c10696a-40295@cxf.apache.org>
[Data of the file]

现在我不确定这是什么意思,虽然我假设一个报头丢失了,并尝试对MTOM报头做进一步的研究,看看是否有像媒体类型报头的东西,并试图找到有关错误消息本身的信息。但我没找到任何有用的信息。我该如何解决这个问题?

如果您可以访问服务器,我会尝试添加这样的内容类型头:

client.Headers.Add("Content-Type", "multipart/related");

你正在创建一个MtomReader,所以如果服务器没有发送mtomm编码的响应,你将无法用给定的代码片段读取它。

最新更新