WCF提供不安全或错误安全的错误

use*_*862 68 c# wcf

我正在尝试使用远程svc Web服务.我创建了代理类svcutil.exe,之后我将该类添加到我的控制台应用程序中,但它产生了一个错误:

从另一方收到了不安全的错误或错误的安全故障.有关故障代码和详细信息,请参阅内部故障异常.

System.ServiceModel.FaultException:验证消息的安全性时发生错误

我没有创建WCF端,它是一个远程svc.请帮忙.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="EloquaDataTransferService" 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="Mtom" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="TransportWithMessageCredential">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://secure.eloqua.com/API/1.2/DataTransferService.svc"
                binding="basicHttpBinding" bindingConfiguration="EloquaDataTransferService"
                contract="DataTransferService" name="EloquaDataTransferService" />
        </client>
    </system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)

这是我的app.config档案.我consoleApp.cs使用obj.ServiceCredentials.UserName.UserName="xxxxxx"和提供我的文件中的用户名和密码.Password="xxxXx"

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <system.serviceModel>
      <bindings>
         <basicHttpBinding>
            <binding name="EloquaDataTransferService" 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="Mtom" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
               <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
               <security mode="TransportWithMessageCredential">
                  <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
                  <message clientCredentialType="UserName" algorithmSuite="Default" />
               </security>
            </binding>
         </basicHttpBinding>
      </bindings>
      <client>
         <endpoint address="https://secure.eloqua.com/API/1.2/DataTransferService.svc" binding="basicHttpBinding" bindingConfiguration="EloquaDataTransferService" contract="DataTransferService" name="EloquaDataTransferService" />
      </client>
   </system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)

Ran*_*pho 133

这是WCF服务抛出的一个非常模糊的错误.问题是WCF无法验证传递给服务的消息的安全性.

这几乎总是因为服务器时间偏差.远程服务器和客户端的系统时间必须在(通常)彼此相差10分钟之内.如果不是,安全验证将失败.

我打电话给eloqua.com,找出他们的服务器时间,并将其与服务器时间进行比较.

  • @Randolpho ...嗯...在我的情况下,我正在运行我的WCF服务,测试服务器和测试客户端都运行在同一台机器上,所以我不确定在我的情况下,这可能是服务器时间歪...如果你能告诉我......或者我能解决的其他问题,我将非常感激! (3认同)
  • @ user782534如果您使用[自定义绑定](http://msdn.microsoft.com/en-us/library/aa738468.aspx),您可以在配置中设置偏斜,但是您无法使用默认绑定我所知道的.我也没有意识到完全禁用支票的能力.我倾向于那个. (2认同)
  • 我打电话给一个远程服务的人比我的还要快9个小时回复我.(实际上它似乎就像在SoapUI日志上那样.)然后我收到了这个错误.响应头包含我的senddate但在SOAP UI日志上我注意到响应时间总是比我的请求时间长9小时.怎么会这样?即使我改变了我的本地日期时间.感谢名单 (2认同)

Xca*_*bur 22

尽管您的问题已通过上述解决方案之一解决,但为了其他人的利益,这是另一种选择.

当不正确的凭据传递到使用用户名消息凭据的基本端点(SOAP 1.1)时,您也可以获得此异常.例如,如果您从代码调用服务并执行以下操作:

var service = new TestService();

service.ClientCredentials.UserName.UserName = "InvalidUser";
service.ClientCredentials.UserName.Password = "InvalidPass";
Run Code Online (Sandbox Code Playgroud)

这与WSHTTP端点(SOAP 1.2)不同,后者AccessDeniedException在传递无效凭据时抛出.我个人觉得这里包含的信息有点误导(因为这个原因我第一次遇到它时肯定花了几分钟)但是一旦我查阅了WCF诊断跟踪日志,其根本原因就很明显了.


Dan*_*ner 13

您显然遇到了WCF安全子系统的问题.你使用什么装订?什么认证?加密?登录?你必须越过域名界限吗?

如果客户端和服务器的时钟不同步(超过大约五分钟),因为某些安全模式依赖于同步时钟,所以进一步显示其他人正在经历此错误.

  • 在我的情况下,同一台机器上的服务和客户端,但我仍然是例外.这发生在一段时间(即10分钟)之后,clientCredentialType是Windows (2认同)

Hai*_*ihi 5

同样的问题,我面临的客户端应用程序是WinForms应用程序C#4.0

当我在这里阅读解决方案时,我检查了客户端计算机的日期和时间,但这是正确的,当前时间显示,但我仍然面临着这些问题.

经过一些解决方法我发现选择了错误的时区,我在印度和时区是加拿大,主机服务器位于科威特.

我发现系统将时间转换为通用时间.

当我把时区改为印度的时区时,问题就出现了.