Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF启动:未能添加服务_C#_Wcf_Service - Fatal编程技术网

C# WCF启动:未能添加服务

C# WCF启动:未能添加服务,c#,wcf,service,C#,Wcf,Service,我的WCF有问题。我的服务合同界面是: namespace A.B.C { [ServiceContract] public interface IWSpExporter { [OperationContract] int ExportFile(); [OperationContract] int ExportMetaData(); [OperationContract]

我的WCF有问题。我的服务合同界面是:

namespace A.B.C
{
    [ServiceContract]
    public interface IWSpExporter
    {
        [OperationContract]
        int ExportFile();

        [OperationContract]
        int ExportMetaData();

        [OperationContract]
        int ExportAll();
    }
}
当然,我有一门课:

namespace A.B.C
{
    class WSpExporter : IWSpExporter
    {

        public int ExportFile() 
        {
            return 0;
        }

        public int ExportMetaData()
        {
            return 0;
        }

        public int ExportAll()
        {
            return 0;
        }
    }
}
我的App.config是:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>

      <service name="A.B.C.WSpExporter"
               behaviorConfiguration="WSpExporterBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8000/WSpExporter/service"/>
          </baseAddresses>
        </host>

        <!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/WSpExporter/service-->
        <endpoint address=""
                  binding="wsHttpBinding"
                  contract="A.B.C.IWSpExporter">
          <identity>
            <servicePrincipalName value="host/localhost"/>
          </identity>
        </endpoint>

        <!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/WSpExporter/service/mex -->
        <endpoint address="mex" 
                  binding="mexHttpBinding" 
                  contract="IMetadataExchange" />

      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="WSpExporterBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>
我发现了我的错误:

方法:

protected override void OnStart(string[] args)
{

    if (serviceHost != null)
    {
        serviceHost.Close();
    }

    serviceHost = new ServiceHost(typeof(PExporter)); // ERROR HERE

    serviceHost.Open();
}
启动一个错误的类。。。更正:

protected override void OnStart(string[] args)
{

    if (serviceHost != null)
    {
        serviceHost.Close();
    }

    serviceHost = new ServiceHost(typeof(WSpExporter)); //GOOD NOW

    serviceHost.Open();
}

您的类
PExporter
似乎不是
public
,或者您只是没有粘贴它?最终,您需要将调试器附加到正在运行的服务进程,以检查变量和异常,但也可以添加日志记录。ServiceHost实际启动了吗?它的终点是什么?你觉得你的服务怎么样?
netstat-ab
告诉你什么,它在听吗?您是否有防火墙阻止本地主机连接?
protected override void OnStart(string[] args)
{

    if (serviceHost != null)
    {
        serviceHost.Close();
    }

    serviceHost = new ServiceHost(typeof(WSpExporter)); //GOOD NOW

    serviceHost.Open();
}