我正在尝试使用SOAP Webservice,它假设返回Document。 以下是输出的WSDL。
<wsdl:binding name="NGOImageEnableServiceImpHttpBinding" type="ns:NGOImageEnableServiceImpPortType">
<http:binding verb="POST"/>
<wsdl:operation name="downloadDocInFile">
<http:operation location="NGOImageEnableServiceImp/downloadDocInFile"/>
<wsdl:input>
<mime:content type="text/xml" part="downloadDocInFile"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="downloadDocInFile"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
我在web.config中设置的绑定是
<webHttpBinding>
<binding name="NGOImageEnableServiceImpSoap12Binding"
allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
transferMode="Streamed">
</binding>
相同的服务在使用邮递员时提供这样的输出
--MIMEBoundaryurn_uuid_C455EAC131FBC506CE1521635293615
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID:
<0.urn:uuid:C455EAC131FBC506CE1521635293616@apache.org>
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:downloadDocInFileResponse xmlns:ns="http://provider.ws.jts.omni.newgen.com">
<ns:return>
<swa:fileName xmlns:swa="http://provider.ws.jts.omni.newgen.com">
<swa:graph>urn:uuid:C455EAC131FBC506CE1521635293614</swa:graph>
<swa:message>file download on server successfully</swa:message>
</swa:fileName>
</ns:return>
</ns:downloadDocInFileResponse>
</soapenv:Body>
</soapenv:Envelope>
--MIMEBoundaryurn_uuid_C455EAC131FBC506CE1521635293615
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
Content-ID:
<urn:uuid:C455EAC131FBC506CE1521635293614>
****BINARY CONTENT****
我想在我的c#代码中使用它。
答案 0 :(得分:0)
唉!这是一个SOAP-With-Attachments(SWA)。 WCF不支持此功能。 WCF使用MTOM,但我认为有解决方法:
答案 1 :(得分:0)
在完成这项工作后,我在MultipartMemoryStreamProvider
的帮助下找到了解决方案async static Task<string> readMultipart(HttpWebResponse httpResponse)
{
var content = new StreamContent(httpResponse.GetResponseStream());
content.Headers.Add("Content-Type", httpResponse.ContentType);
MultipartMemoryStreamProvider multipart = new MultipartMemoryStreamProvider();
Task.Factory.StartNew(() => multipart = content.ReadAsMultipartAsync().Result,
CancellationToken.None,
TaskCreationOptions.LongRunning, // guarantees separate thread
TaskScheduler.Default)
.Wait();
String filename = "";
String json = await multipart.Contents[0].ReadAsStringAsync();
string path = HttpContext.Current.Server.MapPath("/test.jpeg");
byte[] fileData = multipart.Contents[1].ReadAsByteArrayAsync().Result;
System.IO.File.WriteAllBytes(path, fileData);
return json;
}