简体   繁体   English

WCF应用程序托管服务故障状态异常?

[英]WCF Application hosted service Faulted State exception?

No idea what's going on. 不知道发生了什么。 Simple application hosted service. 简单的应用程序托管服务。 Ran fine on server A. Copied everything over to server B...and suddenly won't launch. 在服务器A上运行良好。将所有内容复制到服务器B ...然后突然无法启动。

Any tips? 有小费吗? Ideas? 有想法吗? I'll happily provide more info. 我会很乐意提供更多信息。 Thanks for any help. 谢谢你的帮助。

Error message: 错误信息:

The communication object, System.ServiceModel.ServiceHost, cannot be used for communication because it is in the Faulted state. 通信对象System.ServiceModel.ServiceHost不能用于通信,因为它处于故障状态。

Code (FAILS AT HOST.OPEN()_ 代码(在HOST.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

You have to follow certain rules while working with Message contract 1. When using Message contract type as parameter, Only one parameter can be used in servicie Operation [OperationContract] void SaveEmployeeDetails(EmployeeDetails emp); 使用消息协定1时,必须遵循某些规则。当使用消息协定类型作为参数时,服务操作中只能使用一个参数。[OperationContract] void SaveEmployeeDetails(EmployeeDetails emp);

2. Service operation either should return Messagecontract type or it should not return any value

[OperationContract] EmployeeDetails GetEmployeeDetails(); [OperationContract] EmployeeDetails GetEmployeeDetails();

3. Service operation will accept and return only message contract type. Other data types are not allowed.

[OperationContract] EmployeeDetails ModifyEmployeeDetails(EmployeeDetails emp); [OperationContract] EmployeeDetails ModifyEmployeeDetails(EmployeeDetails emp);

Note: If a type has both Message and Data contract, service operation will accept only message contract. 注意:如果类型同时具有消息合同和数据合同,则服务操作将仅接受消息合同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM