使用wsHttpBinding,ssl和TransportWithMessageCredential的WCF服务

时间:2013-06-01 22:55:01

标签: wcf web-services security wshttpbinding

我通过ssl通信,wsHttpBinding和Transport安全性获得了wcf服务,但当我尝试将其更改为:

      <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.

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

你能帮助我吗?

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:

<?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>

1 个答案:

答案 0 :(得分:0)

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

要注意这一点,否则你将失去半天:P。