【发布时间】:2021-05-31 21:12:09
【问题描述】:
我正在使用 Web 服务,它在带有附件的 SOAP 中给出响应。 我使用 PostMan 捕获的响应是
--MIMEBoundaryurn_uuid_C455EAC131FBC506CE1521805985220
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <0.urn:uuid:C455EAC131FBC506CE1521805985221@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:C455EAC131FBC506CE1521805985219</swa:graph><swa:message>file download on server successfully</swa:message></swa:fileName></ns:return></ns:downloadDocInFileResponse></soapenv:Body></soapenv:Envelope>
--MIMEBoundaryurn_uuid_C455EAC131FBC506CE1521805985220
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <urn:uuid:C455EAC131FBC506CE1521805985219>
II*----binary content----
我的代码是
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
retVal = soapResult;
byte[] temp = Encoding.ASCII.GetBytes(soapResult);
}
}
var binaryString = ToBinary(ConvertToByteArray(retVal, Encoding.ASCII));
byte[] bytes = Convert.FromBase64String(binaryString);
string path = HttpContext.Current.Server.MapPath("/test.pdf");
File.WriteAllBytes(path, bytes);
但是文件正在损坏。
【问题讨论】:
-
我怀疑 pdf 是 ascii 编码的。试试 UTF-8。
标签: c# web-services soap attachment