How to add wcf service at runtime

前端 未结 3 1579
没有蜡笔的小新
没有蜡笔的小新 2021-01-16 16:27

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

相关标签:
3条回答
  • 2021-01-16 17:04

    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 :

    • By Extending Hosting Using ServiceHostFactory

    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 ]

    0 讨论(0)
  • 2021-01-16 17:15

    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

    0 讨论(0)
  • 2021-01-16 17:15

    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?

    0 讨论(0)
提交回复
热议问题