您所在的位置: 首页>>开发>>语言&工具>>

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

http://developer.51cto.com  2008-03-13 10:18  Artech  博客园  我要评论(0)
  • 摘要:WCF实际上是构建了一个框架,这个框架实现了在互联系统中各个Application之间如何通信。使得Developers和Architect在构建分布式系统中,无需在考虑如何去实现通信相关的问题,更加关注与系统的业务逻辑本身。
  • 标签:WCF  Endpoint Overview  Endpoint

3、Hosting:Artech.WCFService.Hosting/Program.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using Artech.WCFService.Contract;
using Artech.WCFService.Service;
using System.ServiceModel.Description;

namespace Artech.WCFService.Hosting
{
class Program
{
static void Main(string[] args)
{
//HostCalculatorServiceViaCode();
HostCalculatorSerivceViaConfiguration();
}

/**////


/// Hosting a service using managed code

without any configuraiton information.
/// Please note that the related configuration data

should be removed before calling the method.
///


static void HostCalculatorServiceViaCode()
{
Uri httpBaseAddress = new Uri("http://localhost:8888/generalCalculator");
Uri tcpBaseAddress = new Uri("net.tcp://localhost:9999/generalCalculator");

using (ServiceHost calculatorSerivceHost = new ServiceHost(typeof

(GeneralCalculatorService), httpBaseAddress, tcpBaseAddress))
{          
BasicHttpBinding httpBinding = new BasicHttpBinding();
NetTcpBinding tcpBinding = new NetTcpBinding();

calculatorSerivceHost.AddServiceEndpoint(typeof(IGeneralCalculator),

httpBinding, string.Empty);
calculatorSerivceHost.AddServiceEndpoint(typeof(IGeneralCalculator),

tcpBinding, string.Empty);

ServiceMetadataBehavior behavior =

calculatorSerivceHost.Description.Behaviors.Find();
{
if(behavior == null)
{
behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
calculatorSerivceHost.Description.Behaviors.Add(behavior);
}
else
{
behavior.HttpGetEnabled = true;
}
}

calculatorSerivceHost.Opened += delegate
{
Console.WriteLine("Calculator Service has begun to listen  ");
};

calculatorSerivceHost.Open();

Console.Read();
}
}

static void HostCalculatorSerivceViaConfiguration()
{
using (ServiceHost calculatorSerivceHost = new ServiceHost(typeof

(GeneralCalculatorService)))
{              
calculatorSerivceHost.Opened += delegate
{
Console.WriteLine("Calculator Service has begun to listen  ");
};

calculatorSerivceHost.Open();

Console.Read();
}
}       
}
}


4、Service.svchttp://localhost/WCFService/ GeneralCalculatorService.svc

<%@ ServiceHost Language="C#" Debug="true" Service="Artech.WCFService.Service.

GeneralCalculatorService" %>


共5页: 上一页 [1] 2 [3] [4] [5] 下一页
【内容导航】
WCF开发基础
深入Vista应用程序开发
走向银光 —— 一步一步学Silverlight2
让你的代码“炫”起来——WPF开发教程
WebSphere 实现SOA的利器
 
 验证码: (点击刷新验证码)   匿名发表
  • Visual C++ 完全自学宝典

  • 作者:强锋科技,朱洪波
  • Visual C++ 6.0是微软公司为程序人员提供的Visual Studio 6.0工具套件中的重要组成部分。本书由浅入深地介绍使用Visual C++ 6.0..
Copyright©2005-2008 51CTO.COM 版权所有