73

I am trying to write a simple c# console application to test the SOAP API from here: https://www.imailtest.co.uk/webservice/imail_api.asmx?wsdl (or https://www.imailtest.co.uk/webservice/imail_api.asmx to see the api methods)

So, I added this reference and tried to invoke 2 api methods (Authentiacate & ProcessPrintReadyPDF) calls on it and got this error:

Error : An endpoint configuration section for contract 'ServiceReference1.imail_ apiSoap' could not be loaded because more than one endpoint configuration for th at contract was found. Please indicate the preferred endpoint configuration sect ion by name.

Here's my C# Code:

static void Main(string[] args)
{
    // Anticipate Error
    try
    {
        // Generate SOAP Client
        ServiceReference1.imail_apiSoapClient soapClient = new ServiceReference1.imail_apiSoapClient();

        // Login
        Console.WriteLine("Authenticating");
        soapClient.Authenticate(iMailUser, iMailPass);

        // Proceed If PDF File Exists
        if (File.Exists(PDFFile))
        {
            // Upload PDF File To iMail
            Console.WriteLine("Uploading PDF File");
            soapClient.ProcessPrintReadyPDF(File.ReadAllBytes(PDFFile), "", true);

            // Test Complete
            Console.WriteLine("Done");
        }
        else
        {
            // Log Error
            Console.WriteLine("PDF File [{0}] Does Not Exists", PDFFile);
        }
    }
    catch (Exception ex)
    {
        // Log Error
        Console.WriteLine("Error : "+ ex.Message);
    }

    // End Test
    Console.WriteLine("Press any key to continue ...");
    Console.ReadKey();
}

This is how I added the service reference to my console app:

screenshot

Any ideas?

kkuilla
  • 2,226
  • 3
  • 34
  • 37
Latheesan
  • 23,247
  • 32
  • 107
  • 201
  • Where is the client configuration in your web.config? – ChrisBint Jul 09 '13 at 09:50
  • 1
    @ChrisBint -There was no web.config, however there was a app.config with the following: http://pastebin.com/XhbK0YNk – Latheesan Jul 09 '13 at 10:21
  • @CodeCaster - actually, the problem is described in the next line `because more than one endpoint configuration for th at contract was found` – Latheesan Jul 09 '13 at 10:22

5 Answers5

152

In your App.config you can see some thing like this

 <client>
      <endpoint address="https://www.imailtest.co.uk/webservice/imail_api.asmx "
        binding="basicHttpBinding" bindingConfiguration="xxxxxxxxxx"
        contract="xxxxxxxxxx" name="xxxxxxxxxxxxx" />
      <endpoint address="https://www.imailtest.co.uk/webservice/imail_api.asmx"
        binding="customBinding" bindingConfiguration="xxxxxxxxxxxxx"
        contract="xxxxxxxxxxx" name="xxxxxxxxxxxxx" />
  </client>

remove the second endpoint and now it should be like this

<client>
      <endpoint address="https://www.imailtest.co.uk/webservice/imail_api.asmx "
        binding="basicHttpBinding" bindingConfiguration="xxxxxxxxxxxxx"
        contract="xxxxxxxxxxxxxx" name="xxxxxxxxxxxxxxx" />      
  </client>

now run the code , hope your code works fine

sudil ravindran pk
  • 2,996
  • 3
  • 24
  • 29
  • 6
    Worked for me. But does anyone know why this step was needed? Why did Visual Studio add the extra end point? – Jonathan Wood Dec 17 '15 at 03:48
  • 7
    There is no need to do that, you only need to explicitly state the name of **endPointConfigurationName**, Meaning `ServiceReference1.svSoapClient service = new ServiceReference1.svSoapClient ("endPointConfigurationName"); instead of `ServiceReference1.svSoapClient service = new ServiceReference1.svSoapClient();` the name can be one of the names in `` in App.config file. – Muhammad Musavi Jun 10 '18 at 06:23
  • 1
    I've noticed that when you delete an webservice in Visual Studio, it doesn't delete the appropriate code in the app.config file. – John Swaringen Jul 30 '18 at 18:55
38

I believe the problem is solved via defining the contract name like so (based on my screenshot):

ServiceReference1.imail_apiSoapClient soapClient = 
new ServiceReference1.imail_apiSoapClient("imail_apiSoap");

Now, I am no longer getting an error and the api appears to be working.

Latheesan
  • 23,247
  • 32
  • 107
  • 201
  • In my case, I... (1) Showed all files in the solution explorer of Visual Studio (icon near the top). (2) Drilled down until I could see configuration.svcinfo. (3) Opened configuration.svcinfo and saw two endpoints listed. (4) Scrolled to the far right to get the name of the endpoint I wanted (info therein looked like the sample posted by Sudil). Since I did not want to delete an endpoint as suggested above, I just added the name of the particular endpoint I wanted to use like Latheesan did. – Saint Ronin Nov 12 '15 at 02:02
  • Note: I am just doing initial testing via a console app so the web.config would not apply/exist in my scenario - nor the app.config file, I believe. – Saint Ronin Nov 12 '15 at 02:11
  • I had duplicates because one was generated for http and the other for https, so this was the correct solution for that scenario – Savage Jul 20 '17 at 08:22
32

[Solved! just add the End point in the webservice's proxy class asp below screen shot

enter image description here

Abdul Khaliq
  • 2,139
  • 4
  • 27
  • 31
3

If you want to keep both client configurations in your config file, just create an application Setting.

So your App.config file will contains this entry that will allow you to specify the endpoint you want:

<setting name="EndPoint" serializeAs="String">
    <value>imail_apiSoap</value>
</setting>

So you can use in your code :

ServiceReference1.imail_apiSoapClient soapClient =
    new ServiceReference1.imail_apiSoapClient(Properties.Settings.Default.EndPoint);
Larry
  • 17,605
  • 9
  • 77
  • 106
0

You don't need to define an endPoint if there is only ONE endpoint in your SOAP service call. However, if there are more, you have to specify the end-point yourself as a string inside the ServiceReference1.imail_apiSoapClient("myEndPoint"); Also, right-click the Connected Service in VS, and choose Update Service Reference. This will re-download any missing configuration settings. Good idea to clean up the config file first though.

Fandango68
  • 4,461
  • 4
  • 39
  • 74