5

我正在使用一个 Web 服务,在该服务中我发送一个带有附件的请求,我们收到来自服务器的包含各种信息的响应。我已经在另一个问题中记录了将请求放在一起的一些问题,将附件添加到 SOAP 请求,但这一点已经解决,现在响应中出现了另一个问题。

我们收到响应正常,但抛出错误说明:

响应不是格式良好的 XML。

内部异常是:

WSE1608:指定内容 ID 的流中没有 XOP 部件:<rootpart*36875c60-630c-4e23-9e74-f9a9c7547fc7@example.jaxws.sun.com>

返回的 xml 如下所示:

--uuid:36875c60-630c-4e23-9e74-f9a9c7547fc7
Content-Type: application/xop+xml;charset=utf-8;type="text/xml";
Content-ID: <rootpart*36875c60-630c-4e23-9e74-f9a9c7547fc7@example.jaxws.sun.com>
content-transfer-encoding: binary

  <?xml version="1.0" encoding="utf-8"?>
  <soapenv:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
      <payloadManifest xmlns="http://(namespace)">
        <manifest contentID="content0" element="ProcessAttachment" namespaceURI="http://(namespace)" version="2.01"/>
      </payloadManifest>
    </soapenv:Header>
    <soapenv:Body>
      <tran:ProcessMessageResponse xmlns="http://(namespace)" xmlns:ns2="http://(ns2Namespace)" xmlns:ns3="http://(ns3Namespace)" xmlns:tran="http://(tranNamespace)">
        <tran:payload>
          <tran:content id="content0">
            <s:ShowServiceProcessingAdvisory xmlns:s="http://(sNamespace)">
              <s:ApplicationArea>
                <s:Sender>
                  <s:Component>Global Warranty Management</s:Component>
                  <s:Task>ShowAttachments</s:Task>
                  <s:CreatorNameCode>Creator</s:CreatorNameCode>
                  <s:SenderNameCode>GM</s:SenderNameCode>
                </s:Sender>
                <s:CreationDateTime>2012-01-10T12:58:27Z</s:CreationDateTime>
                <s:Destination>
                  <s:DestinationNameCode>XX</s:DestinationNameCode>
                  <s:DealerNumber>234567</s:DealerNumber>
                  <s:DealerCountry>US</s:DealerCountry>
                </s:Destination>
              </s:ApplicationArea>
              <s:DataArea>
                <s:Show/>
                <s:ServiceProcessingAdvisory>
                  <s:Header>
                    <s:SecondaryDealerNumber>253909</s:SecondaryDealerNumber>
                    <s:Disposition>
                      <s:RepairOrder>
                        <s:WarrantyClaim xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:WarrantyClaimExtended">
                          <s:OEMClaimNumber>00112233445566778899</s:OEMClaimNumber>
                          <gwm:Attachment xmlns:gwm="http://(gwmNamespace)">
                            <gwm:AttachmentId>5678987</gwm:AttachmentId>
                            <gwm:Filename>14.jpg</gwm:Filename>
                          </gwm:Attachment>
                        </s:WarrantyClaim>
                      </s:RepairOrder>
                    </s:Disposition>
                  </s:Header>
                </s:ServiceProcessingAdvisory>
              </s:DataArea>
            </s:ShowServiceProcessingAdvisory>
          </tran:content>
        </tran:payload>
      </tran:ProcessMessageResponse>
    </soapenv:Body>
  </soapenv:Envelope>

  --uuid:36875c60-630c-4e23-9e74-f9a9c7547fc7--

我假设这是由于 MIME 部分导致的错误,但是应该如何处理呢?

我可以补充一下,这是在 SoapUI 中返回的完全相同的 XML,并且是预期的返回 XML。另外,我可能会补充说,需要 WSE 有两个原因,因为 Web 服务的第三方开发人员拒绝改变他们的工作方法,而且我们也依赖 VS 2005,因此不能使用 WCF,尤其是有截止日期悬在我们头顶。

编辑:我收到的实际回复如下,为了便于阅读,我在上面对其进行了格式化

HTTP/1.1 200 OK
Date: Mon, 16 Jan 2012 09:44:22 GMT
Server: ACE XML Gateway
Cache-Control: no-cache="Set-Cookie"
Set-Cookie: JSESSIONID=h3LnPTxYdZJ3wp4zFl2GV3BYQ7fZD1p8WbvPgl1Qq95g1F9GQhMC!1396094632; path=/
X-Powered-By: Servlet/2.5 JSP/2.1
Content-Type: multipart/related; type="application/xop+xml";  boundary="uuid:a9a94e4e-5134-4995-8884-dfd4d65b7784"; start="<rootpart*a9a94e4e-5134-4995-8884-dfd4d65b7784@example.jaxws.sun.com>"; start-info="text/xml"
Content-Length: 2296
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive


--uuid:a9a94e4e-5134-4995-8884-dfd4d65b7784
Content-Type: application/xop+xml;charset=utf-8;type="text/xml";
Content-ID: <rootpart*a9a94e4e-5134-4995-8884-dfd4d65b7784@example.jaxws.sun.com>
content-transfer-encoding: binary

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><payloadManifest xmlns="http://www.starstandards.org/webservices/2005/10/transport"><manifest contentID="content0" element="ProcessAttachment" namespaceURI="http://www.starstandards.org/STAR" version="2.01"/></payloadManifest></soapenv:Header><soapenv:Body><tran:ProcessMessageResponse xmlns="http://www.starstandards.org/STAR" xmlns:ns2="http://www.gm.com/2006/GWM" xmlns:ns3="http://www.starstandards.org/webservices/2005/10/transport" xmlns:tran="http://www.starstandards.org/webservices/2005/10/transport"><tran:payload><tran:content id="content0"><s:ShowServiceProcessingAdvisory xmlns:s="http://www.starstandards.org/STAR"><s:ApplicationArea><s:Sender><s:Component>Global Warranty Management</s:Component><s:Task>ShowAttachments</s:Task><s:CreatorNameCode>General Motors</s:CreatorNameCode><s:SenderNameCode>GM</s:SenderNameCode></s:Sender><s:CreationDateTime>2012-01-16T09:44:24Z</s:CreationDateTime><s:Destination><s:DestinationNameCode>XX</s:DestinationNameCode><s:DealerNumber>253909</s:DealerNumber><s:DealerCountry>US</s:DealerCountry></s:Destination></s:ApplicationArea><s:DataArea><s:Show/><s:ServiceProcessingAdvisory><s:Header><s:SecondaryDealerNumber>253909</s:SecondaryDealerNumber><s:Disposition><s:RepairOrder><s:WarrantyClaim xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:WarrantyClaimExtended"><s:OEMClaimNumber>001116695583</s:OEMClaimNumber><gwm:Attachment xmlns:gwm="http://www.gm.com/2006/GWM"><gwm:AttachmentId>5677606</gwm:AttachmentId><gwm:Filename>1127.jpg</gwm:Filename></gwm:Attachment></s:WarrantyClaim></s:RepairOrder></s:Disposition></s:Header></s:ServiceProcessingAdvisory></s:DataArea></s:ShowServiceProcessingAdvisory></tran:content></tran:payload></tran:ProcessMessageResponse></soapenv:Body></soapenv:Envelope>

--uuid:a9a94e4e-5134-4995-8884-dfd4d65b7784--
4

3 回答 3

2

您可以使用字符串运算符来提取包含 xml 代码的 2 行。例如,如果你使用 javascript,你会

所有这些都需要在您收到响应之后并将其解析为 xml 之前完成

如果你不使用 javascript,你可以使用 regexp 来做同样的事情

在更糟糕的情况下,如果您的环境不支持我所说的任何事情,您可以采用旧方法:逐行阅读,当您第一次找到“<”作为第一个字符时,保存该行,阅读再一停。

于 2012-01-20T02:11:54.987 回答
2

由于第一行,您的 XML 只有在以 UTF-8 格式存储和打开时才有效。例如,如果您要将其保存到记事本中并将其另存为“sample.xml”,当您在 Internet Explorer 中打开它时,它会将其显示为格式正确的 XML。

但是,如果您要加载此响应,例如 Unicode 字符串并将其提供给 XML 解析器,它将抱怨您的字符串是 Unicode 而内容是 UTF-8。

一种简单的解决方案是在将其提供给 XML 解析器之前剥离该行。这会给您带来初步的成功,但最终,为了正确起见,如果您希望进行国际化,您应该将您的内容作为字节流提供给 XML 解析器。

于 2012-01-19T05:01:53.260 回答
2

我不知道创建帖子时是否疏忽,但如果响应确实在<?xml?>声明之前有两个空格,那么这就是语法错误。如果出现 xml 声明,它必须是文档中的第一件事,而不是其他任何内容(甚至是空格)。

http://www.w3.org/TR/REC-xml/#sec-prolog-dtd

删除这些空格,文档看起来格式正确,所以我不知道它还会是什么。

于 2012-01-14T04:24:25.070 回答