传送消息的身份验证失败。预期的身份是:

9

我在我的电脑上成功地运行了一个WCF服务。

将它移植到服务器后,现在出现了以上错误。

我在服务器上生成了一个测试证书。

这是我的客户端配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <runtime>
        <loadFromRemoteSources enabled="true"/>
    </runtime>
    <system.serviceModel>
        <bindings>
            <wsDualHttpBinding>
                <binding name="WSDualHttpBinding_IMessageHandlerServer" 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="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" clientBaseAddress="http://192.168.1.74:8081">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00" />
                    <security mode="Message">
                        <message clientCredentialType="UserName" negotiateServiceCredential="true"
                            algorithmSuite="Default" />
                    </security>
                </binding>
            </wsDualHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://192.168.1.100:8080/" binding="wsDualHttpBinding"
                bindingConfiguration="WSDualHttpBinding_IMessageHandlerServer"
                contract="MessageService.IMessageHandlerServer" name="WSDualHttpBinding_IMessageHandlerServer" behaviorConfiguration="myClientBehavior">
                <identity>
                    <certificate encodedValue="AwAAAAEAAAAUAAAA9fenyF3cSS38ldDDxtUyC8TajBAgAAAAAQAAALgBAAAwggG0MIIBYqADAgECAhD3kPMzVBbXlEAT5S65MldSMAkGBSsOAwIdBQAwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3kwHhcNMTEwMjExMTU0MDMwWhcNMzkxMjMxMjM1OTU5WjAXMRUwEwYDVQQDEwxNeVNlcnZlckNlcnQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAJ9D8W2GBGvwTAZ2eQj12atxPruZxuOwTCLXRwtEvpnoLmlwBuxo7Wb+of0k4XTNLa7q/Xvjh3zsJbvevlPG3hk9+ugds/Je5X69uPbQApYJO2HZNY9hrwfMZ40iaJ54vVAkdnIhDT5pEpmKVFFkPangk1aMyb6Ilm4NjO9bUxjFAgMBAAGjSzBJMEcGA1UdAQRAMD6AEBLkCS0GHR1PAI1hIdwWZGOhGDAWMRQwEgYDVQQDEwtSb290IEFnZW5jeYIQBjdsAKoAZIoRz7jUqlw19DAJBgUrDgMCHQUAA0EAGT7q1aZwAaJ4sMbv53BOo2/yVSpYkTRIaQwT0uYdY1SLyJ7uaUwqJR0jG+nNqwgyOEOfg4Tz0/dX740dw12+1Q==" />
                </identity>
            </endpoint>
        </client>
      <behaviors>
        <endpointBehaviors>
          <behavior name="myClientBehavior">
            <clientCredentials>
              <serviceCertificate>
                <authentication certificateValidationMode="Custom" customCertificateValidatorType="MyX509Validator,MessageHandlerClient" />
              </serviceCertificate>
            </clientCredentials>
          </behavior>
        </endpointBehaviors>
      </behaviors>
    </system.serviceModel>
</configuration>

编辑

代理初始化如下,但这不是引发错误的地方...

InstanceContext context = new InstanceContext(new MyCallback());
            Configuration stockConfiguration = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = @"C:\Users\Ash\Desktop\Config\app.config" }, ConfigurationUserLevel.None);

            ConfigurationDuplexChannelFactory<MessageHandlerClient.MessageService.IMessageHandlerServerChannel> stockChannelFactory = new ConfigurationDuplexChannelFactory<MessageHandlerClient.MessageService.IMessageHandlerServerChannel>(context, "WSDualHttpBinding_IMessageHandlerServer", null, stockConfiguration);
            stockChannelFactory.Credentials.UserName.UserName = "test";
            stockChannelFactory.Credentials.UserName.Password = "test";
            stockClient = stockChannelFactory.CreateChannel();

错误是在我使用代理进行调用时抛出的,例如:
stockClient.messageToServerWithoutDirectReturn(moduleName, moduleType, methodName, inputs);

如果您需要更多信息,请告诉我。

祝好

Ash


我假设这是当您初始化客户端代理时发生的。您能否展示一下创建您的 Web 服务代理的代码? - Edwin de Koning
没有问题,代理初始化工作正常... 问题出在我通过代理实际调用方法的地方... 我已经在主帖中包含了相关信息。 - user589195
2个回答

12

由于您将客户端移动到另一台服务器并使用新证书,因此您需要更新您的标识/证书节点:

        <identity>
            <certificate encodedValue="..." />
        </identity>

它可能仍然指向您客户端的身份存储和证书


谢谢这个...我该如何更改它呢?比如,我怎么知道要将编码值设置为多少? - user589195
@user589195:你最初是如何生成配置的?你运行了svcutil吗?如果是这样,在服务器上再次运行它,并在客户端配置中替换相应的部分。 - Edwin de Koning
1
感谢您的帮助。我刷新了服务引用,并在我的外部配置中使用了新生成的编码值。 - user589195
1
遇到了同样的问题..谢谢! - Jose

1

你有两种方法来改变它。

<identity>
    <certificate encodedValue="the value of base64 encoded value of the certificate that you are using">
</identity>

或者

<identity>
    <certificateReference findValue="thumbprint" storeLocation="LocalMachine" storeName="My">
</identity>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接