WCF Communication in netstandard2.0 (IServiceBehavior and other class which are not supported)

Viewed 531

I have a group of services that are written in WCF. This is a whole logic which cannot be changed and rewritten to another technology.

I want to create an application in .NET Core 2.1 and connect to WCF services. I am using library which has clients for all services with custom communication, bindings, endpointbehaviors etc. This library is written in .NET Framework v4.7.2, so if I want to use it in my .NET Core App I need to add target to the .net standard 2.0.

I did this and now I am having a problem as some classes are not supported in .netstandard2.0.

public class UserInfoBehavior : Attribute, IServiceBehavior, IEndpointBehavior
{}

For Example above class is used for adding EndpointBehaviors to my Channel:

public DashboardServiceClient(InstanceContext instanceContext, string endpointConfigurationName, string endpointAddress)
        : base(instanceContext, endpointConfigurationName, endpointAddress)
{
       base.ChannelFactory.Endpoint.EndpointBehaviors.Add(new UserInfoBehavior());
}

The problem is that IServiceBehavior is not available in .netstandard 2.0. Do you know some equivalent for this? There are more classes which I am using and are not supported:

  • RemoteEndpointMessageProperty,
  • Method Open() which is in ClientBase,
  • ChannelDispatcher,
  • and also EndpointDispatcher which is empty class in System.ServiceModel.Dispatcher

I am wondering if it is possible to target it to netstandard

1 Answers

You can call the wcf service by adding a connected reference. enter image description here Select the WCF Web Service Reference Provider. enter image description here Enter your WCF Service URI: enter image description here Check all quotes and finish. enter image description here You can see this folder in the client.

enter image description here

Just call it in the client, and you can acess the method in WCF Service.

 static void Main(string[] args)
    {
        ServiceReference2.Service1Client service1Client = new ServiceReference2.Service1Client();

        var t=service1Client.GetDataAsync(15);
        Console.WriteLine(t.Result); 
        Console.ReadKey();
    }

You can also refer to this link to call the wcf service: Use the WCF Web Service Reference Provider Tool

Related