我有一个生成订单号列表的 sql 查询...我可以将这些订单号单独放置在 Web 服务的 Web 请求 URL 中,并收集该订单的详细信息。如果我有一个可用的 WSDL 文件,但 We 服务使用的是 RestFul 服务客户端并且没有 WSDL 文件,我知道该怎么做。我确实有一个 C# 代码,只有在我声明订单号并试图找出如何用 DTS 变量替换此参数并使用 Foreach 循环容器来运行列表中的其余订单号时才能工作。这是我到目前为止的代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.IO;
using System.Net;
using System.Xml;
/**
* A test code to consuming a RESTFUL web service.
* You need to just parse the xml - either save it in memory/Cache to parse immediatly,
* or wrire to file and do read and parse it.
* @author: Jbisht
*/
namespace JbishtApplication
{
class CallWeb
{
static void Main(string[] args)
{
HttpWebRequest request = null;
HttpWebResponse response = null;
String Xml;
String salesOrderNo = "S3107634";
String file_ext = ".xml";
String file_name = salesOrderNo + file_ext;
String file_path = "C:/";
// Create the web request - Zones Test Environment - Orderws URL
// request = WebRequest.Create("http://test2:8080/orderws/order/" + salesOrderNo) as HttpWebRequest;
// Create the web request - My instance - Orderws for test only
request = WebRequest.Create("http://dev2:10580/orderws/order/" + salesOrderNo) as HttpWebRequest;
// Get response
using (response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());
Xml = reader.ReadToEnd();
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(Xml);
xdoc.Save(file_path + file_name); // it will save your response xml to file location;
}
// Console xml output
Console.WriteLine(Xml); //see if we get the xml response, (YES we do)
Console.ReadLine(); // Just wrote to keep console window open after writing to console.
}
}
}