2

我不明白为什么 WCF 工具无法在我的客户端配置上设置用户名凭据。谁能看到我哪里出错了?

从容器中解析 IService 时,ClientCredentials.UserName.UserName 和 Password 为空。端点等价物也是如此。根本没有设置任何凭据引用,并且都保持为空值。

container
   .Register(
        Component
            .For<IService>()
            .ImplementedBy<ServiceClient>()
                .AsWcfClient(
                     new DefaultClientModel
                          {
                              Endpoint = WcfEndpoint
                                  .FromConfiguration("binding"),
                          }
                 .Credentials(
                        new UserNameCredentials(
                            "username", 
                            "password"))));

绑定和端点配置是从 app.config 文件中正确获取的——这纯粹是我需要解决的身份验证。

为了完整性:

 <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="binding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://___________________" binding="basicHttpBinding" bindingConfiguration="binding" contract="Namespace.Class" name="binding" />
    </client>
  </system.serviceModel>
4

0 回答 0