C# WCF 给出不安全或安全不正确的错误错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1484601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WCF gives an unsecured or incorrectly secured fault error
提问by user179862
I am trying to consume a remote svc web service. I created the proxy class using svcutil.exe
, and after that I've added that class to my console application, but it yields an error:
我正在尝试使用远程 svc Web 服务。我使用创建了代理类svcutil.exe
,然后我将该类添加到了我的控制台应用程序中,但它产生了一个错误:
An unsecured error or incorrectly secured fault was received from the other party. See the inner fault exception for the fault code and detail.
System.ServiceModel.FaultException: An error occurred when verifying security for the message
从另一方接收到不安全的错误或不正确的安全故障。故障代码和详细信息请参见内部故障异常。
System.ServiceModel.FaultException:验证消息的安全性时出错
I didn't create the WCF side, it's a remote svc. Please help.
我没有创建 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>
This is my app.config
file. I am providing the username and password in my consoleApp.cs
file using obj.ServiceCredentials.UserName.UserName="xxxxxx"
and .Password="xxxXx"
这是我的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>
回答by Daniel Brückner
You have obviously a problem with the WCF security subsystem. What binding are you using? What authentication? Encryption? Signing? Do you have to cross domain boundaries?
您显然有 WCF 安全子系统的问题。你用的是什么绑定?什么认证?加密?签约?您是否必须跨越域边界?
A bit of goggling further reveals that others are experiencing this error if the clocks of client and server are out of sync (more than about five minutes) because some security schemata rely on synchronized clocks.
如果客户端和服务器的时钟不同步(超过大约 5 分钟),则进一步显示其他人会遇到此错误,因为某些安全模式依赖于同步时钟。
回答by Shiraz Bhaiji
Try changing your security mode to "transport".
尝试将您的安全模式更改为“传输”。
You have a mismatch between the security tag and the transport tag.
您的安全标签和传输标签不匹配。
回答by Randolpho
This is a very obscure fault that WCF services throw. The issue is that WCF is unable to verify the security of the message that was passed to the service.
这是 WCF 服务抛出的一个非常模糊的错误。问题是 WCF 无法验证传递给服务的消息的安全性。
This is almost always because of a server time skew. The remote server and the client's system time must be within (typically) 10 minutes of each other. If they are not, security validation will fail.
这几乎总是因为服务器时间偏差。远程服务器和客户端的系统时间必须在(通常)10 分钟之内。如果不是,安全验证将失败。
I'd call eloqua.com and find out what their server time is, and compare that to your server time.
我会致电 eloqua.com 并找出他们的服务器时间,并将其与您的服务器时间进行比较。
回答by Sam
I've also had this problem from a service reference that was out of date, even with the server & client on the same machine. Running 'Update Service Reference' will generally fix it if this is the issue.
即使服务器和客户端在同一台机器上,我也从过时的服务引用中遇到了这个问题。如果这是问题,运行“更新服务参考”通常会修复它。
回答by user605172
In my case, I was getting this error on the same machine, in my test client-server application. But this problem was resolved by "Update Service Reference".
就我而言,我在同一台机器上,在我的测试客户端 - 服务器应用程序中收到此错误。但是这个问题已经通过“更新服务参考”解决了。
- Tushar G. Walavalkar
- Tushar G. Walavalkar
回答by Chris B
For what it's worth - I also had this error and found it was caused by the connection string in the web services web.config being set to connect to the wrong machine.
对于它的价值 - 我也有这个错误,发现它是由 web 服务 web.config 中的连接字符串被设置为连接到错误的机器引起的。
回答by Xcalibur
Although your problem was solved with one of the above solutions, for the benefit of others, here's another option.
虽然您的问题已通过上述解决方案之一解决,但为了他人的利益,这里还有另一种选择。
You also can get this exception when incorrect credentials are passedto a basic endpoint (SOAP 1.1) that uses username message credentials as you are. For example, if you are calling the service from code and do something like this:
当不正确的凭据传递到使用用户名消息凭据的基本端点 (SOAP 1.1) 时,您也可能会收到此异常。例如,如果您从代码调用服务并执行以下操作:
var service = new TestService();
service.ClientCredentials.UserName.UserName = "InvalidUser";
service.ClientCredentials.UserName.Password = "InvalidPass";
This is different from a WSHTTP endpoint (SOAP 1.2) that throws an AccessDeniedException
when invalid credentials are passed through. I personally find the message contained herein a little misleading (it certainly cost me a few minutes the first time I encountered it for this reason) but the underlying cause was clear once I consulted the WCF Diagnostic Trace Logs.
这与 WSHTTP 端点 (SOAP 1.2) 不同,后者AccessDeniedException
在传递无效凭据时抛出。我个人觉得这里包含的消息有点误导(由于这个原因,我第一次遇到它肯定花了几分钟的时间)但是一旦我查阅了 WCF 诊断跟踪日志,根本原因就很清楚了。
回答by chintan
In my case, when I changed the wshttpbinding
protocol from https
to http
it started working.
就我而言,当我将wshttpbinding
协议从更改为时https
,http
它开始工作。
回答by user2206393
If you are passing user credential from client (As per below code block), then it should match with the username/password on server. otherwise you will get this error.
如果您从客户端传递用户凭据(按照下面的代码块),那么它应该与服务器上的用户名/密码匹配。否则你会得到这个错误。
FYI, in my case I am using "basicHTTPAuthentication" with "TransportWithMessageCredential" security mode. And the WCF service is hosted in IIS on https.
仅供参考,就我而言,我将“basicHTTPAuthentication”与“TransportWithMessageCredential”安全模式一起使用。WCF 服务托管在 IIS 上的 https 中。
var service = new TestService();
service.ClientCredentials.UserName.UserName = "InvalidUser";
service.ClientCredentials.UserName.Password = "InvalidPass";
Hope this will help to someone... :)
希望这会对某人有所帮助... :)
回答by Haider Ali Wajihi
Same this problem i am facing my client application is WinForms application C# 4.0
同样这个问题我面临我的客户端应用程序是 WinForms 应用程序 C# 4.0
When i read the solution here, i checked Date & Time of client computer, but that was right and current time was showing, but still i was facing these problem.
当我在这里阅读解决方案时,我检查了客户端计算机的日期和时间,但这是正确的,并且显示了当前时间,但我仍然面临这些问题。
After some work-around i found that wrong time zone has selected, i am in India and time zone was of Canada, the host server is located in Kuwait.
经过一些变通,我发现选择了错误的时区,我在印度,时区是加拿大,主机服务器位于科威特。
I found that system converts time to universal time.
我发现系统将时间转换为世界时。
When i changed the time zone to India's time zone, the problem was soled.
当我将时区更改为印度时区时,问题就解决了。