【问题标题】:WCF Application hosted service Faulted State exception?WCF 应用程序托管服务故障状态异常?
【发布时间】:2014-10-02 01:09:25
【问题描述】:

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

有什么建议吗?想法?我很乐意提供更多信息。感谢您的帮助。

错误信息:

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

代码(失败在 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);
            }

【问题讨论】:

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


    【解决方案1】:

    如果其他人遇到这种情况,请执行以下操作:Right-click -&gt; Run as administrator

    【讨论】:

    • 我认为从您收到的正确的钱错误消息中很明显:)
    【解决方案2】:

    在使用消息合约时,您必须遵守某些规则 1.使用消息合约类型作为参数时,服务操作只能使用一个参数 [运营合同] void SaveEmployeeDetails(EmployeeDetails emp);

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

    [操作合同] 员工详细信息 GetEmployeeDetails();

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

    [操作合同] EmployeeDetails ModifyEmployeeDetails(EmployeeDetails emp);

    注意:如果一个类型同时具有消息和数据契约,服务操作将只接受消息契约。

    【讨论】:

      猜你喜欢
      • 2014-09-22
      • 1970-01-01
      • 2011-04-02
      • 1970-01-01
      • 2012-01-28
      • 2014-06-27
      • 1970-01-01
      • 2016-08-05
      • 2020-11-02
      相关资源
      最近更新 更多