【问题标题】:wsHttpBinding with custom autorization, certificates authentification and message transfersecurity具有自定义授权、证书身份验证和消息传输安全性的 wsHttpBinding
【发布时间】: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 中启动时尝试连接到服务时,我没有看到任何异常...

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    因为您的内部异常消息不是很精确,所以我会从启用 wcf 日志记录开始调查,这将生成有关究竟出了什么问题的详细信息。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-06
      • 2011-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-14
      • 2012-10-25
      相关资源
      最近更新 更多