2013-02-14 170 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 
     }