0

How can i add wcf service at runtime in my winform UI. I created a wcf service which return running processes of hosted machine. I want to add the hosted machine service in my winform application.

Enigma34
  • 347
  • 2
  • 7
  • 17
  • 1
    when you say you want to ADD wcf service at runtime do you mean you dont the exact end point but you know the operations exposed by the service – bhupendra patel Jun 03 '12 at 21:58
  • the operations are not exposed. but the opertaions on each services are same can i use them by chaning the hosting address ? – Enigma34 Jun 03 '12 at 22:15
  • 1
    if Operations are not exposed how will you call them? Even if the Operations are same on all the service when you call the Operation on that particular service the operations need to be exposed. – bhupendra patel Jun 03 '12 at 22:23
  • i am new to wcf. can you please refer any simple and easy example for wcf discovery. it will be easy for me to understand the concept. – Enigma34 Jun 03 '12 at 22:37
  • Sure, can i first ask you why do you want to add the service at run time? If you know what operations i.e. Service Contract the service is going to expose and you know where it is hosted ( if it is going to be hosted on same machine) then using WCF discovery is OTT. WCF discovery is used when you have several instances of services running and you are not sure which one will be running when your client will come online. – bhupendra patel Jun 03 '12 at 23:46

3 Answers3

2

You need to change endpoints dynamically at runtime, so You need WCF Discovery.

Structure :

WCF Consumer(s) <---> WCF Discovery Service <---> WCF Service(s)

Implementation :

  1. How to: Implement a Discovery Proxy
  2. How to: Implement a Discoverable Service that Registers with the Discovery Proxy
  3. How to: Implement a Client Application that Uses the Discovery Proxy to Find a Service

Topology :

  • Start Discovery Service [ Structure BackBone ]
  • Start Service(s) [ Every Service will ANNOUNCE its startup to the Discovery Service ]
  • Start Client(s) [ Every Client will DISCOVER ( FIND & RESOLVE ) Services' endpoints from the Discovery Service ]

Notes :

  • Discovery process uses UDP ( Check your Firewall, It can block connections )
  • Services MUST announce their startup, thus Self-Hosted services is OK, but IIS-Hosted 5/6 ones is NOT because they started automatically when 1st invoke happends !

Solving IIS-Hosted 5/6 Issue :

So that you can start your IIS-Hosted 5/6 services manually without being invoked for the first time


You can also use WCF Routing Service.

BROTHER TIP :
Don't go far for a Serverless ( No-BackBone, No-BootleNeck, Fully-Distributed, .. etc ) ideal topology, this'll blowup your head and got you crazy :D

For a beginner, I suggest you this tutorial [ WCF Tutorials ]

Ahmed Ghoneim
  • 6,834
  • 9
  • 49
  • 79
1

not sure what you are trying to do here. But you need to know two things to call the WCF service 1) Service Contract 2) End Point. Now there is no escaping from Service Contract as you need to know what all operations you can consume. However, with WCF 4 there is a new feature called WCF discovery which helps you determine the end point dynamically i.e. at RunTime. Refer to following link http://msdn.microsoft.com/en-us/library/dd456791.aspx

bhupendra patel
  • 3,139
  • 1
  • 25
  • 29
0

If I understand you question properly you need some code that will add service in run-time without using any configuration in *.config file and *.svc files.

See that sample:

    Uri baseAddress = new Uri("http://localhost:8080/hello");
    // Create the ServiceHost.
    using (ServiceHost host = new ServiceHost(typeof(HelloWorldService), baseAddress))
    {
        // Enable metadata publishing.
    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
    host.Description.Behaviors.Add(smb);

    // Open the ServiceHost to start listening for messages. Since
    // no endpoints are explicitly configured, the runtime will create
    // one endpoint per base address for each service contract implemented
    // by the service.
    host.Open();

    Console.WriteLine("The service is ready at {0}", baseAddress);
    Console.WriteLine("Press <Enter> to stop the service.");
    Console.ReadLine();

    // Close the ServiceHost.
    host.Close();
}

It creates self-hosted service in console app.

http://msdn.microsoft.com/en-us/library/ms731758.aspx

Is that what you asked?

Dmitry Harnitski
  • 5,838
  • 1
  • 28
  • 43