c# - wcf service with a custom username a password authentication -


i trying access wcf service custom username , password validator.. in case have win console app running in .net 2.0 , wcf service running in .net 4.0 after adding web reference service, can call method , print result in console.

now want add security.. kind new authentication process of web/wcf services.. in first project made , using soap headers, in case both running in .net 4.0.

i did find there ways of doing it, beginner want understand basic way, , in case sending username , passoword , seems easy way it.. in order need create new class extends usernamepasswordvalidator , override method validate

 public override void validate(string username, string password)         {             if (username != "teste")                 throw new securitytokenexception("unknown username or password");          } 

the problem having configure web config file of webservie use custom validator..

this web.config

    <?xml version="1.0"?> <configuration>    <system.web>     <compilation debug="true" targetframework="4.0" />   </system.web>   <system.servicemodel>     <bindings>       <basichttpbinding>         <binding name="securehtpps">           <security mode="transportwithmessagecredential">             <message clientcredentialtype="username"/>           </security>         </binding>       </basichttpbinding>     </bindings>     <behaviors>       <servicebehaviors>          <behavior>           <servicecredentials>             <usernameauthentication usernamepasswordvalidationmode="custom"           customusernamepasswordvalidatortype="services.customusernamepasswordvalidator, services" />           </servicecredentials>           <!-- avoid disclosing metadata information, set value below false before deployment -->           <servicemetadata httpgetenabled="true"/>           <!-- receive exception details in faults debugging purposes, set value below true.  set false before deployment avoid disclosing exception information -->           <servicedebug includeexceptiondetailinfaults="false"/>         </behavior>       </servicebehaviors>     </behaviors>      <servicehostingenvironment multiplesitebindingsenabled="true" />   </system.servicemodel>   <system.webserver>     <modules runallmanagedmodulesforallrequests="true"/>     <!--         browse web app root directory during debugging, set value below true.         set false before deployment avoid disclosing web app folder information.       -->     <directorybrowse enabled="true"/>   </system.webserver>  </configuration> 

after should able call service in console this

        localhost.service1 client = new consoleapplication1.localhost.service1();         client.clientcredentials.username.username = "yaron";         client.clientcredentials.username.password = "1234"; 

but in case giving me error on clientcredentials, missing reference.. reference available on .net 3.0 , above...

the idea send username , password validate username, after call method...

how can it..

i have been around problems , didnt manage working...

so need use basichttpbinding because of differences of framework use on console app , on service...

i need configure iis use https...and did follow example: http://msdn.microsoft.com/en-us/library/hh556232.aspx

i follow page creating service example.. http://www.brhlavinka.com/2013/06/07/secure-wcf-service-with-basichttpbinding-and-custom-credentials/

this web.config file

<?xml version="1.0"?> <configuration>    <system.web>     <compilation debug="true" targetframework="4.0" />   </system.web>   <system.servicemodel>     <services>       <service name="wcfservice1.service1"               behaviorconfiguration="brett_behavior">         <endpoint address=""                   binding="basichttpbinding"                   bindingconfiguration="brett_bindingconfiguration"                   contract="wcfservice1.iservice1" />         <endpoint address="mex"                   binding="mexhttpsbinding"                   contract="imetadataexchange" />       </service>     </services>     <bindings>       <basichttpbinding>         <binding name="brett_bindingconfiguration">           <security mode="transportwithmessagecredential">             <message clientcredentialtype="username" />           </security>         </binding>       </basichttpbinding>     </bindings>     <behaviors>       <servicebehaviors>         <behavior name="brett_behavior">           <servicemetadata httpsgetenabled="true" />           <servicedebug includeexceptiondetailinfaults="true"/>           <servicecredentials>             <usernameauthentication usernamepasswordvalidationmode="custom"                                     customusernamepasswordvalidatortype="wcfservice1.auth, wcfservice1"/>           </servicecredentials>         </behavior>       </servicebehaviors>     </behaviors>     <servicehostingenvironment multiplesitebindingsenabled="true" />   </system.servicemodel>  <system.webserver>     <modules runallmanagedmodulesforallrequests="true"/>     <!--         browse web app root directory during debugging, set value below true.         set false before deployment avoid disclosing web app folder information.       -->     <directorybrowse enabled="true"/>   </system.webserver>  </configuration> 

when select service1.svc , try view in browser give me error:

unable find matching scheme https base address endpoint binding basichttpbinding. registered base address schemes [http].

what need do?


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -