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 6029569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:54:20+00:00 2026-05-23T04:54:20+00:00

We have an old Silverlight UserControl + WCF component in our framework and we

  • 0

We have an old Silverlight UserControl + WCF component in our framework and we would like to increase the reusability of this feature. The component should work with basic functionality by default, but we would like to extend it based on the current project (without modifying the original, so more of this control can appear in the full system with different functionality).

So we made a plan, where everything looks great, except one thing. Here is a short summary:

Silverlight UserControl can be extended and manipulated via ContentPresenter at the UI and ViewModel inheritance, events and messaging in the client logic.

Back-end business logic can be manipulated with module loading.

This gonna be okay I think. For example you can disable/remove fields from the UI with overriden ViewModel properties, and at the back-end you can avoid some action with custom modules.

The interesting part is when you add new fields via the ContentPresenter. Ok, you add new properties to the inherited ViewModel, then you can bind to them. You have the additional data. When you save base data, you know it’s succeeded, then you can start saving your additional data (additional data can be anything, in a different table at back-end for example). Fine, we extended our UserControl and the back-end logic and the original userControl still doesn’t know anything about our extension.

But we lost transaction. For example we can save base data, but additional data saving throws an exception, we have the updated base data but nothing in the additional table. We really doesn’t want this possibility, so I came up with this idea:

One WCF call should wait for the other at the back-end, and if both arrived, we can begin cross thread communication between them, and of course, we can handle the base and the additional data in the same transaction, and the base component still doesn’t know anything about the other (it just provide a feature to do something with it, but it doesn’t know who gonna do it).

I made a very simplified proof of concept solution, this is the output:

1 send begins

Press return to send the second piece

2 send begins

2 send completed, returned: 1

1 send completed, returned: 2

Service

namespace MyService
{
    [ServiceContract]
    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class Service1
    {

        protected bool _sameArrived;

        protected Piece _same;

        [OperationContract]
        public Piece SendPiece(Piece piece)
        {
            _sameArrived = false;
            Mediator.Instance.WaitFor(piece, sameArrived);

            while (!_sameArrived)
            {
                Thread.Sleep(100);
            }

            return _same;
        }

        protected void sameArrived(Piece piece)
        {
            _same = piece;
            _sameArrived = true;
        }
    }
}

Piece (entity)

namespace MyService
{
    [DataContract]
    public class Piece
    {
        [DataMember]
        public long ID { get; set; }

        [DataMember]
        public string SameIdentifier { get; set; }
    }
}

Mediator

namespace MyService
{
    public sealed class Mediator
    {
        private static Mediator _instance;

        private static object syncRoot = new Object();

        private List<Tuple<Piece, Action<Piece>>> _waitsFor;

        private Mediator()
        {
            _waitsFor = new List<Tuple<Piece, Action<Piece>>>();
        }

        public static Mediator Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (syncRoot)
                    {
                        _instance = new Mediator();
                    }
                }

                return _instance;
            }
        }

        public void WaitFor(Piece piece, Action<Piece> callback)
        {
            lock (_waitsFor)
            {
                var waiter = _waitsFor.Where(i => i.Item1.SameIdentifier == piece.SameIdentifier).FirstOrDefault();

                if (waiter != null)
                {
                    _waitsFor.Remove(waiter);
                    waiter.Item2(piece);
                    callback(waiter.Item1);
                }
                else
                {
                    _waitsFor.Add(new Tuple<Piece, Action<Piece>>(piece, callback));
                }
            }
        }
    }
}

And the client side code

    namespace MyClient
    {
        class Program
        {
            static void Main(string[] args)
            {
                Client c1 = new Client(new Piece()
                {
                    ID = 1,
                    SameIdentifier = "customIdentifier"
                });

                Client c2 = new Client(new Piece()
                {
                    ID = 2,
                    SameIdentifier = "customIdentifier"
                });

                c1.SendPiece();
                Console.WriteLine("Press return to send the second piece");
                Console.ReadLine();
                c2.SendPiece();
                Console.ReadLine();
            }
        }

        class Client
        {
            protected Piece _piece;

            protected Service1Client _service;

            public Client(Piece piece)
            {
                _piece = piece;
                _service = new Service1Client();
            }

            public void SendPiece()
            {
                Console.WriteLine("{0} send begins", _piece.ID);
                _service.BeginSendPiece(_piece, new AsyncCallback(sendPieceCallback), null);
            }

            protected void sendPieceCallback(IAsyncResult result)
            {
                Piece returnedPiece = _service.EndSendPiece(result);
                Console.WriteLine("{0} send completed, returned: {1}", _piece.ID, returnedPiece.ID);
            }
        }
    }

So is it a good idea to wait for another WCF call (which may or may not be invoked, so in a real example it would be more complex), and process them together with cross threading communication? Or not and I should look for another solution?

Thanks in advance,

negra

  • 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-23T04:54:21+00:00Added an answer on May 23, 2026 at 4:54 am

    If you want to extend your application without changing any existing code, you can use MEF that is Microsoft Extensibility Framework.

    For using MEF with silverlight see: http://development-guides.silverbaylabs.org/Video/Silverlight-MEF

    I would not wait for 2 WCF calls from Silverlight, for the following reasons:

    • You are making your code more complex and less maintainable
    • You are storing business knowledge, that two services should be called together, in the client

    I would call a single service that aggreagated the two services.

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

Sidebar

Related Questions

I have several old 3.5in floppy disks that I would like to backup. My
We have an old project written using Managed C++ syntax. I would like to
We have a Silverlight solution that worked fine on our old computers. It was
I have a Silverlight control with a Content field. I'd like to be able
For someone who's been down this road, please share your breadcrumbs. I have old
I have a snippet to create a 'Like' button for our news site: <iframe
We have old .net 1.1 project that is using a third party component. Aparently
I have an old WCF 3.5 RESTful service that was at: http://www.mydomain.com/rest/Service.svc I have
I have an old .dot file with a few dozen styles in it. I
I have a old website that generate its own RSS everytime a new post

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.