question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NetCoreClient throws exception "type is not a ServiceContract"

See original GitHub issue

I add a small service to NetCoreClient and NetCoreService, when the service factory is created from the NetCoreClient

var factory = new ChannelFactory<ISchedulerService>(new BasicHttpBinding(), new EndpointAddress("http://localhost:8080/basichttp"));

an exception is thrown with the message:

Attempted to get contract type for ISchedulerService, but that type is not a ServiceContract, nor does it inherit a ServiceContract.

Source=System.Private.ServiceModel StackTrace: at System.ServiceModel.Description.ServiceReflector.GetContractTypeAndAttribute(Type interfaceType, ServiceContractAttribute& contractAttribute) at System.ServiceModel.Description.TypeLoader.LoadContractDescriptionHelper(Type contractType, Type serviceType, Object serviceImplementation) at System.ServiceModel.ChannelFactory1.CreateDescription() at System.ServiceModel.ChannelFactory.InitializeEndpoint(Binding binding, EndpointAddress address) at System.ServiceModel.ChannelFactory1…ctor(Binding binding, EndpointAddress remoteAddress) at NetCoreClient.Program.Main(String[] args) in C:\Github\CoreWCF\src\Samples\NetCoreClient\Program.cs:line 23

To do this I added a netstandard 2.0 library TaskLibrary to CoreWCFWithSamples.sln. Then I added a definition for two types:

ISchedulerService

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;

using CoreWCF;

namespace TaskLibrary
{

    [ServiceContract]
    [ServiceKnownType ( typeof ( TaskTypes ) )]

    public interface ISchedulerService
    {
        #region Methods

        [OperationContract]
        List<TaskTypes> GetSupportedTaskTypes  ();

        #endregion
    }
}

TaskTypes


using System;
using System.Collections.Generic;
using System.Text;

namespace TaskLibrary
{
    public enum TaskTypes
    {
        ManualTask,
        AutoTask,
        RepetitiveTask

    }
}

Next I added TaskLibrary references to NetCoreClient and NetCoreServer.

To NetCoreServer startup.cs the Configure code was modified to:

        public void Configure ( IApplicationBuilder app, IHostingEnvironment env )
        {
            app.UseServiceModel ( builder =>
              {
                  builder.AddService<SchedulerService> ();
                  builder.AddServiceEndpoint<SchedulerService, TaskLibrary.ISchedulerService> ( new BasicHttpBinding (), "/basichttp" );
              } );
        }

To NetCoreClient program.cs the Main code was modified as shown below. After NetCoreServer is started up, then NetCoreClient is started and the exception at the start of the post is generated.

What am I doing wrong?


        static void Main(string[] args)
        {
            /*
            var factory = new ChannelFactory<Contract.IEchoService>(new NetTcpBinding(), new EndpointAddress("net.tcp://localhost:8808/nettcp"));
            factory.Open();
            var channel = factory.CreateChannel();
            ((IClientChannel)channel).Open();
            Console.WriteLine("net.tcp Echo(\"Hello\") => " + channel.Echo("Hello"));
            ((IClientChannel)channel).Close();
            factory.Close();
            */

            
            var factory = new ChannelFactory<ISchedulerService>(new BasicHttpBinding(), new EndpointAddress("http://localhost:8080/basichttp"));
            factory.Open();
            var channel = factory.CreateChannel();
            ((IClientChannel)channel).Open();

            var taskTypes = channel.GetSupportedTaskTypes ();

            //Console.WriteLine("http Echo(\"Hello\") => " + channel.Echo("Hello"));


            ((IClientChannel)channel).Close();
            factory.Close();
            

            Console.WriteLine("Hit enter to exit");
            Console.ReadLine();
        }

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:33 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
mconnewcommented, Jan 2, 2020

Yes, that is the problem. ChannelFactory needs to use System.ServiceModel.ServiceContractAttribute and CoreWCF needs to use CoreWCF.ServiceContractAttribute. I actually have a PR right now to allow CoreWCF to use the S.SM attributes so you can use a single common contract if you want (#87). I’m just waiting on a code review. So you can either do the juggling with the two namespaces or you can wait until someone has reviewed my changes and then pick up the latest packages which allows you to just use S.SM.ServiceContract if that’s what you would prefer.

0reactions
mconnewcommented, Feb 11, 2021

There isn’t. Do you see value in having a CoreWCF.All package? Over time we might end up with quite a few packages for various features.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Service 'Service' does not implement a ServiceContract type
My understanding that I have the interface containing the servicecontract in place implemented but the error message is telling me not.
Read more >
Untitled
Service Contract in WCF - c-sharpcorner.com ... NetCoreClient throws exception "type is not a ServiceContract" … System.NotSupportedException when using Hot ...
Read more >
Using WCF With .NET Core - The Seeley Coder
Running this in a netcore application that targets netcore will throw an exception because it cannot load the configuration. Running in a ...
Read more >
How to: Declare Faults in Service Contracts - WCF ...
Create a service contract that specifies a SOAP fault ... In managed code, exceptions are thrown when error conditions occur.
Read more >
Don't throw exceptions in C#. Do this instead - YouTube
The code rapidly becomes unwieldy because you have to check the result at every exit and if the return type of the calling...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found