【问题标题】:Deploying WCF Service Host App without WCF Service Host?在没有 WCF 服务主机的情况下部署 WCF 服务主机应用程序?
【发布时间】:2014-12-08 14:34:46
【问题描述】:

我有一个由简单 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 没有在监听,所以就好像服务对象从未真正初始化过。我确定这是我的某个地方的配置中的一个简单错误,有什么想法吗?谢谢

【问题讨论】:

  • 尝试以管理员身份运行宿主应用程序

标签: c# .net web-services wcf service


【解决方案1】:

端口 8080 是 SQL Server 的保留端口,您的服务 App.config 和主机 App.config 在其基地址中具有不同的端口

【讨论】:

  • 在 8082 和其他各种设备上试过,没有运气。刚刚获得“此服务的元数据发布当前已禁用。”浏览器中的屏幕。
  • 尝试让两个App.config中的基地址相同,你可以用localhost:80试试。
  • 是的,试过了,结果一样。如果我尝试在运行时重新启动服务,则会出现“端口已在使用”类型的异常,因此该应用显然正在注册地址...
  • 试试这个 [URL](link 中给出的说明并确保你没有遗漏任何东西
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-31
    相关资源
    最近更新 更多