首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SSIS Web服务-写入web服务

SSIS Web服务-写入web服务
EN

Stack Overflow用户
提问于 2013-02-14 23:00:28
回答 1查看 306关注 0票数 2

我已经能够成功地在SSIS中使用web服务任务消费,但我不能弄清楚如何写入web服务,有人能帮助我吗?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-12-14 22:46:37

这个问题有点含糊,无法给出明确的答案,但是,猜测一下您的问题是,您已经能够从web服务(GET)读取数据,但现在您希望将数据写入(POST/PUT)到web服务。

如果是这样的话,最好的办法是使用脚本任务并使用C# (或VB)来调用所述web服务。我还建议对GET请求使用这种方式,而不是SSIS Web Service任务,后者不处理“较新”的web服务协议,如oAuth身份验证。

粗略样本如下:

代码语言:javascript
复制
      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
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14877683

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档