c# Soap Client Issue - more than one endpoint configuration for th at contract was found

C#Soap

C# Problem Overview


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?

C# Solutions


Solution 1 - C#

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

Solution 2 - C#

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.

Solution 3 - C#

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

enter image description here

Solution 4 - C#

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLatheesanView Question on Stackoverflow
Solution 1 - C#sudil ravindran pkView Answer on Stackoverflow
Solution 2 - C#LatheesanView Answer on Stackoverflow
Solution 3 - C#Abdul KhaliqView Answer on Stackoverflow
Solution 4 - C#LarryView Answer on Stackoverflow