SSIS脚本任务soap Web服务调用错误

时间:2017-01-23 15:17:03

标签: c# web-services soap ssis

我在SSIS脚本任务中调用基于SOAP的Web服务。 Web服务需要用户名,密码和guid才能工作。在从SSIS脚本任务调用Web服务之前,我已成功从控制台应用程序调用Web服务。 这是我的急剧代码:

public void Main()
        {
            // TODO: Add your code here

                        // TODO: Add your code here
            MessageBox.Show((string)Dts.Variables["ServiceDateStart"].Value);

            string userName = "xxx";
            string password = "xxx";
            string licenceID = "xxx";
            ServiceReference.AuthenticationHeader a = new ServiceReference.AuthenticationHeader();
            a.LicenceID = new Guid(licenceID);
            a.UserName = userName;
            a.Password = password;
            ServiceReference.CompanyAccountXmlServiceSoapClient service = new ServiceReference.CompanyAccountXmlServiceSoapClient();

            string result;
            long numberOfResults;
            int counter1 = 0;
            int counter2 = 19;



            do
            {



               result = service.GetCompanyAccountUpdated(a, (string)Dts.Variables["ServiceDateStart"].Value, (string)Dts.Variables["ServiceDateEnd"].Value, counter1, counter2);
               //result = service.GetCompanyAccountUpdated(a, "20150101", "20150107", counter1, counter2);
                counter1 = counter1 + 20;
                counter2 = counter2 + 20;



                using (System.IO.StreamWriter file =
      new System.IO.StreamWriter(@"C:\Users\jkrneta\Documents\GetCompanyAccountUpdated.txt", true))
             {


                 file.WriteLine(result);


             }

            } while (!result.Equals("<CompanyAccountDataSet />"));


            Dts.TaskResult = (int)ScriptResults.Success;
        }

代码在我调用Web服务的地方失败:

ServiceReference.CompanyAccountXmlServiceSoapClient service = new ServiceReference.CompanyAccountXmlServiceSoapClient();

这是我的app.config文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="CompanyAccountXmlServiceSoap">
                    <security mode="Transport" />
                </binding>
                <binding name="CompanyAccountXmlServiceSoap1" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://webservices.nbs.rs/CommunicationOfficeService1_0/CompanyAccountXmlService.asmx"
                binding="basicHttpBinding" bindingConfiguration="CompanyAccountXmlServiceSoap"
                contract="ServiceReference.CompanyAccountXmlServiceSoap" name="CompanyAccountXmlServiceSoap" />
        </client>
    </system.serviceModel>
</configuration>

在调试模式下运行服务时出现的错误是:

  

找不到引用合同的默认端点元素   ServiceModel中的“ServiceReference.CompanyAccountXmlServiceSoap”   客户端配置部分。这可能是因为没有配置   找到了您的应用程序的文件,或者因为没有端点元素   匹配此合同可以在客户端元素中找到。

通过脚本工作使我的SSIS Web服务需要什么? 问候。

2 个答案:

答案 0 :(得分:0)

尝试使用这种方式:

ServiceReference.CompanyAccountXmlServiceSoapClient service = 
new  ServiceReference.CompanyAccountXmlServiceSoapClient("CompanyAccountXmlServiceSoap");

其他选项是:

Reload the service reference of your project.

只是给你一个想法:

在我自己的经验中,我确实为我的代码设置了一个端点地址,如下所示:

service.Endpoint.Address = new System.ServiceModel.EndpointAddress("https://webservices.nbs.rs/CommunicationOfficeService1_0/CompanyAccountXmlService.asmx");

答案 1 :(得分:0)

问题是脚本任务不接受app.config,所以你的配置没有进入游戏。请尝试在代码中设置所有组件,如下所示:

            EndpointAddress endpointAdress = new 
 EndpointAddress("https://webservices.nbs.rs/CommunicationOfficeService1_0/CompanyAccountXmlService.asmx");
            BasicHttpBinding binding1 = new BasicHttpBinding();
            binding1.Security.Mode = BasicHttpSecurityMode.Transport;
            var client = new ServiceReference.CompanyAccountXmlServiceSoapClient(binding1, endpointAdress);

如果客户端被创建得很好,那么你就可以去了。

相关问题