【发布时间】:2019-09-03 05:03:27
【问题描述】:
不知何故,我最终遇到了使用带有运行 vb 的 aspx 页面的 SOAP 端点的问题。发送文件和简单数据有效,但我无法再次下载文件。
对于 MTOM 响应,我只是对其中的内容进行正则表达式并将其解析为有效的 XElement。现在对于二进制流,我尝试了相同的方法,但尚未成功。请参阅下面的代码以调用端点并返回结果。
Private Function sendSOAPRequest(url As String, enpoint As String, data As Byte()) As String
Dim result As String = ""
Try
Dim req = WebRequest.Create(url)
req.Headers.Add("SOAPAction", url + enpoint)
req.ContentType = "application/soap+xml"
req.ContentLength = data.Length
req.Method = "POST"
Dim DataStream = req.GetRequestStream()
DataStream.Write(data, 0, data.Length)
DataStream.Close()
Dim WebResponse = req.GetResponse()
Dim resp = WebResponse.GetResponseStream()
Dim Reader = New StreamReader(resp)
result = Reader.ReadToEnd()
DataStream.Close()
Reader.Close()
resp.Close()
Catch ex As WebException
System.Diagnostics.Debug.WriteLine(ex.ToString())
End Try
System.Diagnostics.Debug.WriteLine(result)
Return result
End Function
现在可以登录/注销/上传了。现在对于一些 fileContent 调用,我得到了回复:
HTTP/1.1 200 OK
X-Powered-By: Undertow/1
Access-Control-Allow-Headers: accept, authorization, content-type, x-requested-with
Server: WildFly/10
Date: Fri, 12 Apr 2019 12:06:58 GMT
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Content-Type: multipart/related; type="application/xop+xml"; boundary="uuid:6c8ac7c2-cac9-437f-a319-72c7c0e60328"; start="<root.message@cxf.apache.org>"; start-info="application/soap+xml"
Content-Length: 5371
Access-Control-Max-Age: 1
Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT
--uuid:6c8ac7c2-cac9-437f-a319-72c7c0e60328
Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml"
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><ns2:getContentObjectStreamResponse xmlns:ns2="http://ws.soap.transfer.services.sedna.ser.com/"><dataHandler><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:a31b1e84-b3a5-4482-90af-f99943ec08a2-9@cxf.apache.org"/></dataHandler></ns2:getContentObjectStreamResponse></soap:Body></soap:Envelope>
--uuid:6c8ac7c2-cac9-437f-a319-72c7c0e60328
Content-Type: */*
Content-Transfer-Encoding: binary
Content-ID: <a31b1e84-b3a5-4482-90af-f99943ec08a2-9@cxf.apache.org>
‰PNG
binary data
--uuid:6c8ac7c2-cac9-437f-a319-72c7c0e60328--
如何仅解析二进制部分并取回文件?
2019 年 4 月 16 日更新:我得到了以下几行的内容:
Dim rContent As New System.Text.RegularExpressions.Regex("(?<=Content-ID: <[^root].*[>])(.|\n)*(?=--uuid)")
Dim matchContent As Match = rContent.Match(documentResponse)
Dim documentContentData As String = matchContent.Value
但似乎字符串转换以某种方式弄乱了二进制编码。 使用
将该内容写入文件Dim fileBytes As Byte() = UnicodeStringToBytes(trimmedContent)
File.WriteAllBytes("C:\Path\cloud.png", fileBytes)
比原始文件大并且编码错误。
【问题讨论】:
标签: vb.net web-services soap mtom