【问题标题】:Can't find XML in httprequest在 httprequest 中找不到 XML
【发布时间】:2015-08-19 16:27:03
【问题描述】:

我有一个现有的 asp 页面,它很大程度上不能/不会改变调用服务、发送 XML 文档的方式。

Private Function QueryXYZ(ByVal strStreet1 As String, _
                        ByVal strStreet2 As String, _
                        ByVal strCity As String, _
                        ByVal strState As String, _
                        ByVal strZipMain As String, _
                        ByRef objDomDoc As DOMDocument, _
                        ByRef blnStreetMatch) As Boolean

On Error GoTo errorHandler

Dim intCount As Integer
Dim lngErrNum As Long
Dim objResult As IXMLDOMNode
Dim objResultSet As IXMLDOMNodeList
Dim objXMLHTTP As New ServerXMLHTTP
Dim strErrDesc As String
Dim strFault As String
Dim strMessage As String
Dim strResults As String
Dim strSoap As String

'CO 11784 - start
'Build Soap XML request
strSoap = _
"<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>" & _
        "<MatchAddress xmlns='http://(address/'>" & _
                    "<MatchParms>" & _
                        "<Firm />" & _
                        "<Street1>" & strStreet1 & "</Street1>" & _
                    "</MatchParms>" & _
        "</MatchAddress>" & _
    "</soap:Body>" & _
"</soap:Envelope>"
'CO 11784 - end
'Load Request into XML document
objDomDoc.async = False
objDomDoc.loadXML (strSoap)

'Check for syntax errors in Request
If objDomDoc.parseError.errorCode <> 0 Then
    Err.Raise 10620, "Query", "Error parsing generated xml query: [" & objDomDoc.parseError.reason & _
        "]" & "[" & objDomDoc.parseError.srcText & "]"
End If

'Send the Request
objXMLHTTP.Open "POST", mstrGISURL, False
objXMLHTTP.setRequestHeader "soapaction", "http://sampleaddress.com/MatchAddress"
objXMLHTTP.send objDomDoc

'Load Response
strResults = Replace(objXMLHTTP.responseText, "&quot;", """")
strResults = Replace(strResults, "&gt;", ">")
strResults = Replace(strResults, "&lt;", "<")
strResults = Replace(strResults, "&apos;", "'")
objDomDoc.loadXML (strResults)

我想将其设置为与我正在编写的新(非 WCF)服务通信。

public XmlDocument Matchaddress(string AddressInXML)

(我知道参数调用几乎肯定是错误的,它只是为了使用 service.asmx 表单进行测试而设置的)

问题是,我在请求中找不到 XML 的位置。我用测试函数检查了输入流:

    System.IO.StreamReader sr = new System.IO.StreamReader(HttpContext.Current.Request.InputStream);
    string requestContents = sr.ReadToEnd();
    sr.Close();


    StreamWriter Sw = System.IO.File.CreateText( @"C:\Temp\testfile.txt");
    for (int i = 0; i < HttpContext.Current.Request.Headers.AllKeys.Length; i++)
    {
        Sw.WriteLine (HttpContext.Current.Request.Headers.AllKeys[i] + Environment.NewLine);
        //if (HttpContext.Current.Request.Headers.AllKeys[i] == "SOAPAction")
        //{
        string soaphd = HttpContext.Current.Request.Headers.AllKeys[i];
        string soapTXT = System.Web.HttpContext.Current.Request.Headers[soaphd];
        Sw.WriteLine(soapTXT + Environment.NewLine);
        //}
    }
    Sw.Close();

找不到。

我显然做错了什么。我不确定是否需要对经典的 ASP 代码进行更改,无论这样做有多么困难。我不知道是需要找到位置然后更改输入参数(或完全删除)还是需要先知道正确的参数是什么,然后数据会神奇地出现。

我不太了解那个“soapaction”标头——它是否需要与新服务的地址相匹配,或者它是否可以是一些通用(或完全不正确)的其他地址?同样的问题

<MatchAddress xmlns='http://(address/'>"

XML 中的行 - 是否会因为不是匹配的地址而将其搞砸?

当我尝试在 SOAPUI 中运行它时,我什至看不到 XML,所以我不知道这是否意味着什么。

可根据要求提供更多详细信息。

【问题讨论】:

  • 这不是经典的 ASP。当它被明确标记为错误时,人们怎么会投票给这样的问题??
  • 我收到呼叫的页面是经典的 ASP,我正在用 C# 编写服务。让我知道正确的标签是什么,我会相应地更新它们。或许你能帮上忙?
  • 好的,但没有一个代码是经典 ASP,一旦发送请求,它就像任何其他普通 HTTP 请求一样,因此它与问题无关,只会使经典 ASP 问题队列膨胀一些。
  • 告诉我正确的标签,如有必要,请告诉我问题的正确标题,我会很乐意更新它,这样它就不会再阻塞错误的队列了。
  • 我已经删除了 Classic ASP 标签,其他标签看起来还不错。

标签: c# asp.net vb.net soap soapui


【解决方案1】:

原来我使用流阅读器很接近,我只是将它读入错误类型的对象。这让我可以访问整个 XML:

XmlDocument xdoc = new XmlDocument();
using (Stream receiveStream = HttpContext.Current.Request.InputStream)
     {
         // Move to begining of input stream and read
         receiveStream.Position = 0;
         using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
         {
             // Load into XML document
             xdoc.Load(readStream);
         }
     } 

将生成的 XML 转储到一个字符串中,让我能够以任何我喜欢的方式获得我想要的任何东西。完全不用担心函数定义中的参数。

【讨论】:

    猜你喜欢
    • 2013-09-05
    • 1970-01-01
    • 1970-01-01
    • 2014-05-08
    • 2011-10-22
    • 2015-09-25
    • 1970-01-01
    • 2017-07-13
    • 1970-01-01
    相关资源
    最近更新 更多