2015-08-09 82 views
0

嗨我試圖使用autofac並使用wcf客戶端。配置autofac在wcf客戶端使用app.config

但想知道如何從我的app.config中使用「客戶端」配置? 如果可能,我想保留配置中的設置?

public void ConfigureContainer() 
{ 
    var builder = new ContainerBuilder(); 
    builder 
     .Register(c => new ChannelFactory<apiSoapType>(new BasicHttpsBinding("?????")) ?????.SingleInstance(); 
    builder.Build(); 
} 

//My app.config 

<? xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
    <behaviors> 
     <endpointBehaviors> 
     <behavior name = "DisableServiceCertificateValidation" > 
      <clientCredentials> 
      <serviceCertificate> 
       < authentication certificateValidationMode="None" revocationMode="NoCheck" /> 
      </serviceCertificate> 
      </clientCredentials> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
    <bindings> 
     <basicHttpsBinding> 
     <binding name = "apiSoapBinding" maxBufferPoolSize="20000000" maxBufferSize="20000000" maxReceivedMessageSize="20000000"> 
      <readerQuotas maxDepth = "32" maxStringContentLength="200000000" maxArrayLength="200000000" /> 
      <security mode = "Transport" > 
      < transport clientCredentialType="None" proxyCredentialType="None" realm="" /> 
      </security> 
     </binding> 
     </basicHttpsBinding> 
    </bindings> 
    <client> 
     <endpoint 
     address = "https://somesite/api.wso" 
     binding="basicHttpsBinding" 
     bindingConfiguration="apiSoapBinding" 
     behaviorConfiguration="DisableServiceCertificateValidation" 
     contract="somename.apiSoapType" 
     name="**somename.apiSoapType**" 
     /> 
    </client> 
    </system.serviceModel> 
</configuration> 

回答

0

嘗試註冊ChannelFactory<T>using the ChannelFactory<T>(string) constructor並通過在您的配置文件中找到的端點名稱。

builder 
    .Register(c => new ChannelFactory<apiSoapType>("**somename.apiSoapType**")) 
    .SingleInstance();