WCF应用程序托管的服务故障状态异常
本文关键字:故障 状态 异常 服务 应用程序 WCF | 更新日期: 2023-09-27 18:25:13
不知道发生了什么。简单的应用程序托管服务。在服务器A上运行良好。将所有内容复制到服务器B…但突然无法启动。
有什么建议吗?想法?我很乐意提供更多信息。谢谢你的帮助。
错误消息:
通信对象System.ServiceModel.ServiceHost不能是用于通信,因为它处于故障状态。
代码(主机OPEN()故障_
static void Main(string[] args)
{
try
{
Uri baseAddress = new Uri("http://localhost:8080/Brp");
Uri mexUri = new Uri("http://localhost:8080/Brp/mex");
// Create the ServiceHost.
using (ServiceHost host = new ServiceHost(typeof(BBService), baseAddress))
{
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetUrl = mexUri;
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
host.Description.Behaviors.Add(smb);
host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
BasicHttpBinding binding = new BasicHttpBinding();
binding.MaxReceivedMessageSize = int.MaxValue;
binding.Security.Mode = BasicHttpSecurityMode.None;
host.AddServiceEndpoint(typeof(IBService), binding, "");
// Enable metadata publishing.
var behavior = host.Description.Behaviors.Find<ServiceDebugBehavior>();
behavior.IncludeExceptionDetailInFaults = true;
host.Open();
Console.ReadLine();
// Close the ServiceHost.
host.Close();
}
} catch (Exception excep)
{
writeMessage("EXCEPTION!!! - " + excep.Message);
}
如果其他人遇到这种情况:Right-click -> Run as administrator
使用Message合约时必须遵守某些规则1.当使用消息合约类型作为参数时,在服务操作中只能使用一个参数【运营合同】void SaveEmployeeDetails(EmployesDetails emp);
2. Service operation either should return Messagecontract type or it should not return any value
【运营合同】EmployeeDetails GetEmployesDetails();
3. Service operation will accept and return only message contract type. Other data types are not allowed.
【运营合同】EmployeeDetails ModifyEmployeedDetails(EmployeeDetails emp);
注意:如果一个类型同时具有Message和Data约定,则服务操作将只接受消息约定。