您好我正在尝试使用autofac并使用wcf客户端。
但想知道我如何使用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 :(得分:3)
尝试注册ChannelFactory<T>
using the ChannelFactory<T>(string)
constructor并传入配置文件中的端点名称。
builder
.Register(c => new ChannelFactory<apiSoapType>("**somename.apiSoapType**"))
.SingleInstance();