2011-05-22 92 views
5

我正在開發一個帶有basicHttpBinding的自定義UserNamePasswordValidator WCF服務。但是,此配置僅適用於HTTPS綁定。由於Visual Studio 2010內置的Web服務器不支持https,我如何測試自定義驗證器?我不斷收到Could not find a base address that matches scheme https for the endpoint with binding BasicHttpBinding. Registered base address schemes are [http].錯誤,如果我將clientCredentialType設置爲none,則錯誤消失,但驗證程序不會被調用。
下面是我的配置。如何使用VS2010內置web服務器中的TransportWithMessageCredential測試WCF服務

<?xml version="1.0"?> 
<configuration> 
    <system.serviceModel> 
    <extensions> 
     <behaviorExtensions> 
     <add name="ServiceErrorHandler" type="company.application.appserver.implementation.ServiceErrorHandlerBehaviorExtensionElement, AppSoftAppServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> 
     </behaviorExtensions> 
    </extensions> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="SimpleBinding"> 
      <security mode="TransportWithMessageCredential"> 
      <message clientCredentialType="UserName"/> 
      </security> 
     </binding> 
     </basicHttpBinding> 
    </bindings> 
    <services> 
     <service behaviorConfiguration="DefaultBehavior" name="company.application.appserver.implementation.AppSoftUpdate"> 
     <endpoint address="udt" binding="basicHttpBinding" bindingConfiguration="SimpleBinding" 
      name="AppSoftUpdate" bindingNamespace="http://company.application/update/2011/04" 
      contract="company.application.appserver.interfaces.IAppSoftUpdate" /> 
     <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" 
      name="AppSoftUpdateMex" bindingNamespace="http://company.application/update/2011/04" 
      contract="IMetadataExchange" /> 
     </service> 
     <service behaviorConfiguration="DefaultBehavior" name="company.application.appserver.implementation.AppSoftTransaction"> 
     <endpoint address="udt" binding="basicHttpBinding" bindingConfiguration="SimpleBinding" 
      name="AppSoftTransacao" bindingNamespace="http://company.application/transaction/2011/04" 
      contract="company.application.appserver.interfaces.IAppSoftTransacao" /> 
     <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" 
      name="AppSoftTransacaoMex" bindingNamespace="http://company.application/transaction/2011/04" 
      contract="IMetadataExchange" /> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="DefaultBehavior"> 
      <serviceMetadata httpGetEnabled="true" httpGetBinding="webHttpBinding" 
      httpGetBindingConfiguration="" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <ServiceErrorHandler /> 
      <serviceCredentials> 
      <userNameAuthentication userNamePasswordValidationMode="Custom" 
       customUserNamePasswordValidatorType=" company.application.appserver.implementation.AppSoftValidacaoLogin, AppSoftAppServer" /> 
      </serviceCredentials> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
</configuration> 

回答

4

使用IIS進行此測試。

打開您的項目屬性,轉到Web選項卡,點擊Use local IIS單選按鈕。本手冊適用於VS2010太:Using Visual Studio 2008 with IIS 7

如果尚未安裝IIS,先安裝:How to install IIS.

你需要有比Windows高首頁Windows版本。

您還需要爲您的網站創建一個自簽名證書。這在IIS 7中很容易實現:Self-Signed Certificates on IIS 7 – the Easy Way and the Most Effective Way

+0

Tks爲答案!得到它的工作 – Pascal 2011-05-22 19:34:21

3

您無法在Cassine(VS 2010中的內置Web服務器)中測試此類WCF服務。您必須使用本地IIS或安裝VS 2010 SP1和download IIS Express,這是用於開發的輕量級Web服務器(can replace Cassini in VS並支持帶有自簽名證書的HTTPS)。 IIS Express不需要任何特定的Windows版本,它可以在Windows XP以後的所有版本上運行,但它提供了與IIS 7.5相同的功能。

+0

Tks for aswer。 @亞歷克斯的情況更爲詳細,所以我將他標記爲答案,但你的幫助也很大,所以我給每個人投了1票。 – Pascal 2011-05-22 19:35:33