1

伙计,我正在开发一个 api,我必须使用soap请求将请求发送到基于xml的服务器,但服务器向我显示以下错误:远程服务器返回错误:(500)内部服务器错误,非常感谢帮助

我的代码是这样的:

   Dim s = ""
    s = s & "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf

    s = s & "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">" & vbCrLf

    s = s & "<soapenv:Body>" & vbCrLf

    s = s & "<OTA_AirLowFareSearchRQ EchoToken=""0"" SequenceNmbr=""0"" TransactionIdentifier=""0"" AvailableFlightsOnly="""" DirectFlightsOnly="""" xmlns=""http://www.opentravel.org/OTA/2003/05"">" & vbCrLf
    s = s & "<POS xmlns=""http://www.opentravel.org/OTA/2003/05"">" & vbCrLf
    s = s & "<Source AgentSine="""" PseudoCityCode="""" TerminalID=""1"">" & vbCrLf
    s = s & "<RequestorID ID=""AFFILIATE""/>" & vbCrLf
    s = s & "</Source>" & vbCrLf



    s = s & "<YatraRequests>" & vbCrLf
    s = s & "<YatraRequest DoNotHitCache=""false"" DoNotCache=""false"" YatraRequestTypeCode=""SMPA"" Description="""" MidOfficeAgentID=""28737"" AffiliateID=""TRAVELPARTNER"" />" & vbCrLf
    s = s & "</YatraRequests>" & vbCrLf
    s = s & "</POS>" & vbCrLf
    s = s & "<TravelerInfoSummary>" & vbCrLf
    s = s & "<AirTravelerAvail>" & vbCrLf
    s = s & "<PassengerTypeQuantity Code=""ADT"" Quantity=""" & drAdult.SelectedValue & """/>" & vbCrLf
    s = s & "<PassengerTypeQuantity Code=""CHD"" Quantity=""" & drpChil.SelectedValue & """/>" & vbCrLf
    s = s & "<PassengerTypeQuantity Code=""INF"" Quantity=""" & drpInfant.SelectedValue & """/>" & vbCrLf

    s = s & "</AirTravelerAvail>" & vbCrLf
    s = s & "</TravelerInfoSummary>" & vbCrLf
    s = s & "<SpecificFlightInfo>" & vbCrLf
    s = s & "<Airline Code=""""/>" & vbCrLf
    s = s & "</SpecificFlightInfo>" & vbCrLf
    s = s & "<OriginDestinationInformation>" & vbCrLf
    s = s & "<DepartureDateTime>" & txtDeparture.Text & "</DepartureDateTime>" & vbCrLf
    s = s & "<OriginLocation CodeContext=""IATA"" LocationCode=""" & drpFrom.SelectedValue & """>" & drpFrom.SelectedValue & "</OriginLocation>" & vbCrLf
    s = s & "<DestinationLocation CodeContext=""IATA"" LocationCode=""" & drpTo.SelectedValue & """>" & drpTo.SelectedValue & "</DestinationLocation>" & vbCrLf
    s = s & "</OriginDestinationInformation>" & vbCrLf
    s = s & "<TravelPreferences>" & vbCrLf
    s = s & "<VendorPref Code=""SG""/>" & vbCrLf
    s = s & "<VendorPref Code=""DN""/>" & vbCrLf
    s = s & "<CabinPref Cabin=""" & drpClass.SelectedValue & """/>" & vbCrLf
    s = s & "</TravelPreferences>" & vbCrLf
    s = s & "</OTA_AirLowFareSearchRQ>" & vbCrLf
    s = s & "</soapenv:Body>" & vbCrLf
    s = s & "</soapenv:Envelope>" & vbCrLf

    Dim url = "http://203.189.91.127:9090/services/spm/spm"

    Dim doc As New XmlDocument()

    doc.LoadXml(s)

    Dim req As HttpWebRequest = WebRequest.Create(url)
    req.Headers.Add("SOAPAction", "")

    req.ContentType = "text/xml;charset=""utf-8"""
    req.Accept = "text/xml"
    req.Method = "POST"
    Dim stm As Stream = req.GetRequestStream()
    doc.Save(stm)
    stm.Close()
    Dim resp As WebResponse = req.GetResponse()
    stm = resp.GetResponseStream()
    Dim r As StreamReader = New StreamReader(stm)
    'process SOAP return doc here. For now, we'll just send the XML out to the browser ...
    Response.Write(r.ReadToEnd())
4

3 回答 3

1

正如它所说,HTTP 错误代码 500 是内部服务器错误。您的联系人可能需要查看他的日志并向您报告错误是什么,因为这是他的结果,而不是您的错误。

如果您的请求格式与他的预期格式不匹配并引发错误,则需要在他端正确处理,而不是报告错误 500。

所以....基本上它不在你的手中。

于 2013-01-18T18:44:58.140 回答
0

获取窗口的应用程序日志会很有帮助。转到开始 -> 运行 -> 事件查看器(单击 Enter)-> Windows 日志 -> 应用程序 -> 检查日志。有关详细信息,请参阅http://support.microsoft.com/kb/308427。或 http://www.dotnetnoob.com/2012/03/iis-500-errors-leave-clues-in-log.html

于 2013-01-19T09:46:39.647 回答
0

先评论这件事

's = ?xml 版本=""1.0"" 编码=""UTF-8""?"

然后添加此代码它的工作正常我尝试

        Dim Parameters As String = GetRq()
        Dim request As WebRequest = WebRequest.Create(url)
        request.Credentials = CredentialCache.DefaultNetworkCredentials
        request.ContentType = "application/x-www-form-urlencoded"
        request.Method = "POST"
        request.Headers.Add("SOAPAction", url)
        Dim byteArray As Byte() = Encoding.UTF8.GetBytes(Parameters)
        request.ContentType = "text/xml"

        request.ContentLength = byteArray.Length

        Dim dataStream As Stream = request.GetRequestStream()
        dataStream.Write(byteArray, 0, byteArray.Length)
        dataStream.Close()

        Dim response As WebResponse = request.GetResponse()
        dataStream = response.GetResponseStream()

        Dim reader As New StreamReader(dataStream)
        Dim responseFromServer As String = reader.ReadToEnd()

        reader.Close()
        dataStream.Close()
        response.Close()

谢谢

马路莫格雷

于 2014-06-11T10:16:53.690 回答