- 添加项目ConsoleWCFTest
- 添加WCFService、WCFServiceProxy
- 配置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> - 调用
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编程", );
List<Book> list = BookServiceProxy.GetList();
Console.WriteLine("Add:" + result);
Console.WriteLine("GetList:" + list);
Console.ReadLine();
}
}
}