.net 向 SOAP 请求添加附件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8574938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 16:07:31  来源:igfitidea点击:

Adding an attachment to SOAP request

.netsoapattachmentmtomwse

提问by anothershrubery

I am at a loose end as to how to add an attachment in my SOAP request. We have to consume a thrid party web service, built in java, which is the most convoluted thing I have ever come across. Any other web services we have used, that required attachments, have a method or property to add the attachment. Simple. However, this one provides no such method.

关于如何在我的 SOAP 请求中添加附件,我尚无定论。我们必须使用用 Java 构建的第三方 Web 服务,这是我遇到的最复杂的事情。我们使用过的任何其他需要附件的 Web 服务都有添加附件的方法或属性。简单的。然而,这个没有提供这样的方法。

We have got a version of the SOAP message together that is exactly as we want the XML, however it is the MIME part of the file that we cannot add.

我们已经获得了一个与我们想要的 XML 完全相同的 SOAP 消息版本,但是我们无法添加文件的 MIME 部分。

Example:

例子:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
<soap:Header>
<payloadManifest xmlns="http://<examplePayload>">
<manifest contentID="Content0" namespaceURI="http://<exampleManifest>" element="ProcessRepairOrder" version="2.01" />
</payloadManifest>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsu:Created>2011-12-19T15:25:13Z</wsu:Created>
<wsu:Expires>2011-12-19T15:30:00Z</wsu:Expires>
</wsu:Timestamp>
<wsse:UsernameToken><wsse:Username>username</wsse:Username><wsse:Password>password</wsse:Password></wsse:UsernameToken></wsse:Security></soap:Header><soap:Body><ProcessMessage xmlns="<examplePayload"><payload><content id="Content0">

<s:ProcessRepairOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://example.xsd" xmlns:s="http://<exampleManifest>" xmlns:gwm="http://example">
    <s:ApplicationArea>
        <s:Sender>
            <s:Component>Test</s:Component>
            <s:Task>ProcessAttachment</s:Task>
            <s:CreatorNameCode>Test</s:CreatorNameCode>
            <s:SenderNameCode>XX</s:SenderNameCode>
            <s:DealerNumber>111111</s:DealerNumber>
            <s:DealerCountry>GB</s:DealerCountry>
        </s:Sender>
        <s:CreationDateTime>2010-03-26T13:37:05Z</s:CreationDateTime>
        <s:Destination>
            <s:DestinationNameCode>GM</s:DestinationNameCode>
            <s:DestinationURI/>
            <s:DestinationSoftwareCode>GWM</s:DestinationSoftwareCode>
        </s:Destination>
    </s:ApplicationArea>
    <s:DataArea xsi:type="gwm:DataAreaExtended">
        <s:Process/>
        <s:RepairOrder>
            <s:Header xsi:type="gwm:RepairOrderHeaderExtended">
                <s:DocumentId/>
            </s:Header>
            <s:Job xsi:type="gwm:JobExtended">
                <s:JobNumber/>
                <s:OperationId>Test</s:OperationId>
                <s:OperationName/>
                <s:CodesAndComments/>
                <s:Diagnostics/>
                <s:WarrantyClaim xsi:type="gwm:WarrantyClaimExtended">
                    <s:OEMClaimNumber>00112233445566778899</s:OEMClaimNumber>
                    <gwm:Attachment>
                        <gwm:File><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:test.gif"/></gwm:File>
                        <gwm:Filename>test.gif</gwm:Filename>
                    </gwm:Attachment>
                </s:WarrantyClaim>
                <s:LaborActualHours>0.0</s:LaborActualHours>
                <s:Technician/>
            </s:Job>
        </s:RepairOrder>
    </s:DataArea>
</s:ProcessRepairOrder>
</content></payload></ProcessMessage></soap:Body></soap:Envelope>

This is the XML part that we can generate and send off, however it is incorrect as we need a MIME part in there like:

这是我们可以生成和发送的 XML 部分,但是它是不正确的,因为我们需要一个 MIME 部分,例如:

Before XML:

在 XML 之前:

--MIMEBoundary
Content-Type: application/xop+xml; charset=utf-8; type="text/xml"
Content-Transfer-Encoding: binary
Content-ID: <rootpart>

After XML

在 XML 之后

--MIMEBoundary
Content-Type: image/gif; name=test.gif
Content-Transfer-Encoding: binary
Content-ID: <test.gif>
GIF89a@?

--MIMEBoundary--

I have scoured the internet for answers but have come up blank. There doesn't seem to be much documentation around using WSE for this. I must stress that WSE is a requirement on the server side, and there is no way I can change the technology to address this issue.

我已经在互联网上搜索了答案,但结果是空白。似乎没有太多关于为此使用 WSE 的文档。我必须强调,WSE 是服务器端的要求,我无法更改技术来解决此问题。

Is there a way that these MIME sections can be added?

有没有办法添加这些 MIME 部分?

EDIT: I must add that I can get a working XML document sent through SoapUI with attachments, but cannot seem to find a way within our code.

编辑:我必须补充一点,我可以通过 SoapUI 发送带有附件的工作 XML 文档,但似乎无法在我们的代码中找到方法。

I have added a bounty to try and get a solution to this problem. If anyone has any other ideas please let me know.

我添加了一个赏金来尝试解决这个问题。如果有人有任何其他想法,请告诉我。

EDIT again: I know it has been a week since I was able to check the responses here, but while some give a good idea where to look I am still drawing a blank. The terrible documentation surrounding XopDocumentand its methods is a big sticking point, if anyone has any examples of using SaveToXopPackagecould they please provide because this is beginning to grate!

再次编辑:我知道自从我能够在这里查看回复以来已经有一个星期了,但是虽然有些人给出了一个很好的主意,但我仍然在画一个空白。糟糕的文档XopDocument及其方法是一个很大的症结,如果有人有任何使用示例,SaveToXopPackage请提供,因为这开始令人讨厌!

回答by ktsiolis gmail com

I was facing the same problem and the final solution I found was through HttpWebRequest. A sample code:

我遇到了同样的问题,我找到的最终解决方案是通过 HttpWebRequest。示例代码:

    public string ProcessAttachment(string fileInput)
    {
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Settings.Default.GWM_WS_WebReference_GWM);
        req.Headers.Add("SOAPAction", "\"http://www.starstandards.org/webservices/2005/10/transport/operations/ProcessMessage/v1_01/ProcessAttachment\"");
        req.Headers.Add("Accept-Encoding", "gzip,deflate");
        req.ContentType = "multipart/related; type=\"application/xop+xml\"; start=\"<[email protected]>\"; start-info=\"text/xml\"; boundary=\"----=_Part_14_1350106.1324254402199\"";
        req.Method = "POST";
        req.UserAgent = "Jakarta Commons-HttpClient/3.1";
        req.Headers.Add("MIME-Version", "1.0");
        System.Net.ServicePointManager.Expect100Continue = false;
        Stream memStream = new System.IO.MemoryStream();
        FileStream fileStream = new FileStream(fileInput, FileMode.Open, FileAccess.Read);
        byte[] buffer = new byte[1024];
        int bytesRead = 0;
        while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
        {
            memStream.Write(buffer, 0, bytesRead);
        }
        fileStream.Close();
        Stream stm = req.GetRequestStream();
        memStream.Position = 0;
        byte[] tempBuffer = new byte[memStream.Length];
        memStream.Read(tempBuffer, 0, tempBuffer.Length);
        memStream.Close();
        stm.Write(tempBuffer, 0, tempBuffer.Length);
        stm.Close();
        HttpWebResponse resp = null;
        resp = (HttpWebResponse)req.GetResponse();
        stm = resp.GetResponseStream();
        StreamReader r = new StreamReader(stm);
        return r.ReadToEnd();            
    }

The parameter fileInput is the absolute path of the file that contains the SOAP Request containing also the raw binary data of the file to be attached at the end separated with MIME Boundary

参数 fileInput 是包含 SOAP 请求的文件的绝对路径,该请求还包含要在末尾附加的文件的原始二进制数据,并以 MIME 边界分隔

回答by competent_tech

I think that you may have a couple of options:

我认为你可能有几个选择:

1) Use MTOM. This appears to automatically wrap the outgoing message in MIME blocks.

1) 使用MTOM。这似乎会自动将外发消息包装在 MIME 块中。

2) Microsoft actually provides support for generating and reading XOP with mime through the XopDocument class, which is what SoapEnvelope inherits from.

2)微软实际上是通过XopDocument类提供了用mime生成和读取XOP的支持,SoapEnvelope就是从这个类继承而来的。

The save method is SaveToXopPackageand the read method is LoadFromXopPackage.

保存方法是SaveToXopPackage,读取方法是LoadFromXopPackage

However, I think that this approach may require you to perform the sending of the message yourself through an HttpWebRequest. This bloghas an example of how to implement this. The downside is that this requires a lot of extra code and configuration in order to work correctly.

但是,我认为这种方法可能需要您自己通过 HttpWebRequest 执行消息的发送。这个博客有一个如何实现这个的例子。缺点是这需要大量额外的代码和配置才能正常工作。

The ideal solution would be to intercept the code that performs the envelope transmission, but I have been unable to locate the correct location for this in the pipeline.

理想的解决方案是拦截执行包络传输的代码,但我一直无法在管道中找到正确的位置。

回答by ChrisB

I'm 90% confident I'm working on the exact same project as you guys. That soap request is a little too familiar :-)

我有 90% 的信心,我正在和你们从事完全相同的项目。那个肥皂请求有点太熟悉了:-)

We've gotten most of the way there by switching over to WCF and basically hand-coding the request object (creating classes that match the soap format and then using xmlelement attributes to decorate it so that it looks like their soap request. The file itself is declared as a Byte() on the Attachment class and also decorated with the xmlelement).

通过切换到 WCF 并基本上手动编码请求对象(创建与soap 格式匹配的类,然后使用xmlelement 属性来修饰它,使其看起来像他们的soap 请求。文件本身),我们已经完成了大部分工作在 Attachment 类上声明为 Byte() 并且还用 xmlelement 修饰)。

Here's what the WCF contract and part of the data model look like. The actual data model has a bunch of extra classes (Application Area, Data Area, Job, etc) but this gives you enough of a sense of how it's structured. The important piece is the File as Byte(). Here it is in Vb.net...

下面是 WCF 契约和部分数据模型的样子。实际的数据模型有一堆额外的类(应用程序区域、数据区域、作业等),但这让您对它的结构有足够的了解。重要的部分是 File as Byte()。这是在 Vb.net 中...

Public Class WarrantyClaim
    <XmlElement(Order:=0)> Public OEMClaimNumber As String = ""
    <XmlElement(Order:=1, namespace:="http://www.gm.com/2006/GWM")> Public Attachment As New Attachment
End Class

Public Class Attachment
    <XmlElement(Order:=0)> Public File As Byte()
    <XmlElement(Order:=1)> Public Filename As String
End Class

<ServiceContract(XmlSerializerFormat()> _
Public Interface IService
    <OperationContract(action:="http://www.starstandards.org/webservices/2005/10/transport/operations/ProcessMessage/v1_01/ProcessAttachment")> _
    Sub ProcessMessage(ByVal payload As WarrantyClaim)
End Interface

Next you've got your WCF client, this is pretty much the same as all WCF clients.

接下来,您有了 WCF 客户端,这与所有 WCF 客户端几乎相同。

Public Class GmgwClient
    Inherits System.ServiceModel.ClientBase(Of IService)
    Implements IService

    Public Sub New()
        MyBase.New()
    End Sub
    Public Sub New(ByVal configName As String)
        MyBase.New(configName)
    End Sub
    Public Sub New(ByVal binding As System.ServiceModel.Channels.Binding, ByVal remoteAddress As System.ServiceModel.EndpointAddress)
        MyBase.New(binding, remoteAddress)
    End Sub

    Public Sub ProcessMessage(ByVal payload As Payload) Implements IService.ProcessMessage
        MyBase.Channel.ProcessMessage(payload)
    End Sub
End Class

Finally you've got the app.config. Here's the magic because we're telling WCF to use Mtom to send the message. This will take the Byte() and strip it out into a seperate MIME section replacing it with an XOP:Include. Note that for now I'm just sending it through localhost so I can see the request using tcpTrace. You can google that app but it'll basically capture the request so we can see how it looks. I setup tcpTrace to listen on port 84.

最后你得到了 app.config。这就是魔法,因为我们告诉 WCF 使用 Mtom 发送消息。这将获取 Byte() 并将其剥离到单独的 MIME 部分中,并用 XOP:Include 替换它。请注意,目前我只是通过 localhost 发送它,因此我可以使用 tcpTrace 查看请求。你可以谷歌那个应用程序,但它基本上会捕获请求,所以我们可以看到它的外观。我设置了 tcpTrace 来监听端口 84。

<system.serviceModel>
  <bindings>
    <wsHttpBinding>
      <binding name="WsHttpMtomBinding" messageEncoding="Mtom">
        <security mode="None">
          <transport clientCredentialType="Basic" proxyCredentialType="None" realm="" />
        </security>
        <reliableSession enabled="false" />
      </binding>
    </wsHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://localhost:84/ProcessMessage" binding="wsHttpBinding" bindingConfiguration="WsHttpMtomBinding" contract="MyAppNameSpace.IService" name="preprod"/>
  </client>
</system.serviceModel>

Finally, here's the actual call to the WCF client to make the request.

最后,这是对 WCF 客户端发出请求的实际调用。

Dim x As New WarrantyClaim
x.OEmClaimNumber = "12345"
x.Attachment = New Attachment
x.Attachment.Filename = "sample.gif"
x.Attachment.File = IO.File.ReadAllBytes("C:\sample.gif")

Dim y As New GmgwClient("preprod")
y.ProcessMessage(x)

And here's the trace we got through tcpTrace. It's got the basic structure right and it's managed to pull the binary data out of the xml and place it in a seperate MIME section.

这是我们通过 tcpTrace 得到的跟踪。它具有正确的基本结构,并设法从 xml 中提取二进制数据并将其放置在单独的 MIME 部分中。

POST /ProcessMessage HTTP/1.1
MIME-Version: 1.0
Content-Type: multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:501aa27d-9dd1-4f8a-b56d-3fbf327e7be6+id=1";start-info="application/soap+xml"
VsDebuggerCausalityData: uIDPoysDMCv023ZIjK0Cpp504ooAAAAA//jfaCaohkab2Zx/EU7gpLZDcUldWtlGr1j4ZnrfKl4ACQAA
Host: localhost:84
Content-Length: 55125
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive


--uuid:501aa27d-9dd1-4f8a-b56d-3fbf327e7be6+id=1
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://www.starstandards.org/webservices/2005/10/transport/operations/ProcessMessage/v1_01/ProcessAttachment</a:Action>
    <a:MessageID>urn:uuid:a85374e6-c8ca-4328-ad32-6e8b88a5ca59</a:MessageID>
    <a:ReplyTo>
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <a:To s:mustUnderstand="1">http://localhost:84/ProcessMessage</a:To>
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <ProcessMessage xmlns="http://www.starstandards.org/webservices/2005/10/transport">
      <payload xsi:type="gwm:WarrantyClaimExtended">
        <OEMClaimNumber>12345</OEMClaimNumber>
        <Attachment xmlns="http://www.gm.com/2006/GWM">
          <File>
            <xop:Include href="cid:http%3A%2F%2Ftempuri.org%2F1%2F634618782531246992" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>
          </File>
          <Filename>sample.gif</Filename>
        </Attachment>
      </payload>
    </ProcessMessage>
  </s:Body>
</s:Envelope>
--uuid:501aa27d-9dd1-4f8a-b56d-3fbf327e7be6+id=1
Content-ID: <http://tempuri.org/1/634618782531246992>
Content-Transfer-Encoding: binary
Content-Type: application/octet-stream

GIF89a<BinaryStuff>

Like I mentioned earlier - we've still got some issues. There are some tags missing from the Soap Header... but I think we'll be able to figure those out. The real problem is that the Content-ID is NOT in a format our partner can accept - they expect something like <[email protected]> and .net is formatting them as http://tempuri.org/1/634618782531246992. This is causing their Web Service handler to crash because it doesn't know how to read escaped content-id's inside the soap message.

就像我之前提到的 - 我们仍然有一些问题。Soap Header 中缺少一些标签......但我认为我们能够弄清楚这些。真正的问题是 Content-ID 不是我们合作伙伴可以接受的格式 - 他们期望像 <[email protected]> 之类的东西,而 .net 将它们格式化为http://tempuri.org/1/6464965. 这会导致他们的 Web 服务处理程序崩溃,因为它不知道如何读取soap 消息中转义的内容ID。

回答by Tom De Leu

As you say you got it working through SoapUI, I would think you can just ask SoapUI for the generated XML it sent so you know how it should look, then modify your code to mimic that.

正如您所说,您是通过 SoapUI 让它工作的,我认为您可以向 SoapUI 询问它发送的生成的 XML,这样您就知道它应该是什么样子,然后修改您的代码以模仿它。

UPDATE: after your comment and reading the other answers in more detail: the solution looks to me just sending bytes directly, using HttpWebRequest like in ktsiolis's answer. In detail:

更新:在您发表评论并更详细地阅读其他答案之后:该解决方案在我看来只是直接发送字节,使用 HttpWebRequest 就像 ktsiolis 的答案一样。详细:

  • Create your SOAP XML (the example you gave), encode this to bytes in UTF8 (1)
  • Create a string with the initial mimeboundary (the part in your "Before XML"), encode to bytes in UTF8 (2)
  • Create the bytes for the second mimeboundary (the part in "after XML"). So create the string containing "--MIMEBOUNDARY" etc., encode to UTF8 bytes, and append all bytes of your test.gif file(3)
  • Append all bytes in the order (2), (1) and (3) and send that across the wire.
  • 创建您的 SOAP XML(您提供的示例),将其编码为 UTF8 (1) 中的字节
  • 创建一个带有初始 mimeboundary 的字符串(“Before XML”中的部分),以 UTF8 编码为字节(2)
  • 创建第二个 mimeboundary 的字节(“after XML”中的部分)。因此,创建包含“--MIMEBOUNDARY”等的字符串,编码为 UTF8 字节,并附加 test.gif 文件的所有字节(3)
  • 以 (2)、(1) 和 (3) 的顺序附加所有字节,并通过线路发送。

Shouldn't this do the trick?

这不应该解决问题吗?

回答by anothershrubery

Ok so I got it to accept the data from the file in the <gwm:File>element. This is without using XOP, so the request now looks like:

好的,所以我让它接受<gwm:File>元素中文件中的数据。这是不使用 XOP,所以请求现在看起来像:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">  <soap:Header>  <payloadManifest xmlns="http://<examplePayload>">  <manifest contentID="Content0" namespaceURI="http://<exampleManifest>" element="ProcessRepairOrder" version="2.01" />  </payloadManifest>  <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <wsu:Created>2011-12-19T15:25:13Z</wsu:Created>  <wsu:Expires>2011-12-19T15:30:00Z</wsu:Expires>  </wsu:Timestamp>  <wsse:UsernameToken><wsse:Username>username</wsse:Username><wsse:Password>password</wsse:Password></wsse:UsernameToken></wsse:Security></soap:Header><soap:Body><ProcessMessage xmlns="<examplePayload"><payload><content id="Content0">    <s:ProcessRepairOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://example.xsd" xmlns:s="http://<exampleManifest>" xmlns:gwm="http://example"> 
    <s:ApplicationArea> 
        <s:Sender> 
            <s:Component>Test</s:Component> 
            <s:Task>ProcessAttachment</s:Task> 
            <s:CreatorNameCode>Test</s:CreatorNameCode> 
            <s:SenderNameCode>XX</s:SenderNameCode> 
            <s:DealerNumber>111111</s:DealerNumber> 
            <s:DealerCountry>GB</s:DealerCountry> 
        </s:Sender> 
        <s:CreationDateTime>2010-03-26T13:37:05Z</s:CreationDateTime> 
        <s:Destination> 
            <s:DestinationNameCode>GM</s:DestinationNameCode> 
            <s:DestinationURI/> 
            <s:DestinationSoftwareCode>GWM</s:DestinationSoftwareCode> 
        </s:Destination> 
    </s:ApplicationArea> 
    <s:DataArea xsi:type="gwm:DataAreaExtended"> 
        <s:Process/> 
        <s:RepairOrder> 
            <s:Header xsi:type="gwm:RepairOrderHeaderExtended"> 
                <s:DocumentId/> 
            </s:Header> 
            <s:Job xsi:type="gwm:JobExtended"> 
                <s:JobNumber/> 
                <s:OperationId>Test</s:OperationId> 
                <s:OperationName/> 
                <s:CodesAndComments/> 
                <s:Diagnostics/> 
                <s:WarrantyClaim xsi:type="gwm:WarrantyClaimExtended"> 
                    <s:OEMClaimNumber>00112233445566778899</s:OEMClaimNumber> 
                    <gwm:Attachment> 
                        <gwm:File>GIF89a@?</gwm:File> 
                        <gwm:Filename>test.gif</gwm:Filename> 
                    </gwm:Attachment> 
                </s:WarrantyClaim> 
                <s:LaborActualHours>0.0</s:LaborActualHours> 
                <s:Technician/> 
            </s:Job> 
        </s:RepairOrder> 
    </s:DataArea>  </s:ProcessRepairOrder>  </content></payload></ProcessMessage></soap:Body></soap:Envelope>

When passed into SoapUI this works perfectly, however in code it does give a response, but it throws an error saying Response is not well-formed XML.with an inner exception of WSE1608: No XOP parts were located in the stream for the specified content-id: <rootpart*[email protected]>

当传递到 SoapUI 时,这完美地工作,但是在代码中它确实给出了响应,但是它抛出了一个错误,说Response is not well-formed XML.有一个内部异常WSE1608: No XOP parts were located in the stream for the specified content-id: <rootpart*[email protected]>

I will be opening a new question regarding this as it is technically a different issue.

我将就此提出一个新问题,因为它在技术上是一个不同的问题。

The other question can be found at Soap response, not well formed XML, no XOP parts located, using WSE

另一个问题可以在Soap response, not wellformed XML, no XOP partslocated, using WSE 中找到

回答by Daniel Schlieckmann

I am involved in exactly the same project and I have the same issues as discussed in this thread! I am using vb 2005 and WSE 3.0 enhancements and I got it working even it is a pain for now. When writing the content of the file directly in the File Property, the attachment will be accepted by the partner. In my case, this works for almost all transactions except PRA's. Here, the response is positive and an AttachmentID will be delivered but the attachment does not appear in the transaction.

我参与了完全相同的项目,并且遇到了与此线程中讨论的问题相同的问题!我正在使用 vb 2005 和 WSE 3.0 增强功能,即使现在很痛苦,我也能正常工作。直接在文件属性中写入文件内容时,附件将被合作伙伴接受。就我而言,这适用于除 PRA 之外的几乎所有交易。在这里,响应是肯定的,并且会传递一个 AttachmentID,但该附件不会出现在事务中。

Here is an example of the Attachment section:

以下是附件部分的示例:

                <gwm:Attachment>
                  <gwm:File>/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ...</gwm:File>
                  <gwm:Filename>intro2.jpg</gwm:Filename>
                </gwm:Attachment>

If I set RequireMtom for the Service to True, I'll get the following error:

如果我将服务的 RequireMtom 设置为 True,则会出现以下错误:

Das Pr?fix '' kann nicht von '' in 'http://www.starstandards.org/webservices/2005/10/transport' innerhalb desselben Startelementtags neu definiert werden.

Das Pr?fix ''kann nicht von'' in 'http://www.starstandards.org/webservices/2005/10/transport'innerhalb desselben Startelementtags neu definiert werden。

One the one hand, it works, on the other hand, I am not sure if it will be sent with XOP elements.

一方面,它可以工作,另一方面,我不确定它是否会与 XOP 元素一起发送。