使用MTOM发送第三方SOAP请求我收到一个“ OutOfMemory”错误。该文件约为50 MB,通过StreamContent将其添加到请求中。我的代码有什么问题? 对于小文件,该请求可以。 谢谢!
string _endPointURL = "http://myservice.wsdl";
string _boundary = "=MIME_BOUNDARY=";
Uri _endpoint = new Uri(_endPointURL);
HttpRequestMessage _requestMessage = new HttpRequestMessage(HttpMethod.Post, _endpoint);
MultipartContent _multiPartcontent = new MultipartContent("Related", _boundary);
//Define template request
HttpContent _xmlContent = new StringContent(@"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:ws=""http://ws.ltps.myservice.eu"">
<soapenv:Header>
...
</soapenv:Header>
<soapenv:Body>
<ws:PreserveObjectRequest>
...
<ws:data>cid:3936AE19FBED55AE4620B81C73BDD76E</ws:data>
</ws:PreserveObjectRequest>
</soapenv:Body>
</soapenv:Envelope>");
_xmlContent.Headers.ContentType = new MediaTypeHeaderValue("application/xop+xml");
_xmlContent.Headers.Add("Content-ID", Guid.NewGuid().ToString());
//Add xml content
_multiPartcontent.Add(_xmlContent);
//Add file to request
StreamContent streamContent = new StreamContent(File.OpenRead(@"C:\temp\test.pdf"));
streamContent.Headers.Add("Content-Type", "application/octet-stream");
streamContent.Headers.Add("Content-Id", "3936AE19FBED55AE4620B81C73BDD76E");
_multiPartcontent.Add(streamContent);
_requestMessage.Content = _multiPartcontent;
//Send request
HttpClient httpClient = new HttpClient();
var httpRequest = httpClient.SendAsync(_requestMessage, HttpCompletionOption.ResponseContentRead, CancellationToken.None);
HttpResponseMessage httpResponse = httpRequest.Result;
string s = httpResponse.Content.ReadAsStringAsync().Result;
Console.WriteLine(s);