您好我发送以下XML,但是我收到错误“有多个根元素第2行,第2位”我已经过了这个并且找不到任何错误。奇怪的是,这是在上周工作,代码没有改变。
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/" soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body>
<OTA_VehAvailRateRQ xmlns="http://www.opentravel.org/OTA/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05 OTA_PingRQ.xsd" Target="Test" Version="1.003">
<POS>
<Source ISOCurrency="EUR">
<RequestorID ID="######"/>
</Source>
</POS>
<VehAvailRQCore Status="Available">
<VehRentalCore PickUpDateTime="2016-10-10T12:00:00" ReturnDateTime="2016-10-17T12:00:00">
<PickUpLocation LocationCode="71"/>
<ReturnLocation LocationCode="71"/>
</VehRentalCore>
<DriverType Age="25"/>
</VehAvailRQCore>
<VehAvailRQInfo>
<Customer>
<Primary>
<CitizenCountryName Code="IE"/>
</Primary>
</Customer>
<TPA_Extensions>
<ConsumerIP>###.##.###.###</ConsumerIP>
</TPA_Extensions>
</VehAvailRQInfo>
</OTA_VehAvailRateRQ>
</soap:Body>
</soap:Envelope>
有没有人知道为什么这不会发送?它甚至没有到收件人服务器。
这是发送XML的函数。 XML传递一个字符串“request.request”
Public Function RequestSoapXML(ByVal Request As ALTStructures.ALTXMLStructures.Request) As String
RequestSoapXML = "Success"
Try
Dim webClient As New System.Net.WebClient()
webClient.Headers.Add("Content-Type", "text/xml;charset=utf-8")
webClient.Headers.Add("SOAPAction", Request.SOAPAction)
Dim response = webClient.UploadString(Request.Destination, Request.Request)
Dim XMLdate As String = System.DateTime.Now.ToString("yyyyMMddHHmmssfff")
Dim XMLDoc As New XmlDocument
XMLDoc.LoadXml(response)
XMLDoc.Save(Request.XMLFile)
Catch webExcp As System.Net.WebException
Dim httpResponse As System.Net.HttpWebResponse = CType(webExcp.Response, System.Net.HttpWebResponse)
Dim StreamObj As Stream = webExcp.Response.GetResponseStream
Dim SR As New StreamReader(StreamObj, Encoding.UTF8)
Dim uError As String = SR.ReadToEnd()
Dim XMLErr As New XmlDocument
XMLErr.LoadXml(uError)
XMLErr.Save("###########")
Dim Xmlreader As XmlTextReader = New XmlTextReader("##########")
Xmlreader.WhitespaceHandling = WhitespaceHandling.Significant
Try
While Not Xmlreader.EOF
Select Case Xmlreader.Name
Case "faultstring"
RequestSoapXML = Xmlreader.ReadInnerXml
End Select
Xmlreader.Read()
End While
Xmlreader.Close()
Catch ex As Exception
RequestSoapXML = ex.Message
End Try
Catch ex As Exception
RequestSoapXML = ex.Message
End Try
End Function
此函数处理许多XML请求,因此如果错误发生在此处,我会发现很多错误。
答案 0 :(得分:0)
我发现了问题
它实际上是返回的XML错误,而不是我发送的XML。
干杯。