我在配置X509证书之后调用WCF服务出现了异常,异常信息如下:An error occurred when verifying security for the message,(注:不是由时间差引起的),在线求解。
没有,参数数据类型就是string.
这是对方的webservice 要求安全认证,你应该有用户名或密码的配置
是的,我调用的时候传入了相应的用户名和密码
@大灰机: 检查下服务安全配置,与你的用户名密码,还有wcf的验证代码(如果有的话),问题出在这三个地方
@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;
//查询数据库判断用户名密码是否存在
}
@大灰机:
大侠,不啬赐教。
@大灰机: 有没有进入这个Validate方法?
@大灰机: <userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="WcfSafeTest.UserValidator,WcfSafeTest" />
<issuedTokenAuthentication allowUntrustedRsaIssuers="true" />这一段配置仔细对下
是否传递了接口类型数据,或者是对象类型参数?
看信息是安全性的问题