I am trying to consume SOAP Webservice which is suppose to return Document. Following is WSDL for output.
<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>
And Binding i have set in web.config is
<webHttpBinding>
<binding name="NGOImageEnableServiceImpSoap12Binding"
allowCookies="false" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
transferMode="Streamed">
</binding>
Same service gives output like this while using postman
--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****
I want to consume this in my c# code.
Ugh! This is a SOAP-With-Attachments (SWA). WCF does not support this. WCF uses MTOM but I think there are workarounds:
After working on this i found the solution with the help of 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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.