具有wsHttpBinding,ssl和TransportWithMessageCredential的WCF服务 [英] WCF Service with wsHttpBinding, ssl and TransportWithMessageCredential

查看:107
本文介绍了具有wsHttpBinding,ssl和TransportWithMessageCredential的WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带有ssl通信,wsHttpBinding和传输安全性的wcf服务,但是当我尝试将其更改为:

I've got wcf service with ssl communication, wsHttpBinding and Transport security, but when I try to change it to:

      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="None" />
        <message clientCredentialType="UserName"/>
      </security>

我遇到错误:

An unsecured or incorrectly secured fault was received from the other party. See the  
inner FaultException for the fault code and detail.

我在客户端和服务器端更改了安全模式,并且我有最新的合同. 我找不到解决此问题的任何方法.

I change security mode on client side and server side and I have up to date contract. I can't find any solution to this problem.

你会帮助我吗?

Client.config:

Client.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>  
  <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /></startup>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IDatabaseService">          
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="None" />
            <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://dbservice:3915/DatabaseService.svc"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDatabaseService"
        contract="DBService.IDatabaseService" name="WSHttpBinding_IDatabaseService">
        <identity>
          <dns value="dbservice" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

Server.config:

Server.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />

    <!--<roleManager defaultProvider="CustomRoleProvider" enabled="true">
      <providers>
        <clear />
        <add name="CustomRoleProvider" type="CustomRoleProvider" />
      </providers>
    </roleManager>-->
    <!--<membership defaultProvider="CustomMembershipProvider">
      <providers>
        <clear />
        <add name="CustomMembershipProvider" type="CustomMembershipProvider" />
      </providers>
    </membership>-->
  </system.web>

  <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name="sdt" type="System.Diagnostics.XmlWriterTraceListener" initializeData="SdrConfigExample.e2e" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>

  <system.serviceModel>
    <services>      
      <service name="DBService.DatabaseService" behaviorConfiguration="ServiceBehavior">
        <endpoint address="https://dbservice:3915/DatabaseService.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDatabaseService" contract="DBService.IDatabaseService">
          <identity>
            <dns value="dbservice" />
          </identity>
        </endpoint>            
      </service>      
    </services>

    <behaviors>
      <serviceBehaviors>        
        <behavior name="ServiceBehavior">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />

          <!--<serviceAuthorization principalPermissionMode="UseAspNetRoles" roleProviderName="CustomRoleProvider" />-->
          <serviceCredentials>
            <!--<userNameAuthentication userNamePasswordValidationMode="MembershipProvider" membershipProviderName="CustomMembershipProvider" />-->
            <serviceCertificate findValue="dbservice" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" />
          </serviceCredentials>
        </behavior>      
      </serviceBehaviors>
    </behaviors>

    <bindings>   
      <wsHttpBinding>
        <binding name="WSHttpBinding_IDatabaseService">
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="None" />
            <message clientCredentialType="UserName" />
          </security>     
        </binding>   
      </wsHttpBinding> 
    </bindings> 

    <protocolMapping>
      <add binding="wsHttpBinding" scheme="https" />
    </protocolMapping>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>


  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
  <connectionStrings>
    <add name="WypozyczalniaDataContext" connectionString="metadata=res://*/Wypozyczalnia.csdl|res://*/Wypozyczalnia.ssdl|res://*/Wypozyczalnia.msl;provider=System.Data.SqlServerCe.4.0;provider connection string=&quot;data source=C:\Users\Wojciech\Desktop\Wypozyczalnia\Wypozyczalnia.sdf&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

推荐答案

8小时后,终于找到了问题所在.我一直在编辑DBSerivce.config,但我忘记了,我的自托管应用程序有单独的App.config ...

After 8 hours, finally I've found the problem. I've been editing DBSerivce.config, but I've forgotten, that there is separate App.config for my self-hosting application...

请注意,否则您将损失半天时间:P.

Be aware of that or you'll lose half a day :P.

这篇关于具有wsHttpBinding,ssl和TransportWithMessageCredential的WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆