vba,soap webservice响应不完整

时间:2018-10-06 05:48:39

标签: vba web-services soap exchangewebservices

我正在尝试通过肥皂1.1信封请求获取股市的大量数据,此链接中解释了Web服务的结构: http://service.tsetmc.com/WebService/TsePublicV2.asmx?op=BestLimitsAllIns

这是我的代码:

sub downloaddata()    
Dim Url As String
Url = "http://service.tsetmc.com/WebService/TsePublicV2.asmx"
Dim fldr As String
fldr = "C:\Users\daily\"
'init variable values
Dim Response As String
'Build the HTTP Request object
Dim ObjHttp As New MSXML2.XmlHttp
'build soap envelope for fetching header
Dim sEnv As String
sEnv = "<?xml version=" & """" & "1.0" & """" & " encoding=" & """" & "utf-8" & """" & "?>"
sEnv = sEnv & "<soap:Envelope xmlns:xsi=" & """" & "http://www.w3.org/2001/XMLSchema-instance" & """" & " xmlns:xsd=" & """" & "http://www.w3.org/2001/XMLSchema" & """" & " xmlns:soap=" & """" & "http://schemas.xmlsoap.org/soap/envelope/" & """" & ">"
sEnv = sEnv & "<soap:Body>"
sEnv = sEnv & "<BestLimitsAllIns xmlns=" & """" & "http://tsetmc.com/" & """" & ">"
sEnv = sEnv & "<UserName>" & """" & "username" & """" & "</UserName>"
sEnv = sEnv & "<Password>" & """" & "password" & """" & "</Password>"
sEnv = sEnv & "<Flow>" & "0" & " </Flow>"
sEnv = sEnv & "</BestLimitsAllIns>"
sEnv = sEnv & "</soap:Body>"
sEnv = sEnv & "</soap:Envelope>" 
'wrap the http request in a with statement
With ObjHttp
    .Open "post", Url, False
    .setRequestHeader "Host", "service.tsetmc.com"
    .setRequestHeader "Content-Type", "text/xml; charset=utf-8"
    .setRequestHeader "Content-Length", Len(sEnv)
    .setRequestHeader "SOAPAction", "http://tsetmc.com/BestLimitsAllIns"
    .send sEnv
    Response = ObjHttp.responseText
    Debug.Print "111111111111111111111111"
    Debug.Print .getAllResponseHeaders
    Debug.Print .responseText
    Debug.Print .Status
    Debug.Print .statusText
End With
Dim XDoc As MSXML2.DOMDocument
Dim xEmpDetails As MSXML2.IXMLDOMNode
Dim xParent As MSXML2.IXMLDOMNode
Dim xChild As MSXML2.IXMLDOMNode
Dim Col, Row As Integer
Set XDoc = New MSXML2.DOMDocument
XDoc.async = False
XDoc.validateOnParse = False
If Not XDoc.LoadXML(Response) Then  'strXML is the string with XML'
    Err.Raise XDoc.parseError.ErrorCode, , XDoc.parseError.reason
End If
XDoc.LoadXML (Response)
Set xEmpDetails = XDoc.DocumentElement
Set xParent = xEmpDetails.FirstChild
Row = 2
Col = 1
For Each xParent In xEmpDetails.ChildNodes
    For Each xChild In xParent.ChildNodes
        ThisWorkbook.Worksheets("a").Cells(Row, Col).Value = xChild.Text
        Col = Col + 1
    Next xChild
    Row = Row + 1
    Col = 1
Next xParent
End Sub

响应应该是这样的:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
    <BestLimitsAllInsResponse xmlns="http://tsetmc.com/
    <BestLimitsAllInsResult>
        <xsd:schema>schema(real content will be replaced) 
        </xsd:schema>xml(real content will be replaced
        </BestLimitsAllInsResult>
    </BestLimitsAllInsResponse>
</soap:Body>
</soap:Envelope>

但是我给出的真实答案只是样本的一部分,而主要数据未显示:

Cache-Control: private, max-age=0
Content-Length: 301
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Sat, 06 Oct 2018 05:23:47 GMT
Connection: keep-alive
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body
<BestLimitsAllInsResponse xmlns="http://tsetmc.com/" /></soap:Body>
</soap:Envelope>
200 
OK

响应不完整,缺少上面4行中的主要数据。我不知道为什么我不能调试问题。请检查并帮助我。谢谢

0 个答案:

没有答案
相关问题