【发布时间】:2015-08-21 21:33:36
【问题描述】:
我在 Castle Windsor 3.3.0.0 中配置类的使用时遇到问题
类是这样的:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class DentalRecordServiceClient : ClientBase<IDentalRecordService>, IDentalRecordService
{
public DentalRecordServiceClient()
{
}
public DentalRecordServiceClient(string endpointConfigurationName) : base(endpointConfigurationName)
{
}
public DentalRecordServiceClient(string endpointConfigurationName, string remoteAddress) : base(endpointConfigurationName, remoteAddress)
{
}
public DentalRecordServiceClient(string endpointConfigurationName, EndpointAddress remoteAddress) : base(endpointConfigurationName, remoteAddress)
{
}
public DentalRecordServiceClient(Binding binding, EndpointAddress remoteAddress) : base(binding, remoteAddress)
{
}
public int GetNumberOfVisits(string fullname, string city, DateTime dateOfBirth)
{
return base.Channel.GetNumberOfVisits(fullname, city, dateOfBirth);
}
}
我有两个相关的接口,如下所示:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[ServiceContractAttribute(ConfigurationName = "IDentalRecordService")]
public interface IDentalRecordService
{
[OperationContractAttribute(Action = "http://tempuri.org/IDentalRecordService/GetNumberOfVisits", ReplyAction = "http://tempuri.org/IDentalRecordService/GetNumberOfVisitsResponse")]
int GetNumberOfVisits(string fullname, string city, DateTime dateOfBirth);
}
还有这个:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface IDentalRecordServiceChannel : IDentalRecordService, IClientChannel
{
}
我的温莎城堡配置是这样的:
container.Register(
Component.For<IDentalRecordService>()
.ImplementedBy<DentalRecordServiceClient>());
在我的代码中,我试图通过这一行解析服务:
var service = container.Resolve<IDentalRecordService>();
但我收到以下错误:
Castle.MicroKernel.ComponentActivator.ComponentActivatorException:ComponentActivator:无法实例化 DentalRecordServiceClient ----> System.Reflection.TargetInvocationException : 调用目标抛出异常。 ----> System.InvalidOperationException:在 ServiceModel 客户端配置部分中找不到引用合同“IDentalRecordService”的默认端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为在客户端元素中找不到与此协定匹配的端点元素。
我想我意识到我的 Castle Windsor 配置应该指定参数,以便调用 DentalRecordServiceClient 上的其他构造函数之一,但我不确定我需要如何或什么数据来提供它。我完全可以传入虚拟数据,以便 Resolve 行正常工作。
有什么帮助吗?提前致谢。
编辑:
好的,我发现我可以直接使用以下代码实例化对象:
var binding = new BasicHttpBinding();
var address = new EndpointAddress("http://myaddress");
var service = new DentalRecordServiceClient(binding, address);
我如何通过温莎城堡做到这一点?
TIA
【问题讨论】:
-
好的,我发现我可以通过使用以下构造函数参数正确地实例化其中一个构造函数:'var binding = new BasicHttpBinding()' 和 'var address = new EndpointAddress("@ 987654321@);'然后做'new DentalRecordServiceClient(binding, address)'。我怎样才能在温莎城堡做同样的事情?
标签: c# castle-windsor