【发布时间】:2014-06-12 06:01:32
【问题描述】:
我需要 WCF 方面的帮助!
我编写了带有自定义授权和身份验证的 WCF 服务。当我从 Visual Studio 启动它时,服务运行良好,但是当我从任何主机(Windows 服务或我创建的主机)启动它时 - 抛出下一个异常:
“从另一方收到不安全或不正确安全的故障。请参阅内部 FaultException 了解故障代码和详细信息。”
内部异常:
“验证消息的安全性时出错。”
服务配置(它配置我复制到主机 app.cong):
<system.serviceModel>
<!--Binding with custom authentication-->
<bindings>
<wsHttpBinding>
<binding name="licenseServiceBinding">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="NS_SLM_Service.Service.LicenseService" behaviorConfiguration="customBehaviour">
<!--One service devided by a few contracts, because on a client need to separate API-functions-->
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="licenseServiceBinding" contract="NS_SLM_Service.Service.IAdminFunctions" />
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="licenseServiceBinding" contract="NS_SLM_Service.Service.IManagerFunctions" />
<endpoint address="http://localhost:8080/LicenseService/CommonFunctions" binding="basicHttpBinding" contract="NS_SLM_Service.Service.ICommonFunctions" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/LicenseService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="customBehaviour">
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceAuthorization principalPermissionMode="Custom">
<authorizationPolicies>
<add policyType="NS_SLM_Service.UserAuthorization,NS_SLM_Service" />
</authorizationPolicies>
</serviceAuthorization>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="NS_SLM_Service.UserAuthentication,NS_SLM_Service" />
<serviceCertificate findValue="tempCert" storeLocation="LocalMachine" x509FindType="FindBySubjectName" storeName="My" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
下一个尝试连接到该服务的代码:
using (var proxy = new MyService())
{
proxy.ClientCredentials.UserName.UserName = "Login";
proxy.ClientCredentials.UserName.Password = "password";
proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
proxy.SomeMethod("Parametr");
}
我很沮丧,因为当我在 VS 中启动时尝试连接到服务时,我没有看到任何异常...
【问题讨论】: