smagi smagi

smagi smagi

  • NA
  • 56
  • 923

Wcf redirect and configuration

Mar 22 2017 8:29 AM

Hi,

I have application connected to 2 databases by 2 services (1) and I must to redirect this to server 0 like at (2):
 When I stariting app I have combobox to select server: Prod or Test.
  1. public enum Access  
  2. {  
  3.   Test,  
  4.   ProdL,  
  5. }          
  6.   
  7.   
  8. private static Access _serviceAccess = Access.Prod;  
  9. private static ServiceClient service;  
  10.   
  11. private static void SetServiceAccess(Access access)  
  12. {  
  13.   switch (_serviceAccess )  
  14.   {  
  15.     case Access .Prod: service= new ServiceClient("WSHttpBinding_IService.Prod");  
  16.      break;  
  17.     case Access .Test: service = new ServiceClient("WSHttpBinding_IService.Test");  
  18.      break;        
  19.    }  
  20.   
  21. }  
 
  1. --app.config  
  2.   
  3. <?xml version="1.0" encoding="utf-8" ?>  
  4. <configuration>  
  5.   <system.web>  
  6.     <compilation debug="true"/>  
  7.   </system.web>  
  8.   <system.serviceModel>  
  9.     <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />  
  10.     <bindings>  
  11.       <wsHttpBinding>  
  12.         <binding name="WSHttpBinding_IService.Prod"  
  13.           closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00"  
  14.           sendTimeout="00:10:00" bypassProxyOnLocal="false" transactionFlow="false"  
  15.           hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="52042880"  
  16.           maxReceivedMessageSize="2147483647" messageEncoding="Mtom" textEncoding="utf-8"  
  17.           useDefaultWebProxy="true" allowCookies="false">  
  18.           <readerQuotas maxDepth="62" maxStringContentLength="80000192"  
  19.             maxArrayLength="666116384" maxBytesPerRead="40000096" maxNameTableCharCount="160000384" />  
  20.           <reliableSession ordered="true" inactivityTimeout="00:10:00"  
  21.             enabled="false" />  
  22.           <security mode="None" />  
  23.         </binding>  
  24.         <binding name="WSHttpBinding_IService.Test" closeTimeout="00:03:00"  
  25.           openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"  
  26.           bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"  
  27.           maxBufferPoolSize="52042880" maxReceivedMessageSize="2147483647"  
  28.           messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true"  
  29.           allowCookies="false">  
  30.           <readerQuotas maxDepth="62" maxStringContentLength="80000192"  
  31.             maxArrayLength="666116384" maxBytesPerRead="40000096" maxNameTableCharCount="160000384" />  
  32.           <reliableSession ordered="true" inactivityTimeout="00:10:00"  
  33.             enabled="false" />  
  34.           <security mode="None" />  
  35.         </binding>  
  36.       </wsHttpBinding>  
  37.     </bindings>    
  38.     <client>  
  39.       <endpoint address="http://ProdAddress/Service.svc"  
  40.         binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService.Prod"  
  41.         contract="Service.IService" name="WSHttpBinding_IService.Prod">  
  42.         <identity>  
  43.           <dns value="localhost" />  
  44.         </identity>  
  45.       </endpoint>  
  46.       <endpoint address="http://TestAddress/Service.svc"  
  47.         binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService.Test"  
  48.         contract="Service.IService" name="WSHttpBinding_IService.Test">  
  49.         <identity>  
  50.           <dns value="localhost" />  
  51.         </identity>  
  52.       </endpoint>  
  53.     </client>  
  54.   </system.serviceModel>  
  55.   <startup>  
  56.     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>  
  57.   </startup>  
  58. </configuration>  
  59.   
  60.   
  61. -- web.config 1 and web.config 2 (the same configuration but different connection strings)  
  62.   
  63. <?xml version="1.0"?>  
  64. <configuration>  
  65.   <appSettings>  
  66.     <add key="DbConnStr" .../>  
  67.     <add key="ManagementConnStr" ... />  
  68.   </appSettings>  
  69.     <system.serviceModel>  
  70.       <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" />   
  71.       <services>  
  72.            <service name="ServiceName" behaviorConfiguration="ServiceBehaviour">    
  73.         <endpoint address="" binding="wsHttpBinding" bindingConfiguration="WsHttpBinding" contract="Service.IService">  
  74.          <identity>  
  75.           <dns value="localhost"/>  
  76.          </identity>  
  77.         </endpoint>  
  78.         <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>  
  79.        </service>  
  80.       </services>  
  81.     <behaviors>  
  82.      <serviceBehaviors>  
  83.       <behavior name="ServiceBehaviour">  
  84.        <serviceMetadata httpGetEnabled="true"/>  
  85.        <serviceDebug includeExceptionDetailInFaults="true"/>  
  86.       </behavior>  
  87.      </serviceBehaviors>  
  88.     </behaviors>  
  89.     <bindings>  
  90.       <wsHttpBinding>  
  91.        <binding name="WsHttpBinding" messageEncoding="Mtom" maxReceivedMessageSize="500000000">  
  92.          <security mode="None">  
  93.             <transport clientCredentialType="None" />  
  94.              </security>  
  95.        </binding>  
  96.       </wsHttpBinding>  
  97.         </bindings>  
  98.     </system.serviceModel>  
  99. </configuration>  
 

I don't know If I must change only service reference to service 0? or add client endpoints to service 0?

How to check If I'am connected via server 0 or directly to server 1,2?

Sorry for my inaccuracy I'm new in WCF.