[英]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似乎正在运行。
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.