Using WCF on Localhost on Azure

后端 未结 2 890
悲哀的现实
悲哀的现实 2021-02-09 02:01

In summary
How do I acces a WCF service on localhost when hosted in IIS on Azure? Azure does not bind localhost or 127.0.0.1 to my website.

2条回答
  •  情歌与酒
    2021-02-09 02:22

    You have to build the endpoint address dynamically.

    Step 1: In your ServiceDefinition.csdef you need to declare an Endpoint.

    
      
        
          
            
              
            
          
        
        
          
        
        
          
        
      
    
    

    Step 2: When you want to call the service

    var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["WorkflowService"].IPEndpoint;
    var uri = new Uri(string.Format(
        "http://{0}:{1}/MyService.xamlx",
        endpoint.Address,
        endpoint.Port));
    var proxy = new ServiceClient(
        new BasicHttpBinding(),
        new EndpointAddress(uri));
    

提交回复
热议问题