如何使用IP地址从浏览器访问WCF服务基地址?
我对WCF服务非常陌生。 我用basicHTTPBinding创建了一个基本的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中以发布模式运行此应用程序,并且托管服务并正确返回员工详细信息。
但是现在我想从同一个域中的不同机器访问服务。 每当我使用“localhost”(即http:// localhost:8733 / MyWCF / Service1 /)输入基地址时,它会在浏览器中打开,但每当我用ip地址替换localhost时(即http://10.135。 195.39:8733 / MyWCF / Service1 /)从服务无法从浏览器访问的基地址。
我试图用IP地址(即“10.135.195.39:8733”)更改端点中的身份值“localhost”。
但没有任何工作。 任何人都可以帮助我吗?
请检查您是否启用了多个站点绑定。
<serviceHostingEnvironment multipleSiteBindingsEnabled=”true”/>
阅读更多https://msdn.microsoft.com/zh-cn/library/ee358763(v=vs.110).aspx
链接地址: http://www.djcxy.com/p/95909.html上一篇: How to access WCF service base address from browser with ip address?