繁体   English   中英

在没有WCF服务主机的情况下部署WCF服务主机应用程序?

[英]Deploying WCF Service Host App without WCF Service Host?

我有一个由简单WinForms应用程序托管的WCF服务。 在Visual Studio中,该服务通过内置的WCF服务主机启动,并且一切正常。 我现在想在我的主机应用程序中托管该服务,但是当前该服务无法运行。

服务应用程序:

  ServiceHost host;
    private void btnStart_Click(object sender, EventArgs e)
    {
        host = new ServiceHost(typeof(RegimesService));
        host.Open();
        lblStatus.Text = "Started...";
    }

如果我关闭系统托盘中的WCF服务主机并单击“开始”按钮,则代码会运行,但服务永远不会启动?

这是我的服务主机应用程序配置:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metaBehavior">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
       <service name="diiRegimesService.RegimesService">
        <endpoint address="" binding="basicHttpBinding" contract="diiRegimesService.IRegimesService"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8081" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>

最后是我的服务项目App.config:

 <system.serviceModel>
    <services>
      <service name="diiRegimesService.RegimesService">
        <endpoint address="" binding="basicHttpBinding" contract="diiRegimesService.IRegimesService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttp" allowCookies="true"
                 maxReceivedMessageSize="20000000"
                 maxBufferSize="20000000"
                 maxBufferPoolSize="20000000">
          <readerQuotas maxDepth="32"
               maxArrayLength="200000000"
               maxStringContentLength="200000000"/>
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>

当我从cmd行运行netstat -a ,端口http://localhost:8080没有监听,因此就像服务对象从未真正初始化过。 我确定这是我的某个地方的配置中的一个简单错误,有什么想法吗? 谢谢

端口8080是SQL Server的保留端口,您的服务App.config和Host App.config的基地址也具有不同的端口

好的,使用解决方案资源管理器中的WCF配置向导并将ServiceBehaviour绑定到主机应用程序的App.Config的服务定义,嘿,很简单,一切都已连接并正常工作! 感谢您的帮助@Akshay Choudhary。

暂无
暂无

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

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