2015-11-21 47 views
0

Im對SimpleInjector和WCF一般來說還是新手使用SimpleInjector消耗WCF

是否有任何方式使用SimpleInjector來使用WCF? 下面是我的WCF代碼

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

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

現在的問題是我怎麼能ASP.Net MVC使用SimpleInjector它消耗? 我是否還需要創建一個與其匹配的OperationContracts接口? 我已閱讀文檔on WCF Integration Simple Injector,但我似乎無法理解應有的想法。

任何簡單的代碼將大大清楚和幫助。

回答

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繼承的類。通過這種方法,您可以爲創建的類添加自定義擴展。

+0

這和從RestApi.dll調用一樣嗎? – Reyn

+0

對不起,沒聽說過RestApi.dll。聽起來像是要構建或使用REST服務的東西,但即使使用Google搜索也無法幫助我確定它是什麼特定的解決方案。 –

相關問題