本文介绍了VS2010 用户控件 &周转基金的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在 c# 中使用用户控件来为 tabm 中的功能提供单独的类,效果很好.

We are using usercontrols in c# to have separate classes for features inside a tabm which works perfectly.

当用户控件使用对任何 Web 服务的服务引用时,就会出现我们的问题.第一次在窗体上拖动控件有效.第二次,设计器会显示错误:

Our problem arises, when an usercontrol uses a Service Reference to any Webservice.The first time dragging the control on the form works. The second time, the designer will show an error:

Could not find default endpoint element that references contract 'testSR.WebService' 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.

app.config 包含正确的端点,只要调用代码在表单内部,它就可以工作,一旦我们将代码移动到用户控件,我们就会遇到这些问题.

The app.config contains the correct endpoint and it works as long as the calling code is inside the form itself, as soon as we move the code to the usercontrol, we have these problems.

我什至尝试将用户控件放在解决方案中的另一个项目中,正确引用它并将端点/绑定配置从 DLL 的 app.config 复制到 EXEs app.config - 然后问题再次出现...

I even tried to put the user control inside another project within the solution referenced it correctly and copied the endpoint/binding configurations from the app.config of the DLL to the EXEs app.config - then also the problem arises again...

似乎用户控件不能引用webservices,但应该有解决方案!?

It seems that user controls cannot reference webservices, but there should be a solution!?

从我的测试来看,现在似乎用户控件可以使用服务引用,但 VisualStudio 设计器只会在第一次工作,之后程序仍然有效,但设计器显示错误,当我忽略它时,设计器从表单中删除用户控件.只要我不触摸包含表单,用户控件就可以编辑并且工作正常......

From my testing it now seems that user controls can use service references, but the VisualStudio Designer will only work for the first time, after that the programm still works, but the designer shows the error and when I ignore it, the designer removes the user control from the form. As long as I do not touch the containing form, the usercontrol is editable and working fine ...

推荐答案

我假设您正在使用 winforms.UI 和 WCF 之间有明确的分离,并通过使用户控件不直接调用 wcf 而是调用为您调用服务层的中间类库来避免这个和其他问题.这样,WCF 将被此类库调用,您的 UI 将被隔离.

I assume you are working with winforms. have a clear separation between UI and WCF and avoid this and other issues by making the usercontrol not to call wcf directly but call an intermediate class library which calls the service layer for you. In this way the WCF will be called by such class library and your UI will be isolated.

实际上考虑您描述的这个问题,您是否在设计时也需要 WCF 连接?如果是这样,您可能应该通过检查是否在设计时运行来避免它,在这种情况下什么都不做.删除依赖项并使您的 UI 独立于服务引用无疑是一个好主意.

Actually thinking about this problem you are describing, are you requiring WCF connectivity at design time as well? if so you shoul probably avoid it by checking if running at design time in which case do nothing. removing the dependency and having your UI independent from Service References is anyway surely a good idea.

这篇关于VS2010 用户控件 &周转基金的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 20:58