简体   繁体   English

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

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

There is my code: 有我的代码:

=> Part of my web.config (c#): =>我的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>

=> Function I want to call (c#): =>我要调用的函数(C#):

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

=> My soap I try to send (vb6): =>我尝试发送的肥皂(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"

Data: 数据:

--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

There is my problem: 我的问题是:

I received my data in c#, but the bytes array I received is not good. 我在c#中收到了数据,但是收到的字节数组不好。

I try many way to send my byte array. 我尝试了多种发送字节数组的方法。

1- I try in base64 but the bytes array in c# is longer than my bytes array in vb6. 1-我尝试在base64中使用,但C#中的字节数组比vb6中的字节数组长。 example: I send a byte array of 40000 in vb6 and got a array of 50000 in c#. 示例:我在vb6中发送了一个40000的字节数组,在c#中得到了50000的一个数组。

2- I try in string unicode but the array was too short. 2-我尝试使用字符串unicode,但是数组太短。 example: I send StrConv(b(), vbUnicode) and got a array of 8 in c#. 示例:我发送StrConv(b(),vbUnicode)并在c#中得到8的数组。 UBound(b) = 40000 磅(b)= 40000

My question is how I send my byte array in vb6 to get the same array in c#? 我的问题是我如何在vb6中发送字节数组以在c#中获得相同的数组?

Thanks for your time. 谢谢你的时间。

Finally, I found a way that it work. 最终,我找到了一种可行的方法。

I send my byte array in base64 and convert in c#. 我在base64中发送字节数组,然后在c#中进行转换。

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

The solution with StrConv(b(), vbUnicode) not working because when c# read my string it stop reading on char 0. StrConv(b(),vbUnicode)的解决方案不起作用,因为当c#读取我的字符串时,它将停止读取char 0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM