wsHttpBinding具有自定义授权,证书身份验证和邮件传输安全性

时间:2014-06-10 15:14:55

标签: c# wcf

我需要一些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中尝试连接到服务时,我没有看到任何exeptions ......

1 个答案:

答案 0 :(得分:0)

因为您的内部异常消息不是非常精确,所以我将从启用wcf日志记录开始调查,这将生成有关确切错误的详细信息。

您可以在此处找到示例配置: http://msdn.microsoft.com/en-us/library/ms733025.aspx

对于浏览日志,您可以使用SDK中的SvcTraceViewer.exe工具。