如何使用 MTOM 将 vb6 中带有图像附件的 soap 发送到 c# 中的 Web 服务?

How to send soap with an image attachement in vb6 to a web service in c# with MTOM?

有我的代码:

=> 我的一部分 web.config (c#):

<basicHttpBinding>
    <binding name="secureHttpBinding"
            maxReceivedMessageSize="2097152" messageEncoding="Mtom"
            transferMode="Streamed">
        <readerQuotas maxStringContentLength="2097152" maxArrayLength="2097152" />
        <security mode="Transport">
            <transport clientCredentialType="None"/>
        </security>
    </binding>
</basicHttpBinding>

=> 我要调用的函数 (c#):

[OperationContract]
[WebInvoke(RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest)]
ImageData UploadImage(string clientAppKey, string organizationId, string name, byte[] value);

=> 我尝试发送肥皂 (vb6):

Headers:

objHttpRequest.SetRequestHeader "Content-Type", "multipart/related; type=""application/xop+xml"";start=""<http://tempuri.org/0>"";boundary=""uuid:d2d519f9-a921-436c-95b0-e31576611a01+id=16"";start-info=""text/xml"""
objHttpRequest.SetRequestHeader "SOAPAction", strNameSpace_ & "IFileHostService/" & strAction
objHttpRequest.SetRequestHeader "MIME-Version", "1.0"

数据:

--uuid:d2d519f9-a921-436c-95b0-e31576611a01+id=16
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><UploadImage xmlns="http://tempuri.org/"><clientAppKey>12345</clientAppKey><organizationId>000012</organizationId><name>b8e5cb8c-f82e-450d-a80a-29374640d34200.png</name><value><Include xmlns="http://www.w3.org/2004/08/xop/include" href="cid:http://tempuri.org/1/635630514915728569"/></value></UploadImage></soap:Body></soap:Envelope>

--uuid:d2d519f9-a921-436c-95b0-e31576611a01+id=16
Content-ID: <http://tempuri.org/1/635630514915728569>
Content-Transfer-Encoding: binary
Content-Type: application/octet-stream

[My bytes array??]
--uuid:d2d519f9-a921-436c-95b0-e31576611a01+id=16

我的问题是:

我在 C# 中收到了我的数据,但是我收到的字节数组不好。

我尝试了很多方法来发送我的字节数组。

1- 我在 base64 中尝试,但 c# 中的字节数组比我在 vb6 中的字节数组长。 示例:我在 vb6 中发送了一个 40000 的字节数组,在 C# 中得到了一个 50000 的数组。

2- 我尝试使用字符串 unicode,但数组太短。 示例:我发送 StrConv(b(), vbUnicode) 并在 c# 中得到一个 8 的数组。 UBound(b) = 40000

我的问题是如何在 vb6 中发送我的字节数组以在 c# 中获得相同的数组?

感谢您的宝贵时间。

最后,我找到了它的工作方式。

我在 base64 中发送我的字节数组并在 c# 中转换。

value = Convert.FromBase64String(Encoding.UTF8.GetString(value));

StrConv(b(), vbUnicode) 的解决方案不起作用,因为当 c# 读取我的字符串时它停止读取 char 0。