频 道 直 达 - 新闻 - 读书 - 培训 - 教程 - 前沿 - 组网 - 系统应用 - 安全 - 编程 - 存储 - 操作系统 - 数据库 - 服务器 - 专题 - 产品 - 案例库 - 技术圈 - 博客 - BBS
51CTO.COM_中国领先的IT技术网站
找资料:

WCF体验之旅(2):Endpoint Overview(3)

作者: Artech 出处:博客园 2008-03-13 10:18    砖    好    评论   进入论坛
阅读提示:WCF实际上是构建了一个框架,这个框架实现了在互联系统中各个Application之间如何通信。使得Developers和Architect在构建分布式系统中,无需在考虑如何去实现通信相关的问题,更加关注与系统的业务逻辑本身。

<%@ ServiceHost Language="C#" Debug="true" Service="Artech.WCFService.Service.GeneralCalculatorService" %>5、Client: Artech.WCFService.Client/ GeneralCalculatorClient.cs & Program.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels;
using Artech.WCFService.Contract;

namespace Artech.WCFService.Client
{
class GeneralCalculatorClient:ClientBase,IGeneralCalculator
{
public GeneralCalculatorClient()
: base()
{ }

public GeneralCalculatorClient(string endpointConfigurationName)
: base(endpointConfigurationName)
{ }

public GeneralCalculatorClient(Binding binding, EndpointAddress address)
: base(binding, address)
{ }

IGeneralCalculator Members#region IGeneralCalculator Members

public double Add(double x, double y)
{
return this.Channel.Add(x, y);
}

#endregion
}
}

using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels;
using Artech.WCFService.Contract;

namespace Artech.WCFService.Client
{
class Program
{
static void Main()
{
try
{
//InvocateCalclatorServiceViaCode();

InvocateCalclatorServiceViaConfiguration();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

Console.Read();   
}

static void InvocateCalclatorServiceViaCode()
{
Binding httpBinding = new BasicHttpBinding();
Binding tcpBinding = new NetTcpBinding();

EndpointAddress httpAddress = new EndpointAddress

("http://localhost:8888/generalCalculator");
EndpointAddress tcpAddress = new EndpointAddress("net.tcp:

//localhost:9999/generalCalculator");
EndpointAddress httpAddress_iisHost = new EndpointAddress

("http://localhost/wcfservice/GeneralCalculatorService.svc");

Console.WriteLine("Invocate self-host calculator service ");

Invocate Self-host service#region Invocate Self-host service
using (GeneralCalculatorClient calculator_http = new GeneralCalculatorClient

(httpBinding, httpAddress))
{
using (GeneralCalculatorClient calculator_tcp = new GeneralCalculatorClient

(tcpBinding, tcpAddress))
{
try
{
Console.WriteLine("Begin to invocate calculator service via http

transport

");
Console.WriteLine("x + y = {2} where x = {0} and y = {1}", 1, 2,

calculator_http.Add(1, 2));

Console.WriteLine("Begin to invocate calculator service

via tcp transport ");
Console.WriteLine("x + y = {2} where x = {0} and y = {1}", 1, 2,

calculator_tcp.Add(1, 2));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
#endregion

Console.WriteLine("\n\nInvocate IIS-host calculator service ");

Invocate IIS-host service#region Invocate IIS-host service
using (GeneralCalculatorClient calculator = new GeneralCalculatorClient(

httpBinding, httpAddress_iisHost))
{
try
{
Console.WriteLine("Begin to invocate calculator

service via http transport ")

;
Console.WriteLine("x + y = {2} where x = {0}

and y = {1}", 1, 2, calculator.

Add(1, 2));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
#endregion
}

static void InvocateCalclatorServiceViaConfiguration()
{
Console.WriteLine("Invocate self-host calculator service ");

Invocate Self-host service#region Invocate Self-host service
using (GeneralCalculatorClient calculator_http = new GeneralCalculatorClient

("selfHostEndpoint_http"))
{
using (GeneralCalculatorClient calculator_tcp = new GeneralCalculatorClient

("selfHostEndpoint_tcp"))
{
try
{
Console.WriteLine("Begin to invocate calculator

service via http transport

");
Console.WriteLine("x + y = {2} where x = {0}

and y = {1}", 1, 2, calculator

_http.Add(1, 2));

Console.WriteLine("Begin to invocate calculator service

via tcp transport

");
Console.WriteLine("x + y = {2} where x = {0}

and y = {1}", 1, 2,

calculator_tcp.Add(1, 2));
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
#endregion

Console.WriteLine("\n\nInvocate IIS-host calculator service ");

Invocate IIS-host service#region Invocate IIS-host service
using (GeneralCalculatorClient calculator = new GeneralCalculatorClient

("iisHostEndpoint"))
{
try
{
Console.WriteLine("Begin to invocate calculator service

via http transport ");
Console.WriteLine("x + y = {2}

where x = {0} and y = {1}", 1, 2, calculator.

Add(1, 2));                   
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
#endregion
}
}
}



共5页: 上一页 [1] [2] 3 [4] [5] 下一页
【内容导航】
专题
体验Visual Studio 2008的魅力
Visual Studio 2005开发基础
测试开发人员参考手册
甲骨文85亿美元收购BEA
程序员如何成长?
我也说两句

匿名发表

(如果看不清请点击图片进行更换)


中 国 领 先 的 IT 技 术 网 站 ·
技 术 成 就 梦 想
·Java基础教程 (查看69912次)
·UML类图详解 (查看63757次)
·UML统一建模语言 (查看34694次)
·C#技术开发指南 (查看33015次)
·Java编程开发手册 (查看31041次)
·Java编程开发手册 (1196个砖)
·Java基础教程 (429个砖)
·C#技术开发指南 (309个砖)
·.NET开发手册 (240个砖)
·PB开发教程 (223个砖)
·Java编程开发手册 (654个好)
·Java基础教程 (574个好)
·.NET开发手册 (271个好)
·PB开发教程 (212个好)
·Delphi开发技术手册 (188个好)
订阅技术快讯
电子杂志下载
名称:SQL Server数据库管理精品黄皮书
简介:书中文章经过精挑细选,便于用户能根据自己的实际工作和学习,快速在本书寻找到相关资料。内容涵盖了SQL Server的安装与升级、语句查询、数据备份和恢复、自动化任务、数据同步、数据字典、安全和预防、性能和优化、集群等各方面应用信息,以及DBA管理人员在数据库管理工作中
名称:2007路由技术大全
简介:《2007路由技术大全》由51CTO.com网站特别策划制作,该书包括路由器技术、路由器产品、路由器配置、安全设置、路由器故障处理、路由器密码恢复,以及广大网友在实践使用中的心得经验和技巧文章,内容注重实用性,适用于初学者入门,也适合多年从业者提高,是一本实践和理论完
名称:网络安全精品应用黄皮书
简介:《2007精品网络安全黄皮书》包括了9个大类24个小类, 800余篇文章,内容包含了熊猫烧香病毒、DDOS攻击、ARP病等热点问题的介绍及解决方案。从病毒查杀、防范、系统、数据等各方面的安全设置到黑客技术的了解、防范,涉及到了安全应用的全部领域, 由浅至深内容全面。