消費WCF服務託管在Windows服務


如何通過消耗託管在Windows服務的WCF服務步驟過程, 詳細的編碼和指令表示如下。

一旦成功,我們可以建立代理類業務,並開始使用用戶端應用程式。這裡,顯示使用IIS託管型消費。

Consuming WCF hosted in Windows Service

 

新增 ServiceModel 參考。

Consuming WCF hosted in Windows Service

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespaceWindowServiceClient
{
  classProgram
  {
     staticvoid Main(string[] args)
     {
        //Creating Proxy for the MyService
        MyServiceClient client = newMyServiceClient();
        Console.WriteLine("Client calling the service...");
        Console.WriteLine("Sum of two numbers 5,6");
        Console.WriteLine(client.Add(5, 6));
        
        Console.WriteLine("Subtraction of two numbers 6,5");
        Console.WriteLine(client.Add(6, 5));
        
        Console.WriteLine("Multiplication of two numbers 6,5");
        Console.WriteLine(client.Add(6, 5));
        
        Console.WriteLine("Division of two numbers 6,3");
        Console.WriteLine(client.Add(6, 3));

        Console.Read();
     }
  }
}

 

Consuming WCF hosted in Windows Service