首页 新闻 搜索 专区 学院

调用WCF服务时报异常"An error occurred when verifying security for the message“

0
悬赏园豆:80 [已解决问题] 解决于 2012-11-28 21:42

   我在配置X509证书之后调用WCF服务出现了异常,异常信息如下:An error occurred when verifying security for the message,(注:不是由时间差引起的),在线求解。

WCF
问题补充:

没有,参数数据类型就是string.

David·Li的主页 David·Li | 初学一级 | 园豆:76
提问于:2012-11-27 18:20
< >
分享
最佳答案
0

这是对方的webservice 要求安全认证,你应该有用户名或密码的配置

收获园豆:70
az235 | 大侠五级 |园豆:8283 | 2012-11-28 12:29

是的,我调用的时候传入了相应的用户名和密码

David·Li | 园豆:76 (初学一级) | 2012-11-28 12:39

@大灰机: 检查下服务安全配置,与你的用户名密码,还有wcf的验证代码(如果有的话),问题出在这三个地方

az235 | 园豆:8283 (大侠五级) | 2012-11-28 12:41

@az235: 

  服务安全配置:

<behaviors>
<serviceBehaviors>
<behavior name="WcfSafeTest.SafeService">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="None" />
</clientCertificate>
<serviceCertificate findValue="services.ymcft.com" storeLocation="LocalMachine"
storeName="My" x509FindType="FindBySubjectName" />
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="WcfSafeTest.UserValidator,WcfSafeTest" />
<issuedTokenAuthentication allowUntrustedRsaIssuers="true" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="WcfSafeTest.SafeService" name="WcfSafeTest.SafeService">
<endpoint address="" bindingConfiguration="myUserSafeBinding" binding="basicHttpBinding" contract="WcfSafeTest.ISafeService">
<identity>
<dns value="192.168.0.2"></dns>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="myUserSafeBinding">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None"></transport>
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
</bindings>

验证代码:

public override void Validate(string userName, string password)
{
if (string.IsNullOrEmpty(userName))
throw new ArgumentNullException("userName");
if (string.IsNullOrEmpty(password))
throw new ArgumentNullException("password");

customUserName = userName;
custompassword = password;

//查询数据库判断用户名密码是否存在
}

David·Li | 园豆:76 (初学一级) | 2012-11-28 12:50

@大灰机: 

大侠,不啬赐教。

David·Li | 园豆:76 (初学一级) | 2012-11-28 12:52

@大灰机: 有没有进入这个Validate方法?

az235 | 园豆:8283 (大侠五级) | 2012-11-28 12:57

@大灰机: <userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="WcfSafeTest.UserValidator,WcfSafeTest" />
<issuedTokenAuthentication allowUntrustedRsaIssuers="true" />这一段配置仔细对下

az235 | 园豆:8283 (大侠五级) | 2012-11-28 13:04
其他回答(2)
0

是否传递了接口类型数据,或者是对象类型参数?

收获园豆:5
wizards14 | 园豆:207 (菜鸟二级) | 2012-11-28 11:46
0

看信息是安全性的问题

收获园豆:5
Tom.汤 | 园豆:2388 (老鸟四级) | 2012-11-28 12:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册