The Service on local computer started and then sto

2019-07-03 22:21发布

问题:

I created one sample windows service and installed my service with successfully. But while going to START the service. I am getting below error.

This sevice on local computer started and then stopped. some serivces stop automatically if then are not in use by other serives or programs

My config file Code:

<system.serviceModel>
    <services>
      <service name="SvcClient.WCFJobsLibrary.Service1">
        <endpoint address="" binding="wsHttpBinding" contract="WCFJobsLibrary.IService1">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/WCFJobsLibrary/Service1/" />
          </baseAddresses>
        </host>
      </service>
 </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="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="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

Can any one please suggest me... Thanks in adv.

回答1:

You need to specify the endpoint of the service (the URI at which the service can be reached by the client).

You can do it in the code where you instantiate the ServiceHost (a very generic example):

ServiceHost myHost = new ServiceHost(typeof(TechResponse), new Uri("http://www.somedomain.com/TechResponse"));