2017-02-22 185 views
0

我對WCF服務非常陌生。我用basicHTTPBinding創建了一個基本的WCF服務。下面詳細的代碼片段:如何使用IP地址從瀏覽器訪問WCF服務基地址?

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> 

我在Visual Studio運行在發佈模式下此應用程序和服務託管,並正確地返回員工詳細信息。

但現在我想從同一個域中的不同機器訪問服務。每當我用「本地主機」(即http://localhost:8733/MyWCF/Service1/)輸入基地址時,它都會在瀏覽器中打開,但是無論何時我用基地址(即http://10.135.195.39:8733/MyWCF/Service1/)替換本地主機,服務都無法從瀏覽器訪問。

  • 列表項

我試圖與IP地址(即 「10.135.195.39:8733」),以改變端點的標識值 「localhost」 的。

  • 列表項目 我試圖從端點刪除標識部分。

但沒有任何工作。任何人都可以幫助我嗎?

+0

沒有防火牆不活躍 –

回答