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);
}
}
}
}