我仍然是SimpleInjector和WCF的新手
有没有办法使用SimpleInjector来使用WCF? 以下是我的WCF代码
[ServiceContract]
public interface IPassAuth
{
[OperationContract]
string Authenticate(string uid, string pass);
}
public class PassAuth : IPassAuth
{
// Implementations here...
}
现在QUESTION是如何使用SimpleInjector消耗ASP.Net MVC的? 我是否仍需要创建具有匹配的OperationContracts的接口? 我已经阅读了文件on WCF Integration Simple Injector,但我似乎无法理解这个想法。
任何简单的代码都会非常清晰和有用。
答案 0 :(得分:2)
您提到的文章是关于wcf服务的服务器端激活,它不适用于客户端消费。是的,您需要在客户端实现该类。
最简单的方法是使用内置工厂,该工厂根据使用反射的接口自动创建客户端代理。
在你的情况下
BasicHttpBinding myBinding = new BasicHttpBinding();
EndpointAddress myEndpoint = new EndpointAddress("http://service/address");
ChannelFactory<IPassAuth> myChannelFactory = new ChannelFactory<IPassAuth>(myBinding, myEndpoint);
// the CreateChannel automatically creates a instance
// of a concrete client-side proxy class for given interface
IPassAuth wcfClient = myChannelFactory.CreateChannel();
string s = wcfClient.Authenticate( ... );
另一个更高级的选项是编写一个继承自ClientBase
的类。使用这种方法,您可以为创建的类添加自定义扩展。