views:

135

answers:

0

Hi all,

I am hosting my own WCF service in a web site through configuration. I need to use Sessions so the server will not get clogged with inactive clients. So I want to use reliable messaging, but an exception gets throw on the actual service call: ActionNotSupportedException:

The action http://tempuri.org/IApiService/Authenticate is not supported by this endpoint. Only WS-ReliableMessaging February 2005 messages are processed by this endpoint.

  1. How should I change configuration or interface definition?

  2. Requirements are operability and being able to host it from the default Development server, so I can't use net.tcp because it needs IIS 7 configuration.

  3. I also have a problem when opening the host, but when I restart the debug it works fine. So half the debugs, also without reliable messaging, break on this exception:

The ChannelDispatcher at 'http://localhost:8000/API/Item' with contract(s) '"IApiService"' is unable to open its IChannelListener.

Thanks in advance for any suggestions :)

here is my config:

<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="ServicesBindings">
                <reliableSession inactivityTimeout="00:00:10" enabled="true" ordered="true"/>
            </binding>
        </wsHttpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior name="returnFaults">
                <serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:8000/" />
                <serviceTimeouts transactionTimeout="00:01:00"/>
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="returnFaults" name="ApiService">
            <endpoint bindingConfiguration="ServicesBindings" address="http://localhost:8000/API/Item" binding="wsHttpBinding" contract="IApiService" />
            <endpoint address="http://localhost:8000/mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        </service>
    </services>
</system.serviceModel>

Here is my code:

[ServiceContract(SessionMode = SessionMode.Required)]
public interface IApiService
{
    [OperationContract]
    bool Authenticate(string username, string password);
}

// Run testcode inside web page.
public partial class TestApi : System.Web.UI.Page
{
    // There is a delay of 0.1 sec to make sure the server is ready.
    ApiServer.Start();
    // Client code.
    scf = new ChannelFactory<IApiService>(new WSHttpBinding(), "http://localhost:8000/API/Item");

    service = scf.CreateChannel();

    // Call the service, will return false
    service.Authenticate("username", "password"); // <- 1. this throws the exception

    scf.Close();
    ApiServer.Stop();
}

/// <summary>
/// Hosts the API so clients can call it's services.
/// </summary>
public class ApiServer
{
    private static System.Threading.AutoResetEvent stopFlag = new System.Threading.AutoResetEvent(false);
    private static System.Threading.Thread thServer;

    /// <summary>
    /// Starts hosting in a seperate thread.
    /// </summary>
    public static void Start()
    {
        // start server
        thServer = new System.Threading.Thread(Init);
        thServer.IsBackground = true;
        thServer.Start();
        System.Threading.Thread.Sleep(100);  // wait for server to start up
    }

    /// <summary>
    /// Opens the nessesary bindings and shuts the server down if Stop() is called.
    /// </summary>
    public static void Init()
    {
        ServiceHost host = new ServiceHost(typeof(ApiService));
        host.Open(); // <- 2. throws an Exception every other run...

        Console.WriteLine("SERVER - Running...");
        stopFlag.WaitOne();

        Console.WriteLine("SERVER - Shutting down...");
        host.Close();

        Console.WriteLine("SERVER - Shut down!");
    }

    /// <summary>
    /// Stops the server, running requests will be finished.
    /// </summary>
    public static void Stop()
    {
        stopFlag.Set();
        thServer.Join();    
    }
}