0

我构建了一个使用 wsHttpBinding 的 WCF 服务和一个调用它的客户端。
但我仍然收到以下错误消息:

An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail.

内部例外是:

An error occurred when processing the security tokens in the message.

这是服务的配置文件:

   <configuration>
     <system.serviceModel>
       <bindings>
         <wsHttpBinding>
           <binding name="myWsBinding">
             <security>
               <message negotiateServiceCredential="false" algorithmSuite="Basic128"
                 establishSecurityContext="false" />
             </security>
           </binding>
         </wsHttpBinding>
       </bindings>
       <services>
         <service behaviorConfiguration="ServiceBehavior" name="HelloWorldService.HelloService">
           <endpoint address="" binding="wsHttpBinding" bindingConfiguration="myWsBinding"
             contract="HelloWorldService.IHelloService">
             <identity>
               <servicePrincipalName value="host/MAGBAREYA"/>
             </identity>
           </endpoint>
           <host>
             <baseAddresses>
               <add baseAddress="http://localhost:8999/myService" />
             </baseAddresses>
           </host>
         </service>
       </services>
       <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior">
              <serviceDebug includeExceptionDetailInFaults="true" />
              <serviceMetadata httpGetEnabled="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>

这是客户端配置文件:

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IHelloService">
                    <security mode="Message">
                        <message clientCredentialType="Windows" negotiateServiceCredential="false"
                            algorithmSuite="Basic128" establishSecurityContext="false" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8999/myService" binding="wsHttpBinding"
                bindingConfiguration="WSHttpBinding_IHelloService" contract="ServiceReference1.IHelloService"
                name="WSHttpBinding_IHelloService">
                <identity>
                    <servicePrincipalName value="host/MAGBAREYA"/>
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

有问题的配置是:negotiateServiceCredential="false"。
如果我在服务和客户端中都将其设置为 true,则客户端将完美运行。(除了此更改之外,使用上述配置文件)

谁能告诉我在这里想念什么?

提前致谢。

4

1 回答 1

0

我会尝试启用更多日志记录。在您的服务器上,您可以在服务的配置文件中启用对整个 WCF 消息的日志记录,如下所示:

 <system.diagnostics>
<sources>
  <source name="System.ServiceModel.MessageLogging">
    <listeners>
             <add name="messages"
             type="System.Diagnostics.XmlWriterTraceListener"
             initializeData="c:\logs\messages.svclog" />
      </listeners>
  </source>
</sources>
</system.diagnostics>

<system.serviceModel>
<diagnostics>
<messageLogging 
     logEntireMessage="true" 
     logMalformedMessages="false"
     logMessagesAtServiceLevel="true" 
     logMessagesAtTransportLevel="false"
     maxMessagesToLog="3000"
     maxSizeOfMessageToLog="2000"/>
  </diagnostics>
</system.serviceModel>

完成此操作后,您可以再次测试客户端以重新创建异常并使用工具svctraceviewer检查您的 .svclog 文件

于 2018-07-30T16:02:21.197 回答