为什么服务没有启动? [英] Why doesn't the service start?

查看:75
本文介绍了为什么服务没有启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试启动自托管服务,因此流程如下:



  • 使用WCF VS2017的模板我用服务和合同创建了一个库。

  • 我创建了一个新的WPF项目,它引用了这个库来使用该服务。此WPF应用程序将托管该服务。



  • 我将使用VS2017模板创建的库的app.config中的所有配置复制到WPF应用程序的app.config。只是我修改了URL,为了避免冲突,URL将是Service2而不是Service1。这是因为如果我启动
    来调试,visual studio将启动库的服务和WPF应用程序的服务。



<问题是,WPF应用程序中托管的服务未启动。另外我试图卸载库项目只运行WPF项目,以避免启动我不想运行的服务,但问题是相同的,服务是
没有启动。


app.config是这样的:

  <?  xml版本  =  " 1.0"  编码  =  " utf-8"    ?>   
< ;配置>
< startup>
< supportedRuntime version = " v4.0" sku = ".NETFramework,Version = v4.7.2" />
< / startup >
< appSettings>
< 添加键 = "aspnet:UseTaskFriendlySynchronizationContext" value = " true" />
< / appSettings >
< system web >
< 编译调试 = " true" />
< / system web >
< system serviceModel >
< services>
< 服务名称 = "Servicio.Service1" >
<主机>
< baseAddresses >
< add baseAddress = " http:// localhost:8733 / Design_Time_Addresses / Servicio / Service2 /" ; />
< / baseAddresses >
< / 主机 >
< 端点地址 = "" binding = " basicHttpBinding" 合同 = " Servicio .IService1" <跨度class ="pun">>
< identity>
< dns值 = " localhost" />
< / 身份 >
< / 端点 >
< 端点地址 = " mex" binding = " mexHttpBinding" contract = " IMetadataExchange" ; />
< / service >
< / 服务 >
< behavior>
< serviceBehaviors>
< behavior>
< serviceMetadata httpGetEnabled = " True" httpsGetEnabled = " True" />
< serviceDebug includeExceptionDetailInFaults = < /跨度> < span class ="str">" False" />
< / 行为 >
< / serviceBehaviors >
< / 行为 >
< / system serviceModel >
< / 配置 >

我的WPF项目背后的代码:

   public     partial     class     MainWindow       窗口  
{
public MainWindow ()
{
InitializeComponent ();

使用
_ host = new ServiceHost typeof Servicio Service1 )))
{
_host
打开 ();
}
}

private ServiceHost _host ;
}

为什么服务没有启动?

解决方案

我不知道你使用WPF的这种技术。对我来说,自托管WCF服务将是一个独立的exe解决方案,如控制台或Windows服务。


WPF程序将是WCF自托管WCF服务的WCF客户端在机器上运行。


https://praveenkatiyar.wordpress.com/2013/09/09/creating-a-wcf-service-with-self -hosted /


https://www.codeproject.com/Articles/653493/WCF-Hosting-with-Windows-Service


或许你可以尝试下面的  WPF解决方案而不是Windows窗体解决方案。


https://www.c-sharpcorner.com/UploadFile/8a67c0/wcf-service-self-hosting -and-consume-with-windows-applicat /


 


I am trying to start a self host service, so the process is this:

  • With the WCF template of VS2017 I create a library with the service and the contract.
  • I create a new WPF project that references to this library to can use the service. This WPF application will host the service.

  • I copy all the configuration from app.config of the library that is created with the VS2017 template to the app.config of the WPF application. Just I modify the URL, to avoid conflicts, the URL will be Service2 instead of Service1. This is because if I start to debug, visual studio start the service of the library and the service of the WPF application.

The problem is that the service of hosted in the WPF application is not started. Also I have tried to unload the library project to run only the WPF project, to avoid to start services that I don't want to run, but the problem is the same, the service is not started.

The app.config is this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="Servicio.Service1">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8733/Design_Time_Addresses/Servicio/Service2/" />
          </baseAddresses>
        </host>
        <endpoint address="" binding="basicHttpBinding" contract="Servicio.IService1">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

The code bihind of my WPF project:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        using (_host = new ServiceHost(typeof(Servicio.Service1)))
        {
            _host.Open();
        }
    }

    private ServiceHost _host;
}

Why the service is not started?

解决方案

I don't know about this technique of yours using WPF. To me, a self hosting WCF service would be a standalone exe solution, like a console or Windows service.

The WPF program would be a WCF client to the WCF self hosting WCF service that was running on the machine.

https://praveenkatiyar.wordpress.com/2013/09/09/creating-a-wcf-service-with-self-hosted/

https://www.codeproject.com/Articles/653493/WCF-Hosting-with-Windows-Service

Or maybe you try the below with  WPF solution instead of a Windows form solution.

https://www.c-sharpcorner.com/UploadFile/8a67c0/wcf-service-self-hosting-and-consuming-with-windows-applicat/

 


这篇关于为什么服务没有启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆