Microsoft.CodeDom missing when referencing WCF service who has a callback contract.

Bernard Lessard 1 Reputation point
2022-01-17T22:47:38.953+00:00

if i use a CallbackContract in WCF (.net framework 4.8)

[ServiceContract(CallbackContract = typeof(IEventsService))]

When a service reference in my client app (WPF .Net6.0) the reference.cs file has some lib missing (Microsoft.CodeDom)

I fell like its a bug happen in the tool to generate the client proxy

Anybody had same problem ?

Thanks for your help.

Developer technologies Windows Presentation Foundation
Developer technologies .NET Other
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2022-01-18T03:13:20.317+00:00

    Hi @Bernard Lessard ,
    I think you may be missing the System.CodeDom package, if you add it I suggest you try to regenerate the reference.
    165875-1.png
    166267-1.png
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Bernard Lessard 1 Reputation point
    2022-01-18T22:58:55.047+00:00

    Thanks for the help.. unfortunately now I'm missing : Microsoft.CodeDom.Compiler
    And I cannot find it in nugets...


  3. Bernard Lessard 1 Reputation point
    2022-01-19T21:07:22.357+00:00

    Actually when I have a simple Wcf service it works fine.
    But when I have a duplex one, that's when it's not working.
    I wanted to have a call back in my apps, but I'll just not use it then..
    But its working fine when using .Net Framework 4.8 both client and server.

    0 comments No comments

  4. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2022-01-20T09:30:17.437+00:00

    Hi @Bernard Lessard ,
    .NET currently does not support wcf, .NET Foundation provides a client port, you can see the documentation.
    https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-5#windows-communication-foundation
    About duplex:https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/duplex-services
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  5. Bernard Lessard 1 Reputation point
    2022-01-20T16:49:40.26+00:00

    // I found a way to fix my problem.. it took me a week of research
    // So here it is:
    // How to generate WCF Service (.Net Framework 4.8) proxy in client (.Net 6.0):

    // If using a callback I need duplex communication
    [ServiceContract(CallbackContract = typeof(IEventsService))]
    // Just do as explain here but dont expect it to work for Client .Net 6.0 it will only work for client .net Framework 4.8 as Wcf service is .Net Framework 4.8
    //https://www.codeproject.com/articles/663333/understanding-events-in-wcf#:~:text=Background%20While%20events%20in%20WCF%20are%20nothing%20more,typical%20relationship%20between%20a%20client%20and%20a%20service.

    // so here is what I need to do:
    // Use netHttpBinding for duplex
    // Put this on web.config of your Wcf service
    <service name="HomeManagerWcfService.HomeManagerService" behaviorConfiguration="HomeManagerServiceBehavior">
    <host>
    <baseAddresses>
    <add baseAddress="http://localhost:53318/HomeManagerService"/>
    </baseAddresses>
    </host>

    <endpoint address="" binding="netHttpBinding" contract="HomeManagerWcfService.IHomeManagerService"/>
    <!--<endpoint address="" binding="wsDualHttpBinding" contract="HomeManagerWcfService.IHomeManagerService"/>-->
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
    </services>

    <behaviors>
    <serviceBehaviors>
    <!-- HomeManagerService Behavior -->
    <behavior name="HomeManagerServiceBehavior">
    <serviceMetadata httpGetEnabled="true"/>
    <serviceDebug includeExceptionDetailInFaults="true "/>
    </behavior>
    </serviceBehaviors>
    </behaviors>

    // Generate files for your client proxy on VisualStudio.Tools.Command line.Developer command prompt
    svcutil http://localhost:53318/HomeManagerService.svc
    //copy both files generated in your client project.
    // if using the VS UI generator (Managed connected service) it won't work, there is a bug in it.

    // I also need System.ServiceModel.Http
    // & I need System.ServiceModel.Duplex
    // in the client
    // use NetHttpBinding for duplex communication
    // Use IHomeManagerServiceCallback to implement the callback function where you want it to run the callback
    InstanceContext iCntxt = new InstanceContext(this); // "this" is where i implement the callback for my case
    var endpointAddress = new EndpointAddress("http://localhost:53318/HomeManagerService.svc");
    var binding = new NetHttpBinding();
    var factory = new DuplexChannelFactory<IHomeManagerService>(iCntxt, binding, endpointAddress);
    var clientWCF = factory.CreateChannel();

    EmailMessage emailMessage = new EmailMessage();
    emailMessage.Name = "ww23";
    emailMessage.Body = "SSWDDW223";
    emailMessage.EmailAddress = "EMAIL AD dsf2223";

    clientWCF.SubscribeCalculatedEvent(); // where we register to the event on the server
    clientWCF.AddEmail(emailMessage); // the callback event call is in this function on the server

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.