0

任务很简单,使用 XML 连接到另一个 Web 服务。
在当前页面(经典 ASP)中,我们使用以下代码:

zoekpcode=UCASE(Request.Querystring("zoekpcode")) <-- postal-code
zoeknr=Request.Querystring("zoeknr") <-- house-number

PC=Trim(Replace(zoekpcode," ",""))
NR=Trim(Replace(zoeknr," ",""))

strGetAddress="https://ws1.webservices.nl/rpc/get-simplexml/addressReeksPostcodeSearch/*~*/*~*/" & PC & NR

set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.open "GET", strGetAddress , false
xml.send ""
strStatus = xml.Status
If Len(PC)>5 and Len(NR)>0 Then
    strRetval = Trim(xml.responseText)
End If

set xml = nothing

'Do something with the result string

可能的链接之一可能是:https ://ws1.webservices.nl/rpc/get-simplexml/addressReeksPostcodeSearch/ ~ / ~ /1097ZD49

目前我正在寻找一种在 razor (C#) 中执行此操作的方法,但我似乎能够在 Google 上找到的只是如何在
我尝试过(大多数组合)以下术语的 JavaScript 中执行此操作:

  • 剃刀
  • xmlhttp
  • 组合物
  • 来自网址的 XML
  • -javascript

结果主要是关于 JavaScript 或 razorblades。
根据其他结果(例如在razor 中的搜索 comobjects),似乎 Razor 中没有 comobject。

我确实在stackoverflow上找到了这个问题(How to use XML with WebMatrix razor (C#)),这似乎回答了我的问题(部分),但是否也可以通过链接到外部系统(提到的网络服务)?

4

2 回答 2

0

I have covered the consumption of Web Services in Razor web pages here: http://www.mikesdotnetting.com/Article/209/Consuming-Feeds-And-Web-Services-In-Razor-Web-Pages.

If your web service is a SOAP one, you are best off using Visual Studio (the free Express editions is fine) to add a service reference and then work from there. Otherwise you can use Linq To XML to load the XML directly into an XDocument as in the ATOM example in the article:

var xml = XDoxument.Load("https://ws1.webservices.nl/rpc/get-simplexml/blah/blah");

Then use the System.Xml.Linq APIs to query the document.

于 2013-10-28T14:11:36.540 回答
0

在Ralf的帮助下,我得到了以下代码:

public static XmlDocument getaddress(string pcode, string number){
    string serverresponse = "";
    string getlocation = "https://ws1.webservices.nl/rpc/get-simplexml/addressReeksPostcodeSearch/*~*/*~*/" + Request.QueryString["PCODE"] + Request.QueryString["NR"];

    HttpWebRequest req = (HttpWebRequest) WebRequest.Create(getlocation);
    using (var r = req.GetResponse()) {
        using (var s = new StreamReader(r.GetResponseStream())) {
            serverresponse = s.ReadToEnd();
        }
    }

    XmlDocument loader = new XmlDocument();
    loader.LoadXml(serverresponse);
    return loader;
}

public static string getvalue(XmlDocument document, string node){
    string returnval = "";
    var results = document.SelectNodes(node);
    foreach(XmlNode aNode in results){
        returnval = returnval + "," + aNode.InnerText;
    }

    return returnval.Substring(1);
}
于 2013-10-29T08:13:01.027 回答