简体   繁体   English

c#Soap客户端问题 - 找到了合同中的多个端点配置

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

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) 我正在尝试编写一个简单的c#控制台应用程序来测试SOAP API: https//www.imailtest.co.uk/webservice/imail_api.asmx?wsdl (或https://www.imailtest.co.uk /webservice/imail_api.asmx查看api方法)

So, I added this reference and tried to invoke 2 api methods (Authentiacate & ProcessPrintReadyPDF) calls on it and got this error: 所以,我添加了这个引用,并尝试在其上调用2个api方法(Authentiacate和ProcessPrintReadyPDF)调用并得到此错误:

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. 错误:无法加载合同“ServiceReference1.imail_ apiSoap”的端点配置部分,因为找到了合同中的多个端点配置。 Please indicate the preferred endpoint configuration sect ion by name. 请按名称指明首选端点配置部分。

Here's my C# Code: 这是我的C#代码:

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: 这是我将服务引用添加到控制台应用程序的方式:

截图

Any ideas? 有任何想法吗?

In your App.config you can see some thing like this 在你的App.config中你可以看到这样的东西

 <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 现在运行代码,希望你的代码工作正常

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. 现在,我不再收到错误,api似乎正在运行。

[Solved! [解决了! just add the End point in the webservice's proxy class asp below screen shot 只需在webservice的代理类asp下面的屏幕截图中添加End point

在此输入图像描述

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: 因此,您的App.config文件将包含此条目,允许您指定所需的端点:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 调用Web服务时出现错误,“该合同有多个端点配置”或“没有端点监听” - Errors calling web service, “ more than one endpoint configuration for that contract” or “no endpoint listening” 从c#服务器端调用asmx:可以在client元素中找到匹配此契约的端点元素 - calling asmx from c# server side: endpoint element matching this contract could be found in the client element 一个端点中的多服务合同c#wcf - multi service contract in one endpoint c# wcf 使用具有不同端点URI的C#服务引用SOAP客户端 - Using a C# Service Reference SOAP Client with different Endpoint URIs 在ServiceModel客户端配置部分中找不到名称为``and contract&#39;&#39;的终结点元素 - Could not find endpoint element with name '' and contract '' in the ServiceModel client configuration section C#中的代码合同问题 - Issue with Code Contract in c# 在1个端点,WCF,Mono中找不到客户端端点配置“*” - Client endpoint configuration '*' was not found in 1 Endpoints, WCF, Mono c#正则表达式不止一个词 - c# Regex more than one word 一个以上单例C#实例 - more than one instance of singleton c# 客户端无法从服务器(C#)读取多个消息 - Client can't read more than one message from server (C#)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM