[Mono-list] Wrong MessageVersion with NetTcpBinding and BasicHttpBinding

Cocai simionato.cristiano at gmail.com
Tue Jun 28 05:10:12 EDT 2011


This is the code with the test, comment in the code explain the difference
between .Net 4.0 and Mono 2.10.2.

using System;
using System.ServiceModel;
using System.ServiceModel.Channels;

namespace TestWCF
{
	class Program
	{
		static void Main(string[] args)
		{
			Console.WriteLine(">>> Test 1");
			Test1();

			Console.WriteLine(">>> Test 2");
			Test2();

		}


		public static void Test1()
		{
			var serviceHost = new ServiceHost(typeof(BaseService));
			serviceHost.AddServiceEndpoint(typeof(IFoo), new
NetTcpBinding(SecurityMode.None),
										   "net.tcp://127.0.0.1:8080/BaseService");
			serviceHost.Open();

			var client = new BaseClient(new NetTcpBinding(SecurityMode.None), new
EndpointAddress("net.tcp://127.0.0.1:8080/BaseService"));

			var z1 = client.Endpoint.Binding.MessageVersion;

			//Without the service side running, in Mono 2.10.2 the next line throw a
SocketException "Connection refused"; but in .Net 4.0 runs correctly
			//so Mono has to have the service running to continue
			var z2 = client.InnerChannel.GetProperty<MessageVersion>();

			//In .Net 4.0 sameReference is True, in Mono z1 is the same as .Net, but
z2 is null or sometime (it seems random and not so frequent) is the Uri
			var sameReference = Object.ReferenceEquals(z1, z2);
			Console.WriteLine(sameReference ? "The reference are same! z ={0}" : "The
reference are not same! z1 = {0}; z2 = {1}", z1, z2);

			new OperationContextScope(client.InnerChannel);

			var z3 = OperationContext.Current.OutgoingMessageHeaders.MessageVersion;

			sameReference = Object.ReferenceEquals(z1, z3);
			Console.WriteLine(sameReference ? "The reference are same! z ={0}" : "The
reference are not same! z1 = {0}; z3 = {1}", z1, z3);

			Console.WriteLine("press enter to continue...");
			Console.ReadLine();

			var aux1 = client.Echo("test");
			var aux2 = client.Add(1, 2);

			Console.WriteLine("Echo = {0}; Add = {1}", aux1, aux2);

			Console.WriteLine("press enter to continue...");
			Console.ReadLine();
			serviceHost.Close();
		}


		public static void Test2()
		{
			var client = new BaseClient(new BasicHttpBinding() {
HostNameComparisonMode = HostNameComparisonMode.Exact }, new
EndpointAddress("http://127.0.0.1/BaseService"));
			var z1 = client.Endpoint.Binding.MessageVersion;

			//Without the service side running, the next line runs correctly either
in Mono 2.10.2 and in .Net 4.0
			//This is a different behaviour from NetTcpBinding
			var z2 = client.InnerChannel.GetProperty<MessageVersion>();

			//In .Net 4.0 sameReference is True, in Mono z1 is the same as .Net
(Soap11 AddressingNone),
			//but z2 is always null
			var sameReference = Object.ReferenceEquals(z1, z2);
			Console.WriteLine(
				sameReference ? "The reference are same! z ={0}" : "The reference are
not same! z1 = {0}; z2 = {1}", z1,
				z2 == null ? "NULL" : z2.ToString());
			
			new OperationContextScope(client.InnerChannel);

			//In .Net 4.0 sameReference is True, in Mono z1 is the same as .Net, but
z3 is Soap12 Addresing10
			var z3 = OperationContext.Current.OutgoingMessageHeaders.MessageVersion;

			sameReference = Object.ReferenceEquals(z1, z3);
			Console.WriteLine(
				sameReference ? "The reference are same! z ={0}" : "The reference are
not same! z1 = {0}; z3 = {1}", z1,
				z3 == null ? "NULL" : z3.ToString());

			Console.WriteLine("press enter to continue...");
			Console.ReadLine();
		}
	}

	[ServiceContract]
	public interface IFoo
	{
		[OperationContract]
		string Echo(string msg);

		[OperationContract]
		uint Add(uint v1, uint v2);
	}


	public class BaseClient : ClientBase<IFoo>, IFoo
	{
		public BaseClient(Binding binding, EndpointAddress remoteAddress)
			: base(binding, remoteAddress)
		{ }

		public string Echo(string msg)
		{
			return Channel.Echo(msg);
		}

		public uint Add(uint v1, uint v2)
		{
			return Channel.Add(v1, v2);
		}
	}


	public class BaseService : IFoo
	{
		public string Echo(string msg)
		{
			return msg;
		}


		public uint Add(uint v1, uint v2)
		{
			return v1 + v2;
		}
	}
}

Cristiano

--
View this message in context: http://mono.1490590.n4.nabble.com/Wrong-MessageVersion-with-NetTcpBinding-and-BasicHttpBinding-tp3605695p3629840.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list