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

时间:2014-10-02 01:09:26

标签: c# .net wcf service console-application

不知道发生了什么。简单应用托管服务。在服务器A上运行良好。将所有内容复制到服务器B ......然后突然无法启动。

任何提示?想法?我很乐意提供更多信息。谢谢你的帮助。

错误讯息:

  

通信对象System.ServiceModel.ServiceHost不能   用于通信,因为它处于Faulted状态。

代码(在主页上失败()_

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);
            }

2 个答案:

答案 0 :(得分:2)

如果遇到其他人,请执行以下操作:Right-click -> Run as administrator

答案 1 :(得分:0)

使用消息合约时,您必须遵循某些规则     1.使用Message contract type作为参数时,servicie Operation中只能使用一个参数 [OperationContract的] void SaveEmployeeDetails(EmployeeDetails emp);

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

[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);

注意:如果类型同时具有消息和数据合同,则服务操作将仅接受消息合同。