InvalidOperationException异常,同时创造WCF Web服务实例 [英] InvalidOperationException while creating wcf web service instance

查看:226
本文介绍了InvalidOperationException异常,同时创造WCF Web服务实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从一个类库引用一个WCF Web服务。项目运行后,创建从内一个类库的服务客户对象的时候,我收到一个InvalidOperationException与消息:

  

找不到引用合同默认的终结点元素   在ServiceModel客户的MyServiceReference.IMyService   配置部分。这可能是因为没有配置文件是   找到了适合自己的应用程序,或者是因为没有终点的元素匹配   本合同可以在客户端元素中找到。

在code我用来创建实例是:

  myServiceClient =新MyServiceClient();
 

其中MyServiceClient继承

System.ServiceModel.ClientBase

我要如何解决这个问题?

注:我有一个简单的创建相同的服务对象并调用它一个单独的控制台应用程序和它的作品没有任何问题

解决方案
  

下面是类库我app.config文件:

您应该把这个配置设置,主要的应用程序的配置文件。 .NET应用程序(而调用你的类库)使用的数据来自其自己的配置文件不是从资料库的配置文件。

I have a WCF Web Service which is referenced from a class library. After the project is run, when creating the service client object from inside a class library, I receive an InvalidOperationException with message:

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.

The code I am using to create the instance is:

myServiceClient = new MyServiceClient();

where MyServiceClient inherits from

System.ServiceModel.ClientBase

How do I solve this?

Note: I have a seperate console application which simply creates the same service object and makes calls to it and it works without no problems.

解决方案

Here is my app.config file of the class library:

You should put this configuration settings to main app's config file. .NET application (which is calling your class library) uses data from it's own config file not from your library config file.

这篇关于InvalidOperationException异常,同时创造WCF Web服务实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆