zoukankan      html  css  js  c++  java
  • WCF

    https://www.tutorialspoint.com/wcf/wcf_consuming_service.htm

    WCF services allow other applications to access or consume them. A WCF service can be consumed by many ways depending on the hosting type. Here, we are explaining the step-by-step method to consume a WCF service for each of the following popular hosting options:

    • Consuming WCF Service hosted in IIS 5/6
    • Consuming WCF Service that is self-hosted
    • Consuming WCF Service hosted in Windows Activation Service
    • Consuming WCF Service hosted in Windows Service

    Consuming WCF Service Hosted in IIS 5/6

    The process of consumption of a WCF service hosted in IIS 5/6 is discussed below in detail. In addition, the discussion includes how to create proxy and console applications.

    Step-1: Once a service is hosted in IIS, we have to consume it in client applications. Before creating the client application, we need to create a proxy for the service.

    This proxy is used by the client application to interact with the service. To create a proxy, run Visual Studio 2008 command prompt.

    Using service utility, we can create the proxy class and its configuration information.

    svcutilhttp://localhost/IISHostedService/Service.svc

    After executing this command, we will get two files generated in the default location.

    • MyService.cs – Proxy class for the WCF service

    • output.config – Configuration information about the service

    Step-2: Now, we will start creating the Console application using Visual Studio 2008 (Client application).

    Step-3: Add the reference 'System.ServiceModel'; this is the core dll for WCF.

    Step-4: Create a Proxy class.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace MyServiceClient
    {
       Class Program
       {
          Static void Main(string[] args)
          {
             // Creating Proxy for the MyService
             ServiceClient Client = newServiceClient();
             Console.WriteLine("Client calling the service...");
             Console.WriteLine("Hello Ram");
             Console.Read();
          }
       }
    }
    

    The output appears as follows:

  • 相关阅读:
    Python 字符串(一)
    UVA 11552 四 Fewest Flops
    UVA 10534 三 Wavio Sequence
    UVA 1424 二 Salesmen
    UVA 11584 一 Partitioning by Palindromes
    CodeForces 549G Happy Line
    CodeForces 451C Predict Outcome of the Game
    CodeForces 567C Geometric Progression
    CodeForces 527B Error Correct System
    CodeForces 552C Vanya and Scales
  • 原文地址:https://www.cnblogs.com/chucklu/p/4630514.html
Copyright © 2011-2022 走看看