我已经能够成功地在SSIS中使用web服务任务消费,但我不能弄清楚如何写入web服务,有人能帮助我吗?
谢谢
发布于 2016-12-14 22:46:37
这个问题有点含糊,无法给出明确的答案,但是,猜测一下您的问题是,您已经能够从web服务(GET)读取数据,但现在您希望将数据写入(POST/PUT)到web服务。
如果是这样的话,最好的办法是使用脚本任务并使用C# (或VB)来调用所述web服务。我还建议对GET请求使用这种方式,而不是SSIS Web Service任务,后者不处理“较新”的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
}https://stackoverflow.com/questions/14877683
复制相似问题