我已经成功地能够在 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
}