tags:

views:

189

answers:

3

I'm having trouble with a simple self-hosted WCF service, using basic HTTP binding on Mono. When I run the service on .NET, everything works fine. When I run the server on Mono, the first request works fine, but the second request hangs, eventually timing out.

To test, I ran the server on both windows and Mono and made two requests from a client running on Mono. When the service runs on windows, the HTTP stream looks like I would expect:

POST /Echo HTTP/1.1 -->
<-- HTTP/1.1 100 Continue
POST /Echo HTTP/1.1 -->
<-- HTTP/1.1 100 Continue

On Mono, though, it looks like this:

POST /Echo HTTP/1.1 -->
<-- HTTP/1.1 100 Continue
<-- HTTP/1.1 200 OK
POST /Echo HTTP/1.1 -->

There's no other activity on the network until the default 60 second timeout is reached and the client sends a FIN to the server.

I've included configuration information and code below. Thanks in advance.

Configuration

Here's the output from mono --version:

Mono JIT compiler version 2.4.2.3 (Debian 2.4.2.3+dfsg-2~dhx1~jaunty1)
Copyright (C) 2002-2008 Novell, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        GC:            Included Boehm (with typed GC)
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none

Code

Service

using System;
using System.ServiceModel;

namespace Sample.Echo
{
    [ServiceContract]
    public interface IEchoService
    {
        [OperationContract]
        string Echo(string val);
    }

    public class EchoService : IEchoService
    {
        public string Echo(string val)
        {
            return val ?? String.Empty;
        }
    }
}

Server

using System;
using System.ServiceModel;
using Sample.Echo;

namespace Sample.Echo.Server
{
    class Program
    {
        static void Main(string[] args)
        {
            string addr = "http://localhost:9999/";
            if (args.Length > 0)
            {
                addr = args[0];
            }
            var host = new ServiceHost(typeof(EchoService));
            host.AddServiceEndpoint(typeof(IEchoService), new BasicHttpBinding(), addr + "Echo");
            host.Open();

            Console.Write("Press any key to end...");
            Console.ReadKey();
            Console.WriteLine("terminated");
            host.Close();
        }
    }
}

Client

using System;
using System.ServiceModel;

using Sample.Echo;

namespace Sample.Echo.Client
{
    class Program
    {
        static void Main(string[] args)
        {
            string addr = "http://localhost:9999/";
            if (args.Length > 0)
            {
                addr = args[0];
            }
            var client = new ChannelFactory<IEchoService>(new BasicHttpBinding(), addr + "Echo");
            var echoServ = client.CreateChannel();

            Console.WriteLine("Enter text to echo, or \"quit\" to quit.\n");
            int count = 0;
            while (true) 
            {
                string line = Console.ReadLine();
                if (line == null || line.ToLower().Equals("quit")) break;
                string response = echoServ.Echo(line);
                Console.WriteLine("{0}: {1} => {2}", ++count, line, response);
            }
        }
    }
}
A: 

Although this works on .net, reusing the client is not the recommend way to do this.

http://msdn.microsoft.com/en-us/library/ms735103.aspx

try moving the creation of the client inside the while loop, and do a client.close() after the console.writeline().

Shiraz Bhaiji
I've attempted what you suggested and it does not fix the problem.Maybe I'm missing something, but I didn't see anything at the link above that indicated I should call Close() on a client after invocation of a service operation.
Matt McClellan
@Matt, it was point 4 on the list. But I see that your variable client is a channel factory, not a wcf client, try doing the close on the echoServ.
Shiraz Bhaiji
@Shiraz But point 3 before it leads me to believe I can call operations multiple times before closing.
Matt McClellan
+4  A: 

Would you mind testing our Mono 2.6 preview packages?

WCF was not very strong in Mono 2.4, it was merely shipped as a preview.

miguel.de.icaza
@miguel Will do. And it looks like suse studio will make it nice and easy too. :-)
Matt McClellan
Tried again with the Mono 2.6 preview packages on an openSUSE 11.1 vmware image and it worked as expected. Thanks!
Matt McClellan
A: 

I've tried the same sort of thing but I used a NetTcpBinding and I have the same results using mono 2.6.

Marcus Monaghan