Ask a questionAsk a question
 

QuestionReplace the Localhost with IP address

  • Thursday, September 17, 2009 6:36 AMSamG301 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello,
    Please help me on this issue,

    I have created a WCF server and trying to use this in C# asp .net website available on same machine.

    However in SCF service we.config It has default endpoint address with 'localhost'. I just want to replace this with IP address of machine so that client app from diff machine can also call this service.

    Here is my Webservice config file..

    ------------------------------------------------------

        <system.serviceModel>
       
       
       
            <services>
       <service behaviorConfiguration="PriceServer.Service1Behavior"
        name="PriceServer.PriceService">
        <endpoint address="http://localhost:50161/PriceService.svc" behaviorConfiguration=""
         binding="mexHttpBinding" bindingConfiguration="" contract="PriceServer.IPriceService">
         <identity>
          <dns value="localhost" />
         </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
         contract="IMetadataExchange" />
       </service>
      </services>
            <behaviors>
         
                <serviceBehaviors>
         
                    <behavior name="PriceServer.Service1Behavior">
                        <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                        <serviceMetadata httpGetEnabled="true"/>
                        <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                        <serviceDebug includeExceptionDetailInFaults="false"/>
             
            
                    </behavior>
                </serviceBehaviors>
         
         
          <!-- Adding to enable the calling from client side-->

          <endpointBehaviors>
            <behavior name="ServiceAspNetAjaxBehavior">
              <enableWebScript/>
            </behavior>
          </endpointBehaviors>
        </behaviors>

        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        <!-- Adding to enable the calling from client side-->

      <!--  </behaviors>-->
       
        </system.serviceModel>

    thanks

All Replies

  • Tuesday, September 22, 2009 7:10 PMGregory Leake Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    This seems like a question not related to Config Services itself; but rather a generic WCF question. 

    Using localhost should typically allow remote clients to connect up over a specific IP address or DNS name; as this really is telling the services to listen on all IP's on the machine; I do believe.  However, this can become an issue if endpoint identities are used, such as with message level encryption; where certs expect incoming requests to match a specific DNS name, etc.  But assumig this is not the issue, yet you want to restrict the service to listen on a specific IP address:

    1) Assuming you know the IP (it is static vs. DHCP defined); you can simply put this IP address in your endpoint definition instead of localhost.

    2)  You must also create a binding configuration, and in this binding configuration set the property for HostNameComparison to Exact vs. StrongWildCard.


    Finally, Config Services takes care of much of this for you; typically creating endpoints on the DNS host name, meaning listening on every IP address on that host.  It provides a mechanism in config, to override on a per-endpoint basis, with the use of a specific IP address (or alternate hostheader name in IIS, if desired); but you still have to use binding configs with HostNameComparison set to Exact for those endpoints you want to constrict to a single IP address; see page 32 of the Config Service Technical Guide.

    -Greg
    Greg Leake, Microsoft