Jovo Krneta
Jovo Krneta

Reputation: 558

SSIS script task soap web service call error

I am calling a soap based web service inside a SSIS script task. The web service requires a user name, password and a guid to work. Previous to calling a web service from a SSIS script task I have called a web service from a console application with success. This is my C sharp code:

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;
        }

The code fails on line where I call the web service :

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

This is my app.config file :

<?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>

The error that I get when I run the service in the debug mode is :

Could not find default endpoint element that references contract 'ServiceReference.CompanyAccountXmlServiceSoap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

What is needed to make my SSIS web service from script work? Regards.

Upvotes: 0

Views: 1656

Answers (2)

maicalal
maicalal

Reputation: 101

The problem is Script Task does not entertain app.config, so your config is not getting into play. Please try setting all components within the code, like below:

            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);

If the client gets created fine then you are good to go.

Upvotes: 0

Vijunav Vastivch
Vijunav Vastivch

Reputation: 4191

Try to use this way:

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

Other option is:

Reload the service reference of your project.

Just giving you an idea:

In my own experienced I do setting up an endpoint address to my code behind like this:

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

Upvotes: 0

Related Questions