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

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

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

6、Self-Hosting Configuration:Artech.WCFService.Hosting/App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="calculatorServieBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="calculatorServieBehavior" name="Artech.WCFService.

Service.GeneralCalculatorService">
<endpoint address="" binding="basicHttpBinding" contract="Artech.WCFService.

Contract.IGeneralCalculator">
</endpoint>
<endpoint address="" binding="netTcpBinding" contract="Artech.WCFService.Contract.

IGeneralCalculator" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8888/generalcalculator" />
<add baseAddress="net.tcp://localhost:9999/generalCalculator" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>

7、IIS-Host Configuration

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="calculatorServiceBehavior">
<serviceMetadata httpGetEnabled ="true"></serviceMetadata>
</behavior>
</serviceBehaviors>
</behaviors>

<services>
<service name="Artech.WCFService.Service.GeneralCalculatorService" behaviorConfiguration="

calculatorServiceBehavior">
<endpoint binding="basicHttpBinding" contract="Artech.WCFService.Contract.

IGeneralCalculator"></endpoint>
</service>
</services>
</system.serviceModel>
<system.web>
<compilation debug="true">
<assemblies>
<add assembly="System.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=

B03F5F7F11D50A3A"/>
<add assembly="Microsoft.Transactions.Bridge, Version=3.0.0.0, Culture=neutral,

PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="SMDiagnostics, Version=3.0.0.0, Culture=neutral, PublicKeyToken=

B77A5C561934E089"/>
<add assembly="System.IdentityModel.Selectors, Version=3.0.0.0, Culture=neutral,

PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral,

PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.RegularExpressions, Version=2.0.0.0, Culture=neutral,

PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral,

PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken

=B03F5F7F11D50A3A"/>
<add assembly="System.ServiceProcess, Version=2.0.0.0, Culture=neutral,

PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>
</system.web>
</configuration>

8、Client configuration:Artech.WCFService.Client/App.config

http://localhost:8888/generalCalculator" binding="basicHttpBinding"

contract="Artech.WCFService.Contract.IGeneralCalculator" name="selfHostEndpoint_http"/>

http://localhost/wcfservice/GeneralCalculatorService.svc" binding="basicHttpBinding"

contract="Artech.WCFService.Contract.IGeneralCalculator" name="iisHostEndpoint"/>

如何在Application中定义Endpoint

对于Self-Host的Service,绝大部分的Endpoint相关的信息都具有两种定义方式——Managed Code 和Configuration。而对于把Service Host到IIS中的情况, Endpoint的信息一般虚拟根目录下的Web.Config中定义。一般的我们我们不推荐使用代码的方式Host和调用Service,这主要是基于以下的理由。首先我们开发的环境往往与部署的环境不尽相同,才用configuration的方式是的我们可以在部署的时候通过修改配置文件以适应新的需要。其次,对于不要出现的新的需要,比如对于一个原来只供Internet内部使用的Service,我们一般会定义一个基于TCP的Endpoint,现在出现来自于Internet的潜在用户,我们只需要通过修改Config文件的方式为这个Service添加一个新的基于Http的Endpoint就可以了。 把Endpoint的信息写在config文件中的优势在于,修改config文件的内容是不需要重新编译和重新部署的。相应的定义方式清参照以上的Sample。

下面我们来看看在host 一个Service的时候,置于配置文件的信息是如何起作用的。在上面的例子中我们通过下面一段代码Host一个Serivice(对应得Service Type是GeneralCalculatorService)。

using (ServiceHost calculatorSerivceHost = new ServiceHost(typeof(GeneralCalculatorService)))
{              
calculatorSerivceHost.Opened += delegate
{
Console.WriteLine("Calculator Service has begun to listen  ");
};
calculatorSerivceHost.Open();
Console.Read();
}


共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 版权所有