Windows Communication Foundation环境安装篇

.NET Framework 3.0发布有一段时间了,惫懒的我是不是也该动手学习点新东西呢?那就先从WCF开始吧。WCFWindows Communication Foundation)作为.NET Framework 3.0的一部分,随着Windows Vista一起而Release,但是并不是说只有在Windows Vista下才可以使用WCF。除了Vista之外的操作系统要安装WCF的开发环境,需要具备如下条件:

1.  操作系统:Windows XP或者Windows 2003

2.  由于WCF构建于.NET Framework 2.0之上,所以需要安装.NET Framework 2.0

3.  下载安装.NET Framework 3.0

Microsoft .NET Framework 3.0 Redistributable Package

4.使用Visual Studio 2005开发,还需要下载VS2005扩展

Microsoft Visual Studio 2005 CTP Extensions for .NET Framework 3.0 (WCF & WPF)

5SDK是必不可少的:Microsoft Windows SDK for .NET Framework 3.0

 

注:微软提供的WCF示例:

http://www.microsoft.com/downloads/details.aspx?FamilyID=0043041f-95d6-4eb7-966a-c21a737e193a&DisplayLang=en

作者:TerryLee
出处:http://terrylee.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
posted @ 2006-12-18 23:38 TerryLee 阅读(7065) 评论(9)  编辑 收藏 网摘 所属分类: [04]  WCF后传

  回复  引用  查看    
#1楼 2006-12-19 08:50 | zhaosichao      
勤奋的人。
  回复  引用    
#2楼 2006-12-22 10:11 | ycl [未注册用户]
Microsoft Windows SDK for .NET Framework 3.0下有很多例子。WCF,WPF,WF。新的多媒体接口例子等等,但WCF要设置一些端口必须打开才能用。LZ慢慢研究吧,看懂了能写出来的确是个好习惯。
  回复  引用  查看    
#3楼 [楼主]2006-12-23 16:26 | TerryLee      
@zhaosichao
:)
  回复  引用  查看    
#4楼 [楼主]2006-12-23 16:27 | TerryLee      
@ycl
嗯,先从SDK开始,最近准备写一个WCF系列
  回复  引用  查看    
#5楼 2007-04-03 21:05 | ColdDog      
博客源是不是出错了,怎么你的很多帖子后面都有我上面的回复阿~
晕阿。。。我冤枉啊...
另外,我怎么安装不成功SDK?
  回复  引用  查看    
#6楼 2007-05-23 15:21 | 食草笨笨熊      
Hi TerryLee:
经常读你写的Blog,从你的文章中学到不少东西,谢谢。
有个关于WCF的问题想请教你一下。我在使用WCF从客户端控制事务的时候,发现必须客户端和服务器端同时配置MSDTC才行,配置如下:
To configure the Microsoft Distributed Transaction Coordinator (MSDTC) to support running the sample across machines
On the service machine, configure MSDTC to allow incoming network transactions.
From the Start menu, navigate to Control Panel, then Administrative Tools, and then Component Services.
Right-click My Computer and select Properties.
On the MSDTC tab, click Security Configuration.
Check Network DTC Access and Allow Inbound.
Click Yes to restart the MSDTC service and then click OK.
Click OK to close the dialog box.
On the service machine and the client machine, configure the Windows Firewall to include the Microsoft Distributed Transaction Coordinator (MSDTC) to the list of excepted applications:
Run the Windows Firewall application from Control Panel.
From the Exceptions tab, click Add Program.
Browse to the folder C:\WINDOWS\System32.
Select Msdtc.exe and click Open.
Click OK to close the Add Program dialog box, and click OK again to close the Windows Firewall applet.
On the client machine, configure MSDTC to allow outgoing network transactions:
From the Start menu, navigate to Control Panel, then Administrative Tools, and then Component Services.
Right-click My Computer and select Properties.
On the MSDTC tab, click Security Configuration.
Check Network DTC Access and Allow Outbound.
Click Yes to restart the MS DTC service and then click OK.
Click OK to close the dialog box.

而且MSDTC还不能像Web Service那样穿透防火墙,我不知道是我代码的原因还是怎么的?怎么样才能脱离MSDTC来使用Transaction?麻烦你帮我看看,代码如下:
服务器端CS:
[ServiceContract(SessionMode=SessionMode.Required)]
public interface IAccountActivities
{
#region Interface for service

[OperationContract]
string HelloWorld(string strUserName);
[OperationContract]
int GetBalance(string strAccountNumber);
[OperationContract]
int DebitBalance(string strAccountNumber, int nAmount);
[OperationContract]
[TransactionFlow(TransactionFlowOption.Mandatory)]
int CreditBalance(string strAccountNumber, int nAmount);
[OperationContract]
int WriteLog(string strAccountNumber, string strOperationType);
[OperationContract]
[TransactionFlow(TransactionFlowOption.Mandatory)]
void transferFunds(string strFromAccountNumber, string strToAccountNumber, int nAmount);

#endregion
}

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]
public class AccountActivities : IAccountActivities
{

#region IAccountActivities Members

public string HelloWorld(string strUserName)
{
return "Hello World, " + strUserName;
}

public int GetBalance(string strAccountNumber)
{
string strSQL = "select Amount from ATMAccount where AccountNumber = '" + strAccountNumber + "'";
return Convert.ToInt32(SqlHelper.ExecuteScalar(CommandType.Text, strSQL));
}

public int DebitBalance(string strAccountNumber, int nAmount)
{
string strSQL = "update ATMAccount set Amount = Amount - " + nAmount + " where AccountNumber='" + strAccountNumber + "'";
return SqlHelper.ExecuteNonQuery(CommandType.Text, strSQL);
}

[OperationBehavior(TransactionScopeRequired=true)]
public int CreditBalance(string strAccountNumber, int nAmount)
{
string strSQL = "update ATMAccount set Amount = Amount + " + nAmount + " where AccountNumber='" + strAccountNumber + "'";
return SqlHelper.ExecuteNonQuery(CommandType.Text, strSQL);
}

public int WriteLog(string strAccountNumber, string strOperationType)
{
string strSQL = "insert into ATMLog (AccountNumber,OperationType) values ('" + strAccountNumber + "','" + strOperationType + "')";
return SqlHelper.ExecuteNonQuery(CommandType.Text, strSQL);
}

[OperationBehavior(TransactionScopeRequired=true)]
public void transferFunds(string strFromAccountNumber, string strToAccountNumber, int nAmount)
{
DebitBalance(strFromAccountNumber, nAmount);
CreditBalance(strToAccountNumber, nAmount);
WriteLog(strFromAccountNumber, "Transfer From");
WriteLog(strToAccountNumber, "Transfer To");

if (GetBalance(strFromAccountNumber) < 0)
{
throw new Exception("Transaction Rollback : There is not so much money in account" + strFromAccountNumber);
}
}

#endregion

服务器端WebConfig:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="ATMwsHttpBinding" transactionFlow="true" />
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="BankServicesBehavior" name="Aegis.BankServices.AccountActivities">
<endpoint binding="wsHttpBinding" bindingConfiguration="ATMwsHttpBinding"
contract="Aegis.BankServices.IAccountActivities" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="BankServicesBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

<system.web>
<compilation debug="true"/>
</system.web>
客户端使用Service代码:
using (TransactionScope objTransactionScope = new TransactionScope())
{
try
{
nTemp = m_ATMService.CreditBalance(m_strAccountNumber, Convert.ToInt32(strTransactionAmount));
m_ATMService.WriteLog(m_strAccountNumber, "Credit");
objTransactionScope.Complete();
}
catch (Exception ex)
{
MessageBox.Show("error:" + ex.Message);
}
}
if (m_ATMService.State != System.ServiceModel.CommunicationState.Faulted)
{
nReturnedBalance = nTemp;
}
else
{
ATMServices.AccountActivitiesClient myService = new ATMClient.ATMServices.AccountActivitiesClient();
myService.WriteLog("001", "error");
}
不胜感激。
  回复  引用  查看    
#7楼 2007-12-10 15:26 | liangyi_neil      
TerryLee, 你好!
我的系统是Win2003 Server, 有SDK2.0, VS2005, 然后安装了Framework 3.0, 到下载Microsoft Visual Studio 2005 CTP Extensions for .NET Framework 3.0 (WCF & WPF)时并没有'download'按纽,却成了'Continue'按纽, 不知道为什么, 是不是系统还缺少其他必须的软件? 谢谢!
而且SDK 也是'Continue'按纽....

页面分别为http://www.microsoft.com/downloads/details.aspx?FamilyId=F54F5537-CC86-4BF5-AE44-F5A1E805680D&displaylang=en#Requirements,
http://www.microsoft.com/downloads/info.aspx?na=40&p=3&SrcDisplayLang=en&SrcCategoryId=&SrcFamilyId=10cc340b-f857-4a14-83f5-25634c3bf043&u=http%3a%2f%2fgo.microsoft.com%2ffwlink%2f%3fLinkId%3d74726
  回复  引用  查看    
#8楼 2007-12-13 15:35 | liangyi_neil      
呵呵,能下载了, 原来要先下载一个插件




标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
Google站内搜索

相关文章:

相关链接: