[英]WCF Runtime Exception “Could not find default endpoint element that references…”
I am beginner to WCF. 我是WCF的初学者。 What I was trying to do is generating Proxyclass using ClientBase<> method where Program is compiled successfully but its getting runtime exception like,
我试图做的是使用ClientBase <>方法生成Proxyclass,其中Program编译成功,但是它得到运行时异常,例如,
"An unhandled exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll Additional information: Could not find default endpoint element that references contract 'ServiceContract.ICalculator' 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." “在System.ServiceModel.dll中发生了'System.InvalidOperationException类型的未处理异常。附加信息:在ServiceModel客户端配置部分中找不到引用合同'ServiceContract.ICalculator'的默认端点元素。这可能是因为没有配置文件为您的应用程序找到,或者因为在客户端元素中找不到与该合同匹配的端点元素。”
I don't get why is it happening eventhough I have given endPoints in configuration file. 即使我在配置文件中指定了端点,我也不知道为什么会这样。 (I am using Self-Hosting)
(我正在使用自托管)
Below is my code. 下面是我的代码。
<---ClientSide---> <--- ---客户方>
Program.cs Program.cs中
namespace Client
{
public class Program
{
public static void Main(string[] args)
{
CalculatorProxy client = new CalculatorProxy();
//CalcService.CalculatorClient client = new CalcService.CalculatorClient();
Console.WriteLine("Addition of 5 & 6 is " + client.Add(5, 6));
Console.ReadLine();
}
}
}
CalculatorProxy.cs CalculatorProxy.cs
namespace Client
{
class CalculatorProxy: ClientBase<ICalculator>, ICalculator
{
public double Add(double n1, double n2)
{
return base.Channel.Add(n1, n2);
}
public double Subtract(double n1, double n2)
{
return base.Channel.Subtract(n1, n2);
}
public double Multiply(double n1, double n2)
{
return base.Channel.Multiply(n1, n2);
}
public double Divide(double n1, double n2)
{
return base.Channel.Divide(n1, n2);
}
}
}
App.config (Same file at both side, Client & Host) App.config (客户端和主机的文件都相同)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICalculator" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/ServiceModelSamples/Service/CalculatorService"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICalculator"
contract="ICalculator" name="WSHttpBinding_ICalculator" />
</client>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
<---ServiceContract---> <--- ---的ServiceContract>
namespace ServiceContract
{
[ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")]
public interface ICalculator
{
[OperationContract]
double Add(double n1, double n2);
[OperationContract]
double Subtract(double n1, double n2);
[OperationContract]
double Multiply(double n1, double n2);
[OperationContract]
double Divide(double n1, double n2);
}
}
将端点中的合同属性值更改为ServiceContract.ICalculator,因为它应该是完全合格的
Try endpoint definition like this: 试试这样的端点定义:
<endpoint address="http://localhost:8080/ServiceModelSamples/Service/CalculatorService"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ICalculator"
contract="ServiceContract.ICalculator" name="WSHttpBinding_ICalculator" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.