Search code examples
c#wcfazureazure-configuration

Calling WCF service from Azure ServiceConfig


I added WCF Servicereference to my webapplication ,the following entries got created to my web.config .

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_INameVerification" 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="65536" 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="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="https://int. NameVerification.com/Default/NameVerificationService.svc"
    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_INameVerification"
    contract="NameVerificationService.INameVerification"
    name="WSHttpBinding_INameVerification" />
</client>

Now I am planning to host my application to Azure cloud platform. Once I host my app on cloud I want to be able to change my endpoints at any time ie.,

<endpoint address=”https://int. NameVerification.com/Default/NameVerificationService.svc” 
   binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_INameVerification"
    contract="NameVerificationService.INameVerification"
    name="WSHttpBinding_INameVerification" />

How do I add this call to my WCF service from SericeConfig ?What is the actual entriess in ServiceConfig so that my application will read my WCF end point address from Service config and not from web.config


Solution

  • Thank you all for your help .

    I found a solution for this problem.

    1. Associated binding and serviceaddress in program, then added settings to Serviceconfig
    2. ServiceConfig entry Added
    <Setting name="myServiceAddressUrl"
        value="https://int.
        NameVerification.com/Default/NameVerificationService.svc" />
    
        WSHttpBinding binding = new WSHttpBinding();
        binding.Name = "WSHttpBinding_INameServiceVerification";
        binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
        binding.ReliableSession.Enabled = false;
        binding.TransactionFlow = false;
        binding.Security.Mode = SecurityMode.Transport;
        binding.Security.Message.ClientCredentialType = 
            MessageCredentialType.Windows;
    
        string myServiceAddressUrl = 
            RoleEnvironmentWrapper.GetConfigurationSettingValue(
               "AdderssServiceURL.svc");
        EndpointAddress myService = new EndpointAddress(myServiceAddressUrl);
    
        NameVerificationClient verificationClient = 
            new NameVerificationClient(binding, myService );