【问题标题】:Consume WCF with SimpleInjector使用 SimpleInjector 使用 WCF
【发布时间】:2015-11-21 12:50:29
【问题描述】:

我对 SimpleInjector 和 WCF 还是很陌生

有没有什么方法可以使用 SimpleInjector 来消耗 WCF? 以下是我的 WCF 代码

[ServiceContract]
public interface IPassAuth
{
    [OperationContract]
    string Authenticate(string uid, string pass);
}

public class PassAuth : IPassAuth
{
    //   Implementations here...
}

现在的问题是如何使用 SimpleInjector 使用 ASP.Net MVC? 我还需要创建一个与其匹配的 OperationContracts 的接口吗? 我已经阅读了on WCF Integration Simple Injector 的文档,但我似乎无法理解这个想法。

任何简单的代码都会非常清晰和有帮助。

【问题讨论】:

    标签: c# asp.net wcf simple-injector


    【解决方案1】:

    您提到的文章是关于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 的类。使用这种方法,您可以向创建的类添加自定义扩展。

    【讨论】:

    • 这和从 RestApi.dll 调用一样吗?
    • 抱歉,从未听说过 RestApi.dll。听起来像是构建或使用 REST 服务的东西,但即使谷歌搜索也无法帮助我确定它是什么特定的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多