C# 在Windows服务中部署托管WCF服务时出现问题

C# 在Windows服务中部署托管WCF服务时出现问题,c#,.net,wcf,service,C#,.net,Wcf,Service,我有一个WCF服务,我正在windows服务中托管该服务。Windows主机服务具有用于使用服务端点的App.config,该服务具有用于公开元数据端点的App.config。当服务通过VS开发系统部署时,一切都很好。加载Web浏览器后,url解析为元数据网页,公开服务的wsdl链接。它甚至可以与WCF测试客户端一起工作,我可以发送服务消息,它会做出响应 但是,由于projectInstaller加载到VS中的托管服务上并部署在VS开发系统之外,因此在Windows中部署托管服务时,我无法再访问

我有一个WCF服务,我正在windows服务中托管该服务。Windows主机服务具有用于使用服务端点的App.config,该服务具有用于公开元数据端点的App.config。当服务通过VS开发系统部署时,一切都很好。加载Web浏览器后,url解析为元数据网页,公开服务的wsdl链接。它甚至可以与WCF测试客户端一起工作,我可以发送服务消息,它会做出响应

但是,由于projectInstaller加载到VS中的托管服务上并部署在VS开发系统之外,因此在Windows中部署托管服务时,我无法再访问元数据端点。服务已启动并正在运行,但端点没有响应。使用“sc create binpath=“Service.exe”start=auto”命令从调试文件夹部署服务。可能这不是正确的部署方式,也可能我的app.Config文件不正确或引用不正确。有人能告诉我这个过程吗?也许可以验证我的app.Config文件对于windows主机和服务端都是正确的。这是相当棘手的配置,所以任何帮助是感激的

要使用终结点的Windows主机服务App.config:

  <system.serviceModel>
    <client>
    </client>

    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBinding_WindowsService" maxReceivedMessageSize="20000000" />
      </basicHttpBinding>
    </bindings>

    <services>
        <!-- Service endpoint to consume -->
        <service name="WindowsService.Service">
            <endpoint address="http://localhost:9001/Service" binding="basicHttpBinding"
                contract="WindowsService.IService" />
        </service>
    </services>

    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBinding_WindowsService" />
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="defaultbehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <services>
        <service behaviorConfiguration="defaultbehavior" name="WindowsService.Service">
          <!-- Base address for exposing Metadata and Service -->
          <host>
            <baseAddresses>
              <add baseAddress="http://localhost:9001/" />
            </baseAddresses>
          </host>

          <!-- Metadata service endpoint to expose -->
          <endpoint address="" binding="mexHttpBinding" contract="IMetadataExchange" />
          <!-- Service contract endpoint to expose -->
          <endpoint address="Service" binding="basicHttpBinding" contract="WindowsService.IService" />
        </service>
    </services>

    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>

要公开终结点的Service Web.config:

  <system.serviceModel>
    <client>
    </client>

    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBinding_WindowsService" maxReceivedMessageSize="20000000" />
      </basicHttpBinding>
    </bindings>

    <services>
        <!-- Service endpoint to consume -->
        <service name="WindowsService.Service">
            <endpoint address="http://localhost:9001/Service" binding="basicHttpBinding"
                contract="WindowsService.IService" />
        </service>
    </services>

    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBinding_WindowsService" />
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="defaultbehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <services>
        <service behaviorConfiguration="defaultbehavior" name="WindowsService.Service">
          <!-- Base address for exposing Metadata and Service -->
          <host>
            <baseAddresses>
              <add baseAddress="http://localhost:9001/" />
            </baseAddresses>
          </host>

          <!-- Metadata service endpoint to expose -->
          <endpoint address="" binding="mexHttpBinding" contract="IMetadataExchange" />
          <!-- Service contract endpoint to expose -->
          <endpoint address="Service" binding="basicHttpBinding" contract="WindowsService.IService" />
        </service>
    </services>

    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>


反弹。。。有人能帮忙吗?这两个app.config文件看起来可疑。您运行多少个进程?“主机服务”和“服务”有什么区别?如果这是一个进程,那么他们应该共享相同的app.config文件。我有一个控制台应用程序的自托管服务,使用ServiceBase类启动/停止该服务。web服务是主机控制的实际服务,它有一个web.config。有人告诉我,托管windows服务的控制台应用程序需要App.config来使用客户端点,而WCF服务需要Web.config来向客户公开端点,这不是真的吗?App.config将同时适用于这两种情况?可能只有IIS.svc类型的服务才需要Web.config,而不是自托管服务。您能告诉我吗?
web.config
在这里没有用,因为Windows服务根本不会加载它。@LexLi是正确的。您需要服务将使用的单个app.config-它可能包含元数据端点和服务端点。