首页 > 技术文章 > WCf客户端测试

wzq806341010 2014-03-16 18:30 原文

  1. 添加项目ConsoleWCFTest
  2. 添加WCFService、WCFServiceProxy
  3. 配置App.config
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
      </startup>
    
      <system.serviceModel>
        <client>
          <endpoint name="bookInfo1" address="net.tcp://localhost:8082/BookService" binding="netTcpBinding"
                    contract="WCFService.IBookService" >
          </endpoint>
          <endpoint name="bookInfo" address="http://localhost:8081/service/basic" binding="basicHttpBinding" contract="WCFService.IBookService">
          </endpoint>
        </client>
      </system.serviceModel>
    </configuration>

     

  4. 调用
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using WCFService.Models;
    using WCFServiceProxy;
    
    namespace ConsoleWCFTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                var result = BookServiceProxy.Add("WCF编程", 12);
                List<Book> list = BookServiceProxy.GetList();
                Console.WriteLine("Add:" + result);
                Console.WriteLine("GetList:" + list);
                Console.ReadLine();
            }
        }
    }

     

推荐阅读