我有一个配置条目,在某些我无法控制的条件下,在运行时没有加载。这阻止我连接到WCF服务。
如何强制加载配置条目或在运行时动态定义端点?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_AReportingService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536000"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="MyEndpointBehavior">
<dataContractSerializer maxItemsInObjectGraph="65536000"/>
</behavior>
<behavior name="ImpersonationBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<clientCredentials>
<windows allowedImpersonationLevel="Impersonation"/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="https://toto.echonet/AReportingService_strong_auth/AReportingService.svc"
behaviorConfiguration="ImpersonationBehavior" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IAReportingService"
contract="AReportingService.IAReportingService"
name="WSHttpBinding_IAReportingService" >
<identity>
<servicePrincipalName value="mytoto01p@net.intra" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
我的问题是在启动时根本没有加载任何配置文件,我无法修改加载我的DLL的应用程序。
EDIT1:我尝试了以下内容,但我认为我错过了以某种方式传递凭据:
public static global::AAA.AReportingService.AReportingServiceClient CreateServiceClientInstance()
{
WSHttpBinding binding = new WSHttpBinding(SecurityMode.TransportWithMessageCredential);
EndpointAddress endpoint = new EndpointAddress(new Uri("https://toto.echonet/AReportingService_strong_auth/AReportingService.svc"));
return new global::AAA.FixLinkReportingService.AReportingServiceClient(
binding, endpoint);
}
这会导致以下FaultException:
The message with Action 'http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).