![](/img/trans.png)
[英]How to call Soap/mtom web service asynchronously from C# winform
[英]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):
头:
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的数组。 磅(b)= 40000
我的问题是我如何在vb6中发送字节数组以在c#中获得相同的数组?
谢谢你的时间。
最终,我找到了一种可行的方法。
我在base64中发送字节数组,然后在c#中进行转换。
value = Convert.FromBase64String(Encoding.UTF8.GetString(value));
StrConv(b(),vbUnicode)的解决方案不起作用,因为当c#读取我的字符串时,它将停止读取char 0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.