• Home
  • About
  • BestBloggingIdeas
  • DotNetLearningSource
  • FORUM
  • Joblinks
  • Latest News
  • Policy
  • POSTS
  • SimplySqlServer.Com && SimplyAspDotNet.Com
  • Sitemap

Join Ours Forum

Asp.Net,C#,Ajax,Sql server,silverlight,Javascript codes exambles articles,Programming exambles

RSS Feed
  • Bounty Huge Roll [Amazon Frustration-Free Packaging]
  • XML Introduction to XML VHS Video Training, 1 hr., 32 minutes.
  • The Basic Overview of Windows Mobile Development Asp.Net C#
  • Overview of Sql server extended properties Asp.Net C#
  • How to Use Sql Server Extended properties using visual studio Asp.Net C#
  • Adobe Dreamweaver Templates Accelerate Web Development
  • Top Tips for Web Design Projects
  • How to Achieve a Good Web Design Structure
  • To Use Or Not To Use Website Templates
  • Five Tips to a Successful Website
  • Top 10 Articles,


    Silverlight Datagrid Select Update Delete Insert Asp.Net C#

    Differences Similarities Benefits Between Typed Datasets and Untyped Datasets asp.net c#

    Linq to Sql Introduction Entities Ado.Net C# SqlClasses Attributes Linq Mapping

    Linq Programming/How Linq Works?/Linq Implementation In Asp.Net C# Ado.Net

    Performing Developing Using Investigating Asp.Net 2.0 Ajax Application Development Asp.Net C#

    Hosting/Install Wcf Services in a Windows Service Asp.Net C#

    Connecting Silverlight to Wcf Asp.Net C#

    Silverlight Data Grid Data Binding WCF Asp.Net C#

    Invoking/Accessing/Calling WCF Service Without Adding/Creating Proxy/Reference Asp.Net C#

    Performing Doing Creating Insert Update Delete sql data Using Linq Database Asp.Net C#

    WCF MSMQ programming using netMsmqBinding/How to use netMsmqBinding in WCF

    Posted by on July 11, 2010 Leave a comment (9) Go to comments

    Introduction:
    In this article, i am going to explain about how to use netmsmq binding in wcf
    and how to create message queue programming using wcf.

    Main:
    MSMQ offers support for building distributed applications using queues.WCF supports
    communication through MSMQ queues as the underlying transport for the netMsmq binding.
    The netMsmqBinding binding allows clients to post messages directly to queue and services
    to read messages from a queue.There is no direct communication between the client and
    server,therefore the communication is inherently disconnected.It also means that all
    communication must be one-way.Therefore,all operations must have the IsOneWay=true
    property set on the operation contract.

    See this below demonstration,

    Before starting demonstration first we need to check the microsoft msmq option is
    enabled in yours machine.If not please enable it,
    msmq

    Please check is there any private queue allready created,(If not you can create it here
    itself or you can crete it through coding),

    msmq11

    Now we need to create a wcf application for msmq service and we to host it,

    Goto File — New — Project — select windows tab — select console application
    and named it MsmqDemo (See the below picture)
    hosting8
    Copy and paste the below code in Program.cs,

    using System;
    using System.Configuration;
    using System.Messaging;
    using System.ServiceModel;
     
    namespace MsmqDemo
    {
        // Define a service contract.
        [ServiceContract]
        public interface IEmpService
        {
            [OperationContract(IsOneWay = true)]
            void GetEmpReport(int Empid, string EmpName, int Salary);
     
        }
     
        // Service class which implements the service contract.
        // Added code to write output to the console window
        public class EmpService : IEmpService
        {
            [OperationBehavior]
            public void GetEmpReport(int Empid, string EmpName, int Salary)
            {
     
     
                Console.WriteLine("Employee Details - Employee Id:{0},EmployeeName:{1},EmployeeSalary:{2}",
                     Empid.ToString(), EmpName.ToString(),
                     Salary.ToString());
                Console.WriteLine();
     
     
            }
     
            // Host the service within this EXE console application.
            public static void Main()
            {
            // Get MSMQ queue name from app settings in configuration
            string queueName = ConfigurationManager.AppSettings["queueName"];
     
            // Create the transacted MSMQ queue if necessary.
            if (!MessageQueue.Exists(queueName))
                MessageQueue.Create(queueName, true);
     
            // Get the base address that is used to listen for
             //    WS-MetaDataExchange requests
            // This is useful to generate a proxy for the client
            string baseAddress = ConfigurationManager.AppSettings["baseAddress"];
     
            // Create a ServiceHost for the EmpService type.
            using (ServiceHost serviceHost = new ServiceHost(
                  typeof(EmpService), new Uri(baseAddress)))
            {
     
                    serviceHost.Open();
     
                    Console.WriteLine("The Trade Service is online.");
                    Console.WriteLine("Press <ENTER> to terminate service.");
                    Console.WriteLine();
                    Console.ReadLine();
                    // Close the ServiceHost to shutdown the service.
                    serviceHost.Close();
              }
            }
        }
        }

    Next right click solution and add new item and select application Configuration file and paste the
    below code,

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="queueName" value=".\private$\EmpQueue"/>
        <add key="baseAddress" value="net.msmq://localhost/private/EmpQueue"/>
      </appSettings>
      <system.serviceModel>
        <services>
          <service
            behaviorConfiguration="MyServiceTypeBehaviors"
             name="MsmqDemo.EmpService">
            <endpoint address="net.msmq://localhost/private/TradeQueue"
                       binding="netMsmqBinding"
                       bindingConfiguration="DomainlessMsmqBinding"
                       contract="MsmqDemo.IEmpService"
                              />
            <!-- Add the following endpoint.  -->
            <!-- Note: your service must have an http base
                             address to add this endpoint. -->
            <endpoint contract="IMetadataExchange" binding=
                             "mexHttpBinding" address="mex" />
     
          </service>
        </services>
     
        <behaviors>
          <serviceBehaviors >
            <behavior name="MyServiceTypeBehaviors">
              <serviceMetadata httpGetEnabled ="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
     
        <bindings>
          <netMsmqBinding>
            <binding name="DomainlessMsmqBinding" >
              <security>
                <transport
                  msmqAuthenticationMode="None"
                  msmqProtectionLevel="None"/>
              </security>
            </binding>
     
          </netMsmqBinding>
        </bindings>
      </system.serviceModel>
    </configuration>

    Now Build it and run

    so now we hosted the wcf application,

    Next create one client application,
    Goto File — New — Project — select windows tab — select console application
    and named it MsmqClient (See the below picture)
    client3
    Next we need to create a proxy for client application,for creating proxy
    please goto .Net commandline and type the below

    svcutil net.msmq://localhost/private/EmpQueue /out:myproxy.cs /config:app.config

    Now paste the below code in client application,

    using System;
    using System.Data;
    using System.Messaging;
    using System.Configuration;
    using System.Web;
    using System.Transactions;
    namespace MsmqClient
    {
        class Client
        {
            static void Main()
            {
                // Create a proxy for the client
                using (TradeServiceClient proxy = new TradeServiceClient())
                {
                    //Create a transaction scope.
                    using (TransactionScope scope = new TransactionScope
                         (TransactionScopeOption.Required))
                    {
                        Console.WriteLine("Seniour Manager Details");
                        proxy.GetEmpReport("100", "Peter", "$6000");
     
                        Console.WriteLine("Assistant Manager Details");
     
                        proxy.GetEmpReport("98", "Michelle", "$3000");                   
     
                        // Complete the transaction.
                        scope.Complete();
                    }
                }
            }
        }
     
    }

    Now build it and run,

    Thatsit…

    Conclusion:
    Hope this helps,
    Happy coding.

    WCF
    ← create/perform duplex service contracts in wcf/Code for wcf duplex service
    Implement/perform/add/use linq into/against Sql,xml,dataset,Objects asp.net →

    Learn Easily Using Video Tutorials


    How to choose the right Java IDE – explained Eclipse NetBeans BlueJ

    Developing/Creating/Performing/Configuring Java Applications Using Eclipse IDE

    Step By Step Guide for Download/Install Configure Eclipse IDE for Java

    Editing data with the GridView control Asp.Net C#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Best way to prepare asp.net Interview - Success Stories

    Download Important Questions and PPT's:

    Sql Server Important Questions Online free download

    Dotnet Important Questions Online free download

    Exploring Linq to Sql Process Flow

    Learn how to perform silverlight programming

    Learn OOPs concepts in better and well manner

    Learn Ajax in better and well manner

    Leave a comment

    9 Comments.

    1. grants for women July 12, 2010 at 3:46 pm

      well written blog. Im glad that I could find more info on this. thanks

    2. Occupational Therapy July 17, 2010 at 8:56 pm

      What a great resource!

    3. Linga Reddy Sama September 16, 2010 at 8:24 am

      I have build one console application for service using your code and i’ve run the application then getting some exception like below

      Could not find a base address that matches scheme http for the endpoint with binding MetadataExchangeHttpBinding. Registered base address schemes are [net.msmq].

      Could you please help me out in this.

    4. james September 16, 2010 at 1:49 pm

      Hi Sama,

      See the below in app.config

      if you are using net.msmq endpoint then its not needed,

    5. Ashish November 4, 2010 at 12:03 pm

      Good article and it works fine.

      messages gets queued to server

      now think of payment situation where client submitted the payment to server using msmq bining

      next thing my server should respond back to client that ok your payment has been processed.

      so it would be like reading the messages from server and respond back

      so how to read those messages..

      any help!

    6. James November 8, 2010 at 5:56 pm

      Ashish,just adapt duplex concept,once the payment is processed raise the callback and inform client,for details about duplex please visit my another article “http://netprogramminghelp.com/wcf/how-to-createperform-duplex-service-contracts-in-wcf/’

    7. Srinivas February 7, 2011 at 1:18 pm

      Hi Lingareddy
      i too have same problem,i solved my problem,

      write instead of

    8. graphic design careers February 17, 2011 at 4:29 pm

      I totally agree with everything you have mentioned. Actually, I browsed through your various other blogposts and I do think that you’re certainly right. Congrats with this particular website.

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    *

    *


    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    Trackbacks and Pingbacks:

    • a few approaches to be able to ignite ones PC’s performance without the need of spending a penny | Forum on China Wholesale Lots - Pingback on 2010/07/12/ 15:24

    Enter your email address:

    Delivered by FeedBurner

    • Recent Posts

      • Bounty Huge Roll [Amazon Frustration-Free Packaging]
      • XML Introduction to XML VHS Video Training, 1 hr., 32 minutes.
      • The Basic Overview of Windows Mobile Development Asp.Net C#
      • Overview of Sql server extended properties Asp.Net C#
      • How to Use Sql Server Extended properties using visual studio Asp.Net C#
    • Search by Tags!

      Application AspNet Basic between Black Bluetooth Build Business Collection Consultants Design Development Downloading effective Excel Experts Generics Implement Installing Interview Logic Management Microsoft Minutes Object Outlook Professional Programmer Programming Project Projects Questions Ready Select Server Services Silverlight Source Strings Studio Through using Visual Website Wordpress
    • Archives

      • August 2011
      • June 2011
      • May 2011
      • April 2011
      • March 2011
      • February 2011
      • December 2010
      • November 2010
      • October 2010
      • September 2010
      • August 2010
      • July 2010
      • June 2010
      • May 2010
      • April 2010
      • March 2010
      • February 2010
      • January 2010
      • December 2009
      • November 2009
      • October 2009
      • September 2009

    Copyright © 2012 NetProgrammingHelp.com

    Δ Top