Bug 40064 - [MONO] Service Endpoint - EndpointBehaviors Not Implement
Summary: [MONO] Service Endpoint - EndpointBehaviors Not Implement
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-04-02 08:43 UTC by Matthew
Modified: 2017-09-06 16:55 UTC (History)
2 users (show)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 40064 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Matthew 2016-04-02 08:43:46 UTC
When creating a WCF client in a PCL (targetting .NET Core) you must use EndpointBehaviors and not Behaviors. This works fine in a Windows RT application, but Mono has not implemented this so produces NotImplementedException in Android and iOS.

https://github.com/mono/mono/blob/master/mcs/class/System.ServiceModel/System.ServiceModel.Description/ServiceEndpoint.cs

		public KeyedByTypeCollection<IEndpointBehavior> Behaviors {
			get { return behaviors; }
		}

		[MonoTODO]
		public KeyedCollection<Type,IEndpointBehavior> EndpointBehaviors {
			get { throw new NotImplementedException (); }
		}
Comment 1 Wayne Stewart 2016-05-18 15:24:10 UTC
I also encountered this bug today. I was able to work around it with reflection and found a similar problem with the ClientMessageInspectors property on the System.ServiceModel.Dispatcher.ClientRuntime class.

//Workaround for accessing Behaviors on a ServiceEndpoint
//client.Endpoint.EndpointBehaviors.Add(new EndpointBehavior());

//client is of type System.ServiceModel.ClientBase<T>
var prop = client.Endpoint.GetType()
                 .GetTypeInfo()
                 .GetDeclaredProperty("Behaviors");
var obj = (KeyedCollection<Type, IEndpointBehavior>)prop
                 .GetValue(client.Endpoint);
obj.Add(new EndpointBehavior());

//Workaround for accessing MessageInspectors on a ClientRuntime
//clientRuntime.ClientMessageInspectors.Add(new MessageInspector());

var prop = clientRuntime.GetType()
                        .GetTypeInfo()
                        .GetDeclaredProperty("MessageInspectors");
var obj = (ICollection<IClientMessageInspector>)prop
                        .GetValue(clientRuntime);
obj.Add(new MessageInspector());
Comment 2 Matthew 2016-05-18 15:28:41 UTC
Does this workaround also work on iOS given that it is restrictive on how you can use reflection?
Comment 3 Wayne Stewart 2016-05-18 15:34:02 UTC
I wrote this while working on the iOS version of the project. I have not tested in Android yet.
Comment 4 Matthew 2016-05-24 13:02:48 UTC
Great work Wayne Stewart - I've got this working across Windows RT, Android and iOS using your workaround for Android and iOS and using the .NETCore code for Windows.

Now I'm no longer using APIs that prevent the Windows Store version passing certification.