2011-10-05 41 views
4

我试图创建一个基本身份验证的wcf服务,但我遇到了一些麻烦。使用传输的WCF服务clientCredentialType Basic

这里就是我对服务的web.config看起来像:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <client /> 
     <services> 
      <service name="Service.DataExchangeService" behaviorConfiguration="MyBehavior"> 
       <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsDataImportEndpoint" contract="Service.IDataExchangeService"> 
        <identity> 
         <dns value="localhost" /> 
        </identity> 
       </endpoint> 
       <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> 
       <host> 
        <baseAddresses> 
         <add baseAddress="http://localhost:8732/Design_Time_Addresses/DataExchange.Server.Service/Service1/" /> 
        </baseAddresses> 
       </host> 
      </service> 
     </services> 
     <bindings> 
      <wsHttpBinding> 
       <binding name="wsDataImportEndpoint" maxBufferPoolSize="2147483647" 
        maxReceivedMessageSize="2147483647"> 
        <readerQuotas maxDepth="32" maxStringContentLength="2147483647" 
         maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <security mode="Transport"> 
         <transport clientCredentialType="Basic"/> 
         <message clientCredentialType="UserName" negotiateServiceCredential="true" /> 
        </security> 
       </binding> 
      </wsHttpBinding> 
     </bindings> 
     <behaviors> 
      <serviceBehaviors> 
       <behavior name="MyBehavior"> 
        <serviceMetadata httpsGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="true" /> 
        <serviceCredentials> 
         <userNameAuthentication customUserNamePasswordValidatorType="DataExchange.Server.Service.UserNameValidator, DataExchange.Server.Service" 
               userNamePasswordValidationMode="Custom" /> 
        </serviceCredentials> 
       </behavior> 
       <behavior name=""> 
        <serviceMetadata httpGetEnabled="true" /> 
        <serviceDebug includeExceptionDetailInFaults="false" /> 
       </behavior> 
      </serviceBehaviors> 
     </behaviors> 
    </system.serviceModel> 
    <connectionStrings> 
     <add name="ApplicationServices" connectionString="data source=sharept07\mssqlserver2008;initial catalog=VOS.Membership;integrated security=True;" providerName="System.Data.SqlClient" /> 
     <add name="ROSEntities" connectionString="metadata=res://*/ROSModel.csdl|res://*/ROSModel.ssdl|res://*/ROSModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=sharept07\MSSQLServer2008;initial catalog=VOS;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
</configuration> 

,这里是我的客户端配置文件是什么样子:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <wsHttpBinding> 
       <binding name="WSHttpBinding_IDataExchangeService" closeTimeout="00:01:00" 
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
        bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
        maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" 
        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" 
        allowCookies="false"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <reliableSession ordered="true" inactivityTimeout="00:10:00" 
         enabled="false" /> 
        <security mode="Transport"> 
         <transport clientCredentialType="Basic" proxyCredentialType="None" 
          realm="" /> 
         <message clientCredentialType="UserName" negotiateServiceCredential="true" /> 
        </security> 
       </binding> 
      </wsHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="https://server.com:446/DataExchangeService/DataExchangeService.svc" 
       binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDataExchangeService" 
       contract="DataExchangeSvc.IDataExchangeService" name="WSHttpBinding_IDataExchangeService"> 
       <identity> 
        <dns value="localhost" /> 
       </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
</configuration> 

,在这里我怎么我中调用该服务的我的客户端:

static void Main(string[] args) 
    { 
     using (var client = new DataExchangeSvc.DataExchangeServiceClient()) 
     { 
      client.ClientCredentials.UserName.UserName = "test"; 
      client.ClientCredentials.UserName.Password = "test"; 
      var data = client.RetrieveData(); 
     } 
    } 

当我在Serv中的安全节点中将传输模式设置为“无”冰配置文件中的上述作品完美,如果我忽略凭证线,但现在我将其更改为基本我不断收到此错误:

There was no endpoint listening at https://server.com:446/DataExchangeService/DataExchangeService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. 

我真的不知道发生了什么事情,所以如果任何人都可以引导我以任何方式,这将是非常有益的。

感谢

回答

9

我觉得你真的想要的这里是用TransportWithMessageCredential,而不只是Transport。只需使用<security mode="Transport">即可让您的服务通过HTTPS,但与使用凭据进行身份验证无关。如果您使用<security mode="TransportWithMessageCredential">,则可以使用HTTPS并使用用户名和密码。 Here是关于此的MSDN文章。

编辑

如果你真的只是想用Transport,拿出您的服务配置的<message>节点。

+0

谢谢!!!你是一种生活品味! – zSynopsis

相关问题