2
我想用結構映射來注入一個wcf客戶端,但我也希望這個客戶端從配置中讀取端點和綁定配置。 我試過如下:用結構映射注入wcf客戶端的可能方法
For<IServiceClient>().LifecycleIs(new UniquePerRequestLifecycle()).Use<ServiceClient>().
Ctor<string>("endpointConfigurationName").Is("WsHttpBinding_IService");
但是,這將導致錯誤:
StructureMap Exception Code: 205\nMissing requested Instance property \"remoteAddress\" for InstanceKey \"e50e036b-9d71-47de-8ac2-d53a641e9be8\"
當我通過remoteAddress它的工作像預期:
For<IServiceClient>().LifecycleIs(new UniquePerRequestLifecycle()).Use<ServiceClient>()
.Ctor<string>("endpointConfigurationName").Is("WsHttpBinding_IService")
.Ctor<string>("remoteAddress").Is("https://myurl/Service.svc");
我不明白爲什麼第一個構造函數重載不能從配置中讀取端點地址? 的配置是這樣的:
>
<client>
<endpoint address="https://myurl/Service.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService" contract="IService" name="WsHttpBinding_IService" />
</client>
史蒂文,你的答案很棒。它爲我節省了很多次。我想知道你是否在這裏糾正我 - > http://stackoverflow.com/questions/19546490/how-to-do-unit-test-a-service-which-has-wcf-client-called – Tun