Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4016568
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:45:20+00:00 2026-05-20T09:45:20+00:00

I recently developed a Silverlight application which uses Mark J Millers ClientChannelWrapper<T> to communicate

  • 0

I recently developed a Silverlight application which uses Mark J Millers ClientChannelWrapper<T> to communicate with the WCF service layer (effectively killing the service reference and wrapping IClientChannel and ClientChannelFactory).
Here is the interface:

public interface IClientChannelWrapper<T> where T : class
{
    IAsyncResult BeginInvoke(Func<T, IAsyncResult> function);
    void Dispose();
    void EndInvoke(Action<T> action);
    TResult EndInvoke<TResult>(Func<T, TResult> function);
}

The Wrapper basically takes a generic async service interface (which might have been generated by slsvcutil or hand crafted after the WCF ServiceContract) and wraps the calls to ensure that in case of a channel fault, a new channel gets created.
Typical usage looks like this:

 public WelcomeViewModel(IClientChannelWrapper<IMyWCFAsyncService> service)
    {
        this.service = service;
        this.synchronizationContext = SynchronizationContext.Current ?? new SynchronizationContext();
        this.isBusy = true;
        this.service.BeginInvoke(m => m.BeginGetCurrentUser(new AsyncCallback(EndGetCurrentUser), null));
    }

private void EndGetCurrentUser(IAsyncResult result)
    {
        string strResult = "";
        service.EndInvoke(m => strResult = m.EndGetCurrentUser(result));
        this.synchronizationContext.Send(
                    s =>
                    {
                        this.CurrentUserName = strResult;
                        this.isBusy = false;
                    }, null);
    }

It all works fine but now I’d like to unit test the view models which use the ClientChannelWrapper.
I’ve set up a simple unit test using Moq:

[TestMethod]
    public void WhenCreated_ThenRequestUserName()
    {
        var serviceMock = new Mock<IClientChannelWrapper<IMyWCFAsyncService>>();
        var requested = false;

        //the following throws an exception
        serviceMock.Setup(svc => svc.BeginInvoke(p => p.BeginGetCurrentUser(It.IsAny<AsyncCallback>(), null))).Callback(() => requested = true);


        var viewModel = new ViewModels.WelcomeViewModel(serviceMock.Object);
        Assert.IsTrue(requested);
    }

I get a NotSupportedException:

Unsupported expression: p => p.BeginGetCurrentUser(IsAny(), null).

I’m pretty new to Moq but I guess there is some problem with the ClientChannelWrapper using generic Service interfaces. Trying to wrap my head around this for quite some time now, maybe someone has an idea. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:45:21+00:00Added an answer on May 20, 2026 at 9:45 am

    Sorry to answer my own question, but I finally got it.
    Here are the details:

    As so often, the solution was right in front of me since it was in Mark J Millers concrete implementation of the IClientChannelWrapper. In there he provides two constructors, one taking in a string of the WCF endpoint name (which I use in production code) and a second one:

    public ClientChannelWrapper(T service)
        {
            m_Service = service;
        }
    

    Without further ado, here’s my new test code:

    [TestMethod]
        public void WhenCreated_ThenRequestUserName()
        {
            var IMySvcMock = new Mock<IMyWCFAsyncService>();
            var serviceMock = new ClientChannelWrapper<IMyWCFAsyncService>(IMySvcMock.Object);
            var requested = false;
    
            IMySvcMock.Setup(svc => svc.BeginGetCurrentUser(It.IsAny<AsyncCallback>(), null)).Callback(() => requested = true);
            var viewModel = new ViewModels.WelcomeViewModel(serviceMock);
    
            Assert.IsTrue(requested);
        }
    

    So I basically ignore the interface of the ChannelWrapper and create a new instance of it with the Mock Object of my WCF service interface. Then I setup the call to the service which will be used in the constructor of my view model as shown above. Everything works like a charm now. I hope this is useful for someone since I think the idea the of the ClientChannelWrapper is great for Silverlight <-> WCF communication. Please feel free to comment on this solution!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm recently want to develop an application for my company. I've checked the Silverlight
Recently I just got assigned a project to develop a web application/site that uses
I recently began using BIRT and have developed a report to use with my
I recently started working with Silverlight and immediately noticed the difference between the Silverlight
I've been doing quite large application recently with Java - Swing. Now I'd like
I recently had to work on a project where the previous developer modified the
I recently had a discussion on another forum with another developer and the topic
I've seen quite a few developer job postings recently that include a sentence that
I'm a kinda newbie developer with a few years under my belt. Recently I
I've been a web developer for some time now, and have recently started learning

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.