[英]SSIS Web services - Write to web services
我已經能夠成功使用SSIS中的Web服務任務,但是我無法弄清楚如何寫Web服務,有人可以幫我這個忙。
謝謝
這個問題有點含糊,無法給出確切的答案,但是,您可以猜測您要問的是,您已經能夠從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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.