与Hosted网站通信时收到MessageSecurityException:WCF

时间:2015-04-18 11:56:03

标签: sql asp.net wcf

我正在以下方案中处理WCF “使用SQL成员资格提供程序和SQL角色提供程序对用户进行身份验证和授权” 主持人:Asp.NET网站 客户:控制台应用程序。

我通过HTTPS通信(在我的本地)使用WsHttpBinding,

I am getting following exception while communicating 
Unhandled Exception:    
========================================================

System.ServiceModel.Security.MessageSecurityException:你     从另一方收到了不安全或不正确的安全故障。见      内部FaultException为故障代码和细节。 ---> System.ServiceModel.Fa     ultException:无法验证消息中至少有一个安全令牌。

   --- End of inner exception stack trace ---

Server stack trace:
   at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChann
el.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState
, TimeSpan timeout)
   at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChann
el.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperat
ion(SecuritySessionOperation operation, EndpointAddress target, Uri via, Securit
yToken currentToken, TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetToken
Core(TimeSpan timeout)
   at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan tim
eout)
   at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecurit
ySessionChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceMod
el.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeo
ut)
   at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeS
pan timeout, CallOnceManager cascade)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean on
eway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan tim
eout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCall
Message methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
   at ProductsClient.ProductsService.IProductsService.ListProducts()
   at ProductsClient.ProductsService.ProductsServiceClient.ListProducts() in D:\
Visual Studio\WCF\PracticeInNotes\51Web_HttpHost_SQLAuth_SQLAutr_TrSec\Web_HttpH
st_SQLAuth_SQLAutr_TrSec\ProductsClient\ProductsService.cs:line 285
   at ProductsClient.Program.Main(String[] args) in D:\Visual Studio\WCF\Practic
eInNotes\51Web_HttpHost_SQLAuth_SQLAutr_TrSec\Web_HttpHst_SQLAuth_SQLAutr_TrSec\
ProductsClient\Program.cs:line 45
Press any key to continue . . .






Here is Web.Config of Host Web Site
===================================
  <?xml version="1.0" encoding="UTF-8"?>
       <configuration>
  <configSections>
   <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral,   PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>
  <dataConfiguration defaultDatabase="AdventureWorksConnection" />
  <connectionStrings>
    <add name="AdventureWorksConnection" connectionString="Data Source=WIN764\SQL2008;Initial Catalog=AdventureWorks2008;User ID=sa;Password=123" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="ProductsServiceWSHttpBindingConfig">
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="None" />
            <message clientCredentialType="UserName" />          
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="ProductsBehavior" name="ProductsService.ProductsServiceImpl">
        <endpoint address="https://localhost/InternetProductsService/ProductsService.svc" binding="wsHttpBinding" 
                  bindingConfiguration="ProductsServiceWSHttpBindingConfig" name="ProductsServiceWSHttpEndpoint" 
                  contract="ProductsService.IProductsService" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ProductsBehavior">
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceAuthorization principalPermissionMode="UseAspNetRoles"
            roleProviderName="AdventureWorksSqlRoleProvider" />
          <serviceCredentials>           
            <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
              membershipProviderName="AdventureWorksSqlProvider" />

          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <diagnostics wmiProviderEnabled="true">
            <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="3000" >
                <filters>
                    <clear/>
                </filters>

            </messageLogging>
    </diagnostics>
  </system.serviceModel>
  <system.web>
    <compilation>
      <assemblies>
        <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>
    </compilation>


  <authentication mode="Forms" />
  <membership defaultProvider="AdventureWorksSqlProvider">
          <providers>
              <clear />
              <add name="AdventureWorksSqlProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="AdventureWorksConnection" applicationName="InternetProductsService " />
      </providers>
  </membership>


  <roleManager enabled="true" defaultProvider="AdventureWorksSqlRoleProvider">
          <providers>
              <clear />
              <add name="AdventureWorksSqlRoleProvider" connectionStringName="AdventureWorksConnection" applicationName="InternetProductsService " type="System.Web.Security.SqlRoleProvider" />
          </providers>
  </roleManager>
  </system.web>
</configuration>




Here is App.Config of Client Application
========================================
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings> 
   <wsHttpBinding>
    <binding name="ProductsClientWSHttpBindingConfig">
     <security mode="TransportWithMessageCredential">
         <transport clientCredentialType="None" />
         <message clientCredentialType="UserName" />
     </security>
    </binding>
   </wsHttpBinding>
  </bindings>
        <client>   
            <endpoint address="https://localhost/InternetProductsService/ProductsService.svc" 
                      binding="wsHttpBinding"
                      bindingConfiguration="ProductsClientWSHttpBindingConfig" 
                      contract="ProductsClient.ProductsService.IProductsService"
                      name="WSHttpBinding_IProductsService" />
      </client>
    </system.serviceModel>  

0 个答案:

没有答案