【发布时间】:2015-09-13 15:04:55
【问题描述】:
有一个 WinForms 应用程序,最近在打开某些表单时开始显示设计时错误:
找不到引用合约的默认端点元素...
你可以看到winforms设计器截图here。
这是一个有据可查的问题(例如here、here 和here),只是我的问题是在我尝试引入依赖注入之后才出现的。
我有一个业务层对象调用这个 web 服务。我已经更改了一些方法,例如:
public class Stocks : BusinessObjectBase
{
private readonly IAxReferenceService axService;
private readonly IDALStock dalstock;
public Stocks()
{
this.axService = new AxReferenceServiceClient();
this.dalstock = new DALStock();
}
public Stocks(IAxReferenceService axService, IDALStock dalStock)
{
this.axService = axService;
this.dalstock = dalStock;
}
public IEnumerable<Model.Stock> GetStock() {
return this.axService.GetStock();
}
}
当我删除我对该服务的依赖注入时,突然一切正常:
public class Stocks : BusinessObjectBase
{
private readonly IDALStock dalstock;
public Stocks()
{
this.dalstock = new DALStock();
}
public Stocks(IDALStock dalStock)
{
this.dalstock = dalStock;
}
public IEnumerable<Model.Stock> GetStock() {
using (var axService = new AxReferenceServiceClient()) {
return axService.GetStock();
}
}
}
我的 webservice 是这样配置的(是的,它在业务层项目和主项目中):
<binding name="BasicHttpBinding_IAxReferenceService"
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" >
<readerQuotas maxDepth="32"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
...
<endpoint address="http://.../AxReferenceService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IAxReferenceService"
contract="AX.IAxReferenceService"
name="BasicHttpBinding_IAxReferenceService" />
我的注射引入了什么问题?
【问题讨论】:
-
我的印象是你使用你的
Stocks类有点像一个单例......并且它是在应用程序引导期间初始化的。如果是这样,请尝试在应用引导生命周期中找到稍后的时间点来创建它。 -
什么?不!为什么我会像单身一样使用它们?每当我需要它的功能时,我都会实例化一个新的
Stock。我还将它注入到其他组件中。