我已经在http端口上以worker角色托管了wcf服务,并且我在代码中给出了onStart方法的端口
public override bool OnStart()
{
try
{
ServicePointManager.DefaultConnectionLimit = 12;
CreateServiceHost();
return base.OnStart();
}
catch (Exception)
{
return true;
}
// Set the maximum number of concurrent connections
}
private ServiceHost serviceHost;
private void CreateServiceHost()
{
//serviceHost = new ServiceHost(typeof(Service));
//WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.None);
//RoleInstanceEndpoint externalEndPoint =
// RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["ServiceEP"];
//string endpoint = String.Format("http://{0}/Service",
// externalEndPoint.IPEndpoint);
//serviceHost.AddServiceEndpoint(typeof(IService), binding, endpoint);
//serviceHost.Open();
var endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["ServiceEP"];
var ub = new UriBuilder();
ub.Host = endpoint.IPEndpoint.Address.ToString();
ub.Port = endpoint.IPEndpoint.Port;
ub.Scheme = "http";
ub.Path = "Service";
var host = new ServiceHost(typeof(Service), ub.Uri);
host.AddDefaultEndpoints();
host.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = true });
foreach (var e in host.Description.Endpoints)
{
((BasicHttpBinding)e.Binding).HostNameComparisonMode = HostNameComparisonMode.Exact;
}
host.Open();
//Trace.WriteLine("WCF Hello service running...");
}
当我尝试访问服务中定义的方法时,我得到了以下错误
远程服务器返回错误:(400)错误请求。