Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 1.49 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Set wcf service credentials in config file for a service with endpoints created in code
  2. var svc = new ServiceHost( typeof (MyService), new Uri(s));
  3. svc.Authorization.PrincipalPermissionMode =
  4.                   PrincipalPermissionMode.UseWindowsGroups;
  5. svc.AddServiceEndpoint(typeof(IMyService), new WSHttpBinding("MyBinding"), "");
  6. //svc.Credentials.ServiceCertificate.SetCertificate(
  7. //    StoreLocation.LocalMachine,
  8. //    StoreName.My,
  9. //    X509FindType.FindBySubjectName,
  10. //    "mycertname"
  11. //    );
  12.        
  13. <system.serviceModel>
  14.      <services>
  15.        <service name="MyNamespace.MyService" behaviorConfiguration="MyBehavior">
  16.        </service>
  17.     </services>
  18.     <bindings>
  19.       <wsHttpBinding>
  20.         <binding name="MyBinding">
  21.           <security mode="Transport">
  22.             <transport clientCredentialType="Windows"/>
  23.           </security>
  24.           <!-- Or for message level security
  25.           <security mode="Message">
  26.             <message clientCredentialType="Certificate"/>
  27.           </security>
  28.           -->
  29.         </binding>
  30.       </wsHttpBinding>
  31.     </bindings>
  32.   </system.serviceModel>
  33.        
  34. <behaviors>
  35.       <serviceBehaviors>
  36.         <behavior>
  37.           <serviceCredentials>
  38.             <serviceCertificate findValue="mycertname"
  39.                                 x509FindType="FindBySubjectName"
  40.                                 storeLocation="LocalMachine"
  41.                                 storeName="My"/>
  42.           </serviceCredentials>
  43.         </behavior>
  44.       </serviceBehaviors>
  45. </behaviors>