Click here to Skip to main content
15,894,176 members
Articles / Programming Languages / Visual Basic

Microsoft Robotics Studio (MSRS) and Windows Communication Foundation (WCF) Work Together

Rate me:
Please Sign up or sign in to vote.
4.80/5 (36 votes)
20 Oct 20066 min read 64.3K   1.1K   57  
A sample of collaboration between MSRS service and WinForm application by means of WCF services.
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.Reflection;


namespace Robotics.Coordinator
{
    /// <summary>
    /// WCF server object
    /// </summary>
    public class CoordinatorServiceType : ICoordinator
    {
        static readonly private Type[] types = null;

        static CoordinatorServiceType()
        {
            types = Assembly.GetExecutingAssembly().GetTypes();
        }

        /// <summary>
        /// Implement [OperationContract] ICoordinator.Command()
        /// 
        /// </summary>
        public object Command(string commandName, object commandData)
        {
            IDssCommand dssCommand = null;
            Type commandType = GetCommandTypeByName(commandName);
            if (null != commandType)
                dssCommand = Activator.CreateInstance(commandType) as IDssCommand;

            return (null != dssCommand)
                ? dssCommand.DoCommand(commandData)
                : string.Format("{0}: Command \"{0}\" is not implemented in DSS Coordinator.", commandName);
        }

        private Type GetCommandTypeByName(string commandName)
        {
            Type commandType = null;
            foreach (Type type in types)
                if (type.Name.ToLower() == commandName.ToLower())
                {
                    try
                    {
                        commandType = type;
                        break;
                    }
                    catch
                    {
                    }
                }

            return commandType;
        }
    }

    [ServiceContract]
    public interface ICoordinator
    {
        [OperationContract]
        object Command(string commandName, object commandData);
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
Israel Israel


  • Nov 2010: Code Project Contests - Windows Azure Apps - Winner
  • Feb 2011: Code Project Contests - Windows Azure Apps - Grand Prize Winner



Comments and Discussions