Bug 14335 - WCF Cannot handle -Multiple inheritance of ServiceContracts. - Throws exception on the host side
Summary: WCF Cannot handle -Multiple inheritance of ServiceContracts. - Throws excepti...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-08-29 16:45 UTC by Mark
Modified: 2013-09-21 20:49 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
a zipped project file that runs in monodevelop (7.89 KB, application/x-zip-compressed)
2013-08-29 17:22 UTC, Mark
Details

Description Mark 2013-08-29 16:45:57 UTC
Multiple contract inhertance first level, host side bug in ServiceHostBase.OnOpen.
This fails on mono running on Linux and Windows. I does not Exception at all on .NET.
The attached test case will always reproduce the problem

	[ServiceContract]
	public interface IBaseContractB
	{
		[OperationContract]
		void BaseMethodB ();
	}



    	[ServiceContract]
    	public interface IBaseContractA
    	{
        	[OperationContract]
        	void BaseMethodA();
        }


	[ServiceContract]
	public interface IFinalContract : IBaseContractA, IBaseContractB //IIntermediateInterfaceA, IIntermediateInterfaceB
	{
		[OperationContract]
		void FinalMethod();
	}

    	public class Service : IFinalContract
    	{
        	public void BaseMethodA()
        	{
            		//throw new NotImplementedException();
        	}

		public void BaseMethodB()
		{
			//throw new NotImplementedException();
		}

		public void FinalMethod()
		{
			//throw new NotImplementedException ();
		}
    	}


EXCEPTION: System.InvalidOperationException: Two or more service endpoints with different Binding instance are bound to the same listen URI.
  at System.ServiceModel.ServiceHostBase.OnOpen (TimeSpan timeout) [0x0008b] in 

/home/build/src/mono/mcs/class/System.ServiceModel/System.ServiceModel/ServiceHostBase.cs:577 
  at System.ServiceModel.Channels.CommunicationObject.Open (TimeSpan timeout) [0x00006] in 

/home/build/src/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/CommunicationObject.cs:170 
  at System.ServiceModel.Channels.CommunicationObject.Open () [0x00000] in 

/home/build/src/mono/mcs/class/System.ServiceModel/System.ServiceModel.Channels/CommunicationObject.cs:164 
  at WCFContractFailure.Program.CreateBasicHttpHost (WCFContractFailure.Service service) [0x0007f] in 

/home/build/src/testcases/WCFContractFailure2/Program.cs:44 
  at WCFContractFailure.Program.Main (System.String[] args) [0x0001b] in /home/build/src/testcases/WCFContractFailure2/Program.cs:17
Comment 1 Mark 2013-08-29 17:22:33 UTC
Created attachment 4756 [details]
a zipped project file that runs in monodevelop
Comment 2 Mark 2013-08-29 18:19:48 UTC
If you build single inheritance hierarchy in service contracts > 2
the same error will occur as happens with directly inheriting from 2 


    [ServiceContract]
    public interface IBaseContractA
    {
        [OperationContract]
        void BaseMethodA();
    }

   public interface IIntermediateInterfaceA : IBaseContractA
    {
		

        void IntermediateMethodA();
    }


    public class Service : IFinalContract
    {
        public void IntermediateMethodA()
        {
            //throw new NotImplementedException();
        }
//
//		public void IntermediateMethodB()
//		{
//			//throw new NotImplementedException();
//		}

        public void BaseMethodA()
        {
            //throw new NotImplementedException();
        }

//		public void BaseMethodB()
//		{
//			//throw new NotImplementedException();
//		}

		public void FinalMethod()
		{
			//throw new NotImplementedException ();
		}
    }
Comment 3 Mark 2013-09-16 16:25:43 UTC
mlintner opened this pull request a day ago 
These changes fix 14335. When in getcontractinternal various things can ...
Edit
 

No milestone  

No one is assigned  
 

...confuse the host processing of ContractInterfaces. I only identified and fixed a couple so far and they fix problems with multiple inheritance of contracts and deep hierarchies. It is looking to verify that all of the contract interfaces it has in the list inherit from the root interface. However when IA and IB inherit from the IRoot. It will iterate nxn times and with multiple inehritance it will eventuall get a 1A and verify that it inherits from iroot it gois along until it verifies that A inherits from the root then finds it cannot verify IA becuase because it is checking to see if IB inherits from it. It doesnt because both of them are peers and inheit from IRoot. This threw an exception. I fixes that and a couple of related bugs.
Comment 4 Mark 2013-09-16 17:40:59 UTC
mlintner opened this pull request a day ago 
These changes fix 14335. When in getcontractinternal various things can ...
Edit
 

No milestone  

No one is assigned  
 

...confuse the host processing of ContractInterfaces. I only identified and fixed a couple so far and they fix problems with multiple inheritance of contracts and deep hierarchies. It is looking to verify that all of the contract interfaces it has in the list inherit from the root interface. However when IA and IB inherit from the IRoot. It will iterate nxn times and with multiple inehritance it will eventuall get a 1A and verify that it inherits from iroot it gois along until it verifies that A inherits from the root then finds it cannot verify IA becuase because it is checking to see if IB inherits from it. It doesnt because both of them are peers and inheit from IRoot. This threw an exception. I fixes that and a couple of related bugs.
Comment 5 Mark 2013-09-21 20:49:54 UTC
Copyed from pull request.

Service --> ITopInterface--> IA, IB. 

There are some edge cases which broke the ContractDescrtiption.GetContract. If a root interface inherits from IA and IB, this interpreted as an ambiguous case when in fact it is not. If the service inherited from 2 service contracts that would be ambiguous. I implemented an algorithm which crawls the ContractInterface set, similar to the original by using IsAssignablefrom and an N * N nested foreach comparing each ContractInterface to each ContractInterface. The smallest will have the most interfaces assignable to them. The largest will only be assignable by themselves. These are candidates for a the legal topmost ContractInterface. If there are 2 or more of these found then that is when the InvalidOperationException should be thrown because it is ambiguous. If none are found then the original interface that was passed in is the topmost interface. 

There were 2 different cases exceptions occurring. With the current code without the fix in pull request #757 only the described here seems to be reproducible. The fix in pull request #757 fixes this multiple inheritance issue described above in a way that will be easy to understand and maintain in the future.

Note You need to log in before you can comment on or make changes to this bug.