2013-02-14 133 views
2

我已经成功地使用SSIS中的Web服务任务,但我无法弄清楚如何写入Web服务,有人可以帮助我解决这个问题。SSIS Web服务 - 写入到Web服务

感谢

+0

我相信“读书”是指“呼叫”,这意味着Web服务是做既可以是操作读或写,谁知道? – 2013-02-14 16:42:54

+0

你有什么尝试?你能提供一个不适合你的代码样本吗? – 2013-02-18 23:59:06

回答

0

的问题是有点太含糊给出一个明确的答案,但是,采取猜你问,是你已经能够读取Web服务数据( GET),但您现在想要将(POST/PUT)数据写入Web服务。

如果是这样,您最好的选择是使用脚本任务并使用C#(或VB)调用所述Web服务。我也推荐这样做GET请求,而不是SSIS Web服务任务,它不处理“更新”的Web服务协议,比如oAuth认证。

粗糙样本情况如下:

 using System.Net 
     using System.IO   

     string url 
      = "http://webservicehere.org"; 

     // create the request 
     HttpWebRequest request 
      = (HttpWebRequest)HttpWebRequest.Create(url); 

     // set the method to POST 
     request.Method 
      = "POST"; 

     // set the content type, usually application/json or application/xml 
     request.ContentType 
      = "application/json"; 

     // handle authentication, in this case the web service 
     // requires the authentication token to be passed in as a 
     // header called "Cookie" 
     request.Headers.Add("Cookie", SqlAuthCookie); 

     // get the stream object to use to write the request data 
     StreamWriter requestWriter 
      = new StreamWriter(request.GetRequestStream()); 

     // write the data to the web service 
     // where (data) is the JSON/XML that you are 
     // sending to the endpoint 
     requestWriter.Write(data); 

     // close the connection upon completion 
     requestWriter.Close(); 

     try 
     { 
      // read the response received from the web service 
      HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse(); 

      // code to handle the response goes here 
      // i.e. deserialise json/xml to strongly typed objects 

     } 
     catch (WebException we) 
     { 
      // catch any exceptions thrown by the web service here 
     } 
     catch (Exception e) 
     { 
      // catch other exceptions here 
     }