我有一个从类库引用的WCF Web服务。运行项目后,从类库内部创建服务客户端对象时,我收到带有消息的InvalidOperationException:
Could not find default endpoint element that references contract 'MyServiceReference.IMyService' 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.
我用来创建实例的代码是:
myServiceClient = new MyServiceClient();
MyServiceClient继承自的位置
System.ServiceModel.ClientBase
我该如何解决?
注意:我有一个单独的控制台应用程序,它可以简单地创建相同的服务对象并对其进行调用,并且可以正常工作。
最佳答案
Here is my app.config file of the class library:
您应该将此配置设置放入主应用程序的配置文件中。 .NET应用程序(正在调用您的类库)使用其自身配置文件中的数据,而不是库配置文件中的数据。
关于.net - 创建WCF Web服务实例时发生InvalidOperationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24993/