Pregunta

For example

        // Create a ServiceHost for the Service type and 
        // provide the base address.
        mServiceHost = new ServiceHost(typeof(T));

        // Open the ServiceHostBase to create listeners and start 
        // listening for messages.
        mServiceHost.Open();

where in this case T is TransactionProcessingService.

So far I am getting an error with the app config and not sure how I should modify it:

Service 'TransactionProcessingWindowsService.TransactionProcessingService`1[[Common.TransactionProcessing, Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.

Here's how I tried to set up my config

      <service name="TransactionProcessingWindowsService.TransactionProcessingService&lt;TransactionProcessingWindowsService.TransactionProcessing&gt;"
           behaviorConfiguration="TransactionProcessingServiceBehavior">
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8000/TransactionProcessingService/service"/>
      </baseAddresses>
    </host>
    <endpoint address=""
              binding="wsHttpBinding"
              contract="TransactionProcessingWindowsService.ITransactionProcessingService" />
    <endpoint address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" />
  </service>

Thanks

¿Fue útil?

Solución

Exception details show you what service name should be used. Try this:

<service name="TransactionProcessingWindowsService.TransactionProcessingService`1[[Common.TransactionProcessing, Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]"
         behaviorConfiguration="TransactionProcessingServiceBehavior">

but that is not cool, as you need to update config file each time you changing the assembly version or sign it.

Otros consejos

Your config file has an endpoint for ITransactionProcessingService, but not for TransactionProcessingService.

Because you are using generics, T can be anything (or whatever you limit it to). But you need to have an endpoint defined for whatever you use as T.

I would recommend an interface instead of a generic.

So, I was trying the generic because I already had an Interface, but needed a common base class for the common functionality. So, I was trying this:

public class TransactionProcessingService<T> : ITransactionProcessingService where T : BaseProgram

Because I wanted to have the common functionality and properties from BaseProgram. I couldn't inherit from 2 interfaces or an interface and a class because I could only have one wsHttpBinding binding endpoint. I ended up going back to

public class TransactionProcessingService : ITransactionProcessingService

and

public class MyServiceBase<T, U> : ServiceBase where U : BaseProgram, new()

where MyServiceBase provides a static property that just provides access to the property in the static instance of U.

private static U mProcess;
protected ServiceHost mServiceHost = null;
public static int StatusCheckFrequency
{
    get { return mProcess.StatusCheckFrequency; }
    set { mProcess.StatusCheckFrequency = value; }
}

This works because I only intend to have one instance of each service running on a machine.

I'll give ie. the answer because it appears to answer my question, even though I didn't end up trying it.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top