0

我有一个生成订单号列表的 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.
            }
        }
    }
4

1 回答 1

0

一般来说,您需要一个 SQL 任务作为起点,从数据库中获取订单号列表,并将查询结果保存到 Object 类型的变量中,例如“OrderNumberList”。然后你有一个 foreach 循环容器来循环“OrderNumberList”变量,并将当前值分配给另一个变量“OrderNumber”。

(如果您之前没有完成所有这些操作,这里有一个链接显示如何遍历数据库查询结果集。)

在 foreach 容器中放置一个 Script 任务,并选择“OrderNumber”作为只读变量,以便您可以在脚本中引用该变量。然后在脚本中,“OrderNumber”可以引用为:

request = WebRequest.Create("http://dev2:10580/orderws/order/" + 
    ((string) Dts.Variables["OrderNumber"].Value)) as HttpWebRequest;
于 2013-04-17T11:08:41.490 回答