Bug 687633

Summary: System.ServiceModel.ClientBase<TChannel> in mono 2.10.1WCF fails with 'Status code 404(NotFound)' or 'Status code 400(BadRequest)'
Product: [Mono] Mono: Class Libraries Reporter: Emily Lewis <emily.lewis>
Component: WCFAssignee: Atsushi Enomoto <atsushieno>
Status: NEW --- QA Contact: Mono Bugs <mono-bugs>
Severity: Normal    
Priority: P5 - None    
Version: 2.10.x   
Target Milestone: ---   
Hardware: 64bit   
OS: Windows Server 2008 R2   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: This is a working solution that reproduces the bug

Description Emily Lewis 2011-04-14 17:48:06 UTC
Created attachment 424997 [details]
This is a working solution that reproduces the bug

User-Agent:       Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)

I sumbitted a potentially related bug, 687580, but I have noticed a seperate issue that seems to be unqiue enough that I am being safe by sumbitting a different bug. 

As I stated in the previous bug, I am presently evaluating whether mono 2.10 WCF is stable enough for a project we are working on. I have written a very simple WCF REST client/server test jig upon which to make this assessment. I have discovered however, that the test only works if I run the test client in Microsoft .NET. The client uses System.ServiceModel.ClientBase<TChannel>. Here are the cases.

First Case -> 
- Run the WCF server in Microsoft .NET
- Run the client in mono
- The client always throws the following exception:

     ---->System.Net.WebException
     Message
          There was an error on processing web request: Status code 404(NotFound
): Not Found
     Stack
          at System.ServiceModel.Channels.HttpRequestChannel+HttpChannelRequestA
syncResult.WaitEnd () [0x0003c] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10
.1\mcs\class\System.ServiceModel\System.ServiceModel.Channels\HttpRequestChannel
.cs:435
          at System.ServiceModel.Channels.HttpRequestChannel.EndRequest (IAsyncR
esult result) [0x00029] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\c
lass\System.ServiceModel\System.ServiceModel.Channels\HttpRequestChannel.cs:289
          at System.ServiceModel.Channels.HttpRequestChannel.Request (System.Ser
viceModel.Channels.Message message, TimeSpan timeout) [0x00000] in C:\cygwin\tmp
\monobuild\build\BUILD\mono-2.10.1\mcs\class\System.ServiceModel\System.ServiceM
odel.Channels\HttpRequestChannel.cs:63
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (Syst
em.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x0000b] in C:\cygwin\t
mp\monobuild\build\BUILD\mono-2.10.1\mcs\class\System.ServiceModel\System.Servic
eModel\ClientRuntimeChannel.cs:579
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (Syst
em.ServiceModel.Description.OperationDescription od, System.Object[] parameters)
 [0x00066] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\class\System.S
erviceModel\System.ServiceModel\ClientRuntimeChannel.cs:534
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.DoProcess (Sy
stem.Reflection.MethodBase method, System.String operationName, System.Object[]
parameters) [0x00038] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\cla
ss\System.ServiceModel\System.ServiceModel\ClientRuntimeChannel.cs:499
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Process (Syst
em.Reflection.MethodBase method, System.String operationName, System.Object[] pa
rameters) [0x00000] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\class
\System.ServiceModel\System.ServiceModel\ClientRuntimeChannel.cs:479


Second Case -> 
- Run the WCF server in mono
- Run the client in mono
- The client always throws the following exception:

     ---->System.Net.WebException
     Message
          There was an error on processing web request: Status code 400(BadReque
st): Bad Request
     Stack
          at System.ServiceModel.Channels.HttpRequestChannel+HttpChannelRequestA
syncResult.WaitEnd () [0x0003c] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10
.1\mcs\class\System.ServiceModel\System.ServiceModel.Channels\HttpRequestChannel
.cs:435
          at System.ServiceModel.Channels.HttpRequestChannel.EndRequest (IAsyncR
esult result) [0x00029] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\c
lass\System.ServiceModel\System.ServiceModel.Channels\HttpRequestChannel.cs:289
          at System.ServiceModel.Channels.HttpRequestChannel.Request (System.Ser
viceModel.Channels.Message message, TimeSpan timeout) [0x00000] in C:\cygwin\tmp
\monobuild\build\BUILD\mono-2.10.1\mcs\class\System.ServiceModel\System.ServiceM
odel.Channels\HttpRequestChannel.cs:63
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (Syst
em.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x0000b] in C:\cygwin\t
mp\monobuild\build\BUILD\mono-2.10.1\mcs\class\System.ServiceModel\System.Servic
eModel\ClientRuntimeChannel.cs:579
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (Syst
em.ServiceModel.Description.OperationDescription od, System.Object[] parameters)
 [0x00066] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\class\System.S
erviceModel\System.ServiceModel\ClientRuntimeChannel.cs:534
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.DoProcess (Sy
stem.Reflection.MethodBase method, System.String operationName, System.Object[]
parameters) [0x00038] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\cla
ss\System.ServiceModel\System.ServiceModel\ClientRuntimeChannel.cs:499
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Process (Syst
em.Reflection.MethodBase method, System.String operationName, System.Object[] pa
rameters) [0x00000] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\class
\System.ServiceModel\System.ServiceModel\ClientRuntimeChannel.cs:479

Here are the details of my test setup (I have included the full Visual Studio
2010 solution in an attachment as well):

Contract

    [ServiceContract]
    public interface IProfileREST
    {
      [OperationContract, WebGet(UriTemplate = "Ping")]
      void Ping();
    }

Server 

    [ServiceBehavior
        (
            InstanceContextMode = InstanceContextMode    .Single        , 
            ConcurrencyMode        = ConcurrencyMode        .Multiple
        )
    ]
    public class ProfileRest : IProfileREST
    {
        #region members
        long _hits = 0;
        #endregion

        #region .ctor
        public ProfileRest()
        {
        }
        #endregion

        #region IProfileREST
        void IProfileREST.Ping()
        {
            Console.WriteLine("Ping {0}",Interlocked.Increment(ref _hits));
        }
        #endregion
    }

        static void Main(string[] args)
        {
            var address = new Uri("http://localhost:8080/ProfileREST");
            var binding    = new WebHttpBinding ();
            var server    = new ProfileRest();
            var host    = new WebServiceHost(server);
            host.AddServiceEndpoint(typeof(IProfileREST), binding, address);
            host.Open();

            Console.WriteLine("The server is running, press a key to stop...");
            Console.ReadKey();
        }


Client

    public class ProfileRESTClient : ClientBase<IProfileREST>, IProfileREST
    {
        #region .ctor
        public ProfileRESTClient() : base()
        {
        }

        public ProfileRESTClient(Binding binding, EndpointAddress address) :
base(binding, address) 
        {
            base.Endpoint.Behaviors.Add(new WebHttpBehavior());
        }
        #endregion

        #region IProfileREST
        void IProfileREST.Ping()
        {
            base.Channel.Ping();
        }
        #endregion
    }

        static void Main(string[] args)
        {
            EndpointAddress address = new EndpointAddress(new
Uri("http://localhost:8080/ProfileREST"));
            Binding binding = new WebHttpBinding();
            using (IProfileREST client = new ProfileRESTClient(binding,
address))
            {
                client.Ping();
            }
        }


Reproducible: Always

Steps to Reproduce:
1. Run the server in Microsoft.net
2. Run the client in mono
3. The client will throw an exception


Alternatively:

1. Run the server in mono
2. Run the client in mono
3. The client will throw an exception
Actual Results:  
If the server is running in Microsoft.net the following exception is thrown on the client:

     ---->System.Net.WebException
     Message
          There was an error on processing web request: Status code 404(NotFound
): Not Found
     Stack
          at System.ServiceModel.Channels.HttpRequestChannel+HttpChannelRequestA
syncResult.WaitEnd () [0x0003c] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10
.1\mcs\class\System.ServiceModel\System.ServiceModel.Channels\HttpRequestChannel
.cs:435
          at System.ServiceModel.Channels.HttpRequestChannel.EndRequest (IAsyncR
esult result) [0x00029] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\c
lass\System.ServiceModel\System.ServiceModel.Channels\HttpRequestChannel.cs:289
          at System.ServiceModel.Channels.HttpRequestChannel.Request (System.Ser
viceModel.Channels.Message message, TimeSpan timeout) [0x00000] in C:\cygwin\tmp
\monobuild\build\BUILD\mono-2.10.1\mcs\class\System.ServiceModel\System.ServiceM
odel.Channels\HttpRequestChannel.cs:63
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (Syst
em.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x0000b] in C:\cygwin\t
mp\monobuild\build\BUILD\mono-2.10.1\mcs\class\System.ServiceModel\System.Servic
eModel\ClientRuntimeChannel.cs:579
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (Syst
em.ServiceModel.Description.OperationDescription od, System.Object[] parameters)
 [0x00066] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\class\System.S
erviceModel\System.ServiceModel\ClientRuntimeChannel.cs:534
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.DoProcess (Sy
stem.Reflection.MethodBase method, System.String operationName, System.Object[]
parameters) [0x00038] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\cla
ss\System.ServiceModel\System.ServiceModel\ClientRuntimeChannel.cs:499
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Process (Syst
em.Reflection.MethodBase method, System.String operationName, System.Object[] pa
rameters) [0x00000] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\class
\System.ServiceModel\System.ServiceModel\ClientRuntimeChannel.cs:479

If the server is running in mono the following exception is thrown on the client:

     ---->System.Net.WebException
     Message
          There was an error on processing web request: Status code 400(BadReque
st): Bad Request
     Stack
          at System.ServiceModel.Channels.HttpRequestChannel+HttpChannelRequestA
syncResult.WaitEnd () [0x0003c] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10
.1\mcs\class\System.ServiceModel\System.ServiceModel.Channels\HttpRequestChannel
.cs:435
          at System.ServiceModel.Channels.HttpRequestChannel.EndRequest (IAsyncR
esult result) [0x00029] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\c
lass\System.ServiceModel\System.ServiceModel.Channels\HttpRequestChannel.cs:289
          at System.ServiceModel.Channels.HttpRequestChannel.Request (System.Ser
viceModel.Channels.Message message, TimeSpan timeout) [0x00000] in C:\cygwin\tmp
\monobuild\build\BUILD\mono-2.10.1\mcs\class\System.ServiceModel\System.ServiceM
odel.Channels\HttpRequestChannel.cs:63
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (Syst
em.ServiceModel.Channels.Message msg, TimeSpan timeout) [0x0000b] in C:\cygwin\t
mp\monobuild\build\BUILD\mono-2.10.1\mcs\class\System.ServiceModel\System.Servic
eModel\ClientRuntimeChannel.cs:579
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Request (Syst
em.ServiceModel.Description.OperationDescription od, System.Object[] parameters)
 [0x00066] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\class\System.S
erviceModel\System.ServiceModel\ClientRuntimeChannel.cs:534
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.DoProcess (Sy
stem.Reflection.MethodBase method, System.String operationName, System.Object[]
parameters) [0x00038] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\cla
ss\System.ServiceModel\System.ServiceModel\ClientRuntimeChannel.cs:499
          at System.ServiceModel.MonoInternal.ClientRuntimeChannel.Process (Syst
em.Reflection.MethodBase method, System.String operationName, System.Object[] pa
rameters) [0x00000] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.10.1\mcs\class
\System.ServiceModel\System.ServiceModel\ClientRuntimeChannel.cs:479

Expected Results:  
The client should be able to call the server without receiving any exceptions both when the client runs in mono and in Microsoft .Net.
Comment 1 Emily Lewis 2011-04-15 15:37:30 UTC
I have discovered that if I build the entire solution, both the server and client, in "Any CPU" configuration I can run a client based on System.ServiceModel.ClientBase<TChannel>. The machine I am developing on on Windows Server 2008 R2 64-bit and I was running the solution in x86 configuration suggesting mono is [too] sensitive to CPU configuration.