How to access WCF service base address from browser with ip address?

I am very new to WCF services. I have created a basic WCF service with basicHTTPBinding. Below the detailed code pieces:

using MyWCF.DataModel;
using System;
using System.Collections.Generic;

namespace MyWCF
{    
    public class Service1 : IService1
    {
        public List<Employee> GetEmployee()
        {
            return new List<Employee>
            {
                new Employee{ FirstName = "Md", LastName = "Arefin", City = "Kolkata", Organisation = "TCS", Experience = 3 },
                new Employee{ FirstName = "Tuhin", LastName = "Som", City = "Kolkata", Organisation = "TCS", Experience = 9 },
                new Employee{ FirstName = "Avik", LastName = "Chattaraj", City = "Kolkata", Organisation = "TCS", Experience = 2 }
            };
        }
    }
}


using MyWCF.DataModel;
using System.Collections.Generic;
using System.ServiceModel;

namespace MyWCF
{    
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        List<Employee> GetEmployee();
    }    
}


using System.Runtime.Serialization;

namespace MyWCF.DataModel
{
    [DataContract]
    public class Employee
    {
        [DataMember]
        public string FirstName { get; set; }
        [DataMember]
        public string LastName { get; set; }
        [DataMember]
        public string City { get; set; }
        [DataMember]
        public string Organisation { get; set; }
        [DataMember]
        public int Experience { get; set; }
    }
}



<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>  
  <system.serviceModel>
    <services>
      <service name="MyWCF.Service1">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8733/MyWCF/Service1/" />
          </baseAddresses>
        </host>        
        <endpoint address="" binding="basicHttpBinding" contract="MyWCF.IService1">          
          <identity>
            <dns value="localhost"/>
          </identity>   
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>          
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>          
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>

I am running this application in release mode in visual studio and the service is hosted and returning employee details correctly.

But now I want to access the service from different machine in same domain. Whenever I am entering the base address with "localhost" (ie http://localhost:8733/MyWCF/Service1/) it is opening in the browser, but whenever I am replacing localhost with ip address(ie http://10.135.195.39:8733/MyWCF/Service1/) from the base address the service is not accessable from browser.

  • List item
  • I tried to change the identity value "localhost" in the endpoint with the ip address (ie "10.135.195.39:8733").

  • List item I tried removing the identity portion also from endpoint.
  • But nothing works. Can anyone help me please?


    Please check you enabled multiple site bindings.

    <serviceHostingEnvironment multipleSiteBindingsEnabled=”true”/>  
    

    read more https://msdn.microsoft.com/en-us/library/ee358763(v=vs.110).aspx

    链接地址: http://www.djcxy.com/p/95910.html

    上一篇: 在WebSite项目中使用grunt和bower进行HTML5开发,或者在Visual Studio 2015中创建HTML5 Web应用程序?

    下一篇: 如何使用IP地址从浏览器访问WCF服务基地址?