wcf中事务的操作
using System;
using System.ServiceModel; namespace Larryle.Wcf.ServiceContract.Transaction
{
[ServiceContract]
public interface IHello
{
[OperationContract]
[TransactionFlow(TransactionFlowOption.Mandatory)]
void WriteHello(string name);
}
}
using System;
using System.ServiceModel; namespace Larryle.Wcf.ServiceContract.Transaction
{
[ServiceContract]
public interface IHi
{
[OperationContract]
[TransactionFlow(TransactionFlowOption.Mandatory)]
void WriteHi(string Name);
}
}
using System;
using System.Collections.Generic;
using System.ServiceModel;
using Larryle.Wcf.ServiceContectData.Transaction; namespace Larryle.Wcf.ServiceContract.Transaction
{
[ServiceContract]
public interface IResult
{
[OperationContract]
List<Item> GetResult();
}
}
using System;
using System.Linq;
using System.ServiceModel;
using Larryle.Wcf.ServiceContract.Transaction;
using Larryle.Wcf.ServiceContectData.Transaction; namespace Larryle.Wcf.Service.Transaction
{
public class Hello : IHello
{
[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public void WriteHello(string name)
{
DBDataContext ctx = new DBDataContext();
ctx.Item.InsertOnSubmit(new Item
{
Title = string.Format("Hello:{0},TransactionId:{1}", name, System.Transactions.Transaction.Current.TransactionInformation.LocalIdentifier),
CreatedTime = DateTime.Now
});
ctx.SubmitChanges();
}
}
}
using System;
using System.ServiceModel;
using Larryle.Wcf.ServiceContectData.Transaction;
using Larryle.Wcf.ServiceContract.Transaction; namespace Larryle.Wcf.Service.Transaction
{
public class Hi : IHi
{
[OperationBehavior(TransactionScopeRequired = true, TransactionAutoComplete = true)]
public void WriteHi(string Name)
{
if (DateTime.Now.Second % == )
{
throw new System.Exception("为测试事务而抛出的异常");
}
DBDataContext dbcx = new DBDataContext();
dbcx.Item.InsertOnSubmit(new Item
{
Title = string.Format("Hi:{0},TransactionId:{1}",Name,System.Transactions.Transaction.Current.TransactionInformation.LocalIdentifier),
CreatedTime=DateTime.Now
});
dbcx.SubmitChanges();
}
}
}
using System;
using System.Linq;
using System.ServiceModel;
using Larryle.Wcf.ServiceContectData.Transaction;
using Larryle.Wcf.ServiceContract.Transaction; namespace Larryle.Wcf.Service.Transaction
{
public class Result : IResult
{
public System.Collections.Generic.List<Item> GetResult()
{
DBDataContext dbcx = new DBDataContext();
var result = from l in dbcx.Item orderby l.CreatedTime descending select l;
return result.ToList();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; namespace Larryle.WcfWebClient
{
public partial class TestTransaction : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void text_Click(object sender, EventArgs e)
{
TransactionHelloSvc.HelloClient hell = new TransactionHelloSvc.HelloClient();
TransactionHiSvc.HiClient hi = new TransactionHiSvc.HiClient();
TransactionResultSvc.ResultClient result = new TransactionResultSvc.ResultClient();
System.Transactions.TransactionOptions tr = new System.Transactions.TransactionOptions();
tr.Timeout = new TimeSpan(, , );
tr.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
{
try
{
hell.WriteHello("larryle1");
hi.WriteHi("larryle2");
hell.Close();
hi.Close();
ts.Complete();
ClientScript.RegisterStartupScript(this.GetType(), "js", "alert('ok')", true);
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "js", "alert('失败')", true);
}
}
this.GridView1.DataSource = result.GetResult();
this.GridView1.DataBind();
result.Close();
}
}
}
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="StreamedBindingConfiguration" transferMode="Streamed" maxReceivedMessageSize="1073741824" receiveTimeout="00:10:00"></binding>
</netTcpBinding>
<netMsmqBinding>
<binding name="MSMQBindingConfiguration">
<security>
<transport msmqAuthenticationMode="None" msmqProtectionLevel="None"/>
<message clientCredentialType="UserName"/>
</security>
</binding>
</netMsmqBinding>
<wsHttpBinding>
<binding name="SecurityBindingConfiguration">
<security>
<message clientCredentialType="UserName"/>
</security>
</binding>
<binding name="TransactionConfiguration" transactionFlow="true">
</binding>
</wsHttpBinding>
<ws2007HttpBinding>
<binding name="SessionManagementBinding" receiveTimeout="00:10:00">
<reliableSession enabled="true"/>
<security>
<message establishSecurityContext="true"/>
</security>
</binding>
</ws2007HttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="BindingBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
<behavior name="MessageBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior name="InstanceModeBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior name="ExceptionBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior name="SecurityBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Larryle.Wcf.Service.Security.CustomNamePasswordValidator,Larryle.Wcf.Service"/>
<serviceCertificate findValue="localhost" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
<clientCertificate>
<authentication certificateValidationMode="None"/>
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Larryle.Wcf.Service.Binding.Hello" behaviorConfiguration="BindingBehavior">
<endpoint address="net.tcp://localhost:54321/Binding/Hello" binding="netTcpBinding" contract="Larryle.Wcf.ServiceContract.Binding.IHello"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:12345/Binding/"/>
</baseAddresses>
</host>
</service>
<service name="Larryle.Wcf.Service.ConcurrencyLock.Hello" behaviorConfiguration="MessageBehavior">
<endpoint address="Hello" binding="wsHttpBinding" contract="Larryle.Wcf.ServiceContract.ConcurrencyLock.IHello"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:12345/ConcurrencyLock/"/>
</baseAddresses>
</host>
</service>
<service name="Larryle.Wcf.Service.Contract.PersonManager" behaviorConfiguration="MessageBehavior">
<endpoint address="PersonManager" binding="mexHttpBinding" contract="ConfigurationNameTest">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:12345/Contract/"/>
</baseAddresses>
</host>
</service>
<service name="Larryle.Wcf.Service.Exception.Hello" behaviorConfiguration="ExceptionBehavior">
<endpoint address="Hello" binding="wsHttpBinding" contract="Larryle.Wcf.ServiceContract.Exception.IHello">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:12345/Exception/"/>
</baseAddresses>
</host>
</service>
<service name="Larryle.Wcf.Service.Security.Hello" behaviorConfiguration="SecurityBehavior">
<endpoint address="Hello" binding="wsHttpBinding" contract="Larryle.Wcf.ServiceContract.Security.IHello" bindingConfiguration="SecurityBindingConfiguration">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:12345/Security/"/>
</baseAddresses>
</host>
</service>
<service name="Larryle.Wcf.Service.SessionManagement.Hello" behaviorConfiguration="MessageBehavior">
<endpoint address="Hello" binding="ws2007HttpBinding" bindingConfiguration="SessionManagementBinding" contract="Larryle.Wcf.ServiceContract.SessionManagement.IHello">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:12345/SessionManagement/" />
</baseAddresses>
</host>
</service>
<service name="Larryle.Wcf.Service.Transaction.Hello" behaviorConfiguration="MessageBehavior">
<endpoint address="Hello" binding="wsHttpBinding" contract="Larryle.Wcf.ServiceContract.Transaction.IHello" bindingConfiguration="TransactionConfiguration">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:12345/Transaction/Hello"/>
</baseAddresses>
</host>
</service>
<service name="Larryle.Wcf.Service.Transaction.Hi" behaviorConfiguration="MessageBehavior">
<endpoint address="Hi" binding="wsHttpBinding" contract="Larryle.Wcf.ServiceContract.Transaction.IHi" bindingConfiguration="TransactionConfiguration">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:12345/Transaction/Hi"/>
</baseAddresses>
</host>
</service>
<service name="Larryle.Wcf.Service.Transaction.Result" behaviorConfiguration="MessageBehavior">
<endpoint address="Result" binding="wsHttpBinding" contract="Larryle.Wcf.ServiceContract.Transaction.IResult" bindingConfiguration="TransactionConfiguration">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:12345/Transaction/Result"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
wcf中事务的操作的更多相关文章
- spring对数据库的操作、spring中事务管理的介绍与操作
jdbcTemplate的入门 创建maven工程 此处省略 导入依赖 <!-- https://mvnrepository.com/artifact/org.springframework/s ...
- 跟我一起学WCF(10)——WCF中事务处理
一.引言 好久没更新,总感觉自己欠了什么一样的,所以今天迫不及待地来更新了,因为后面还有好几个系列准备些,还有很多东西需要学习总结的.今天就来介绍下WCF对事务的支持. 二.WCF事务详解 2.1 事 ...
- WCF中事务处理
一.引言 今天来介绍下WCF对事务的支持. 二.WCF事务详解 2.1 事务概念与属性 首先,大家在学习数据库的时候就已经接触到事务这个概念了.所谓事务,它是一个操作序列,这些操作要么都执行,要么都不 ...
- day18-事务与连接池 3.jdbc中事务操作介绍
那么我们都是通过程序操作数据库.所以要了解jdbc下怎样对事务操作.jdbc如何操作事务? 自动事务false那就不开了呗相当于开启事务. package cn.itcast.transaction; ...
- PHP中使用PDO操作事务的一些小测试
关于事务的问题,我们就不多解释了,以后在学习 MySQL 的相关内容时再深入的了解.今天我们主要是对 PDO 中操作事务的一些小测试,或许能发现一些比较好玩的内容. 在 MyISAM 上使用事务会怎么 ...
- PHP中的PDO操作学习(二)预处理语句及事务
今天这篇文章,我们来简单的学习一下 PDO 中的预处理语句以及事务的使用,它们都是在 PDO 对象下的操作,而且并不复杂,简单的应用都能很容易地实现.只不过大部分情况下,大家都在使用框架,手写的机会非 ...
- WCF中常用的binding方式
WCF中常用的binding方式: BasicHttpBinding: 用于把 WCF 服务当作 ASMX Web 服务.用于兼容旧的Web ASMX 服务.WSHttpBinding: 比 Basi ...
- 跟我一起学WCF(11)——WCF中队列服务详解
一.引言 在前面的WCF服务中,它都要求服务与客户端两端都必须启动并且运行,从而实现彼此间的交互.然而,还有相当多的情况希望一个面向服务的应用中拥有离线交互的能力.WCF通过服务队列的方法来支持客户端 ...
- 游刃于MVC、WCF中的Autofac
为了程序的健壮性.扩展性.可维护性,依赖抽象而不是具体实现类等等,于是我选择了Autofac依赖注入容器 就是这个工厂来降低耦合.之前买东西是自己去超市,现在呢 我需要什么东西,他们给送过来直接拿到了 ...
随机推荐
- Raft算法详解
一致性算法Raft详解 背景 熟悉或了解分布性系统的开发者都知道一致性算法的重要性,Paxos一致性算法从90年提出到现在已经有二十几年了,而Paxos流程太过于繁杂实现起来也比较复杂,可能也是以为过 ...
- Windows 10安装IntelliJ IDEA时快捷键冲突设置
Windows的快捷键的非常多,而且个性化软件获得这些权限的也很多,所以没有最终的方法,只能不断的发现和尝试. 下面是收集的一些教程,或许能在这里找到灵感: 切记:不建议优先修改IDEA的快捷键,应该 ...
- 常用Git命令手册
常用Git命令手册 此文只是对Git有一定基础的人当记忆使用,比较简略,初级学员强烈推荐廖雪峰老师的Git系列教程,通俗易懂,戳此处即可开始学习 1.安装Git Linux sudo apt-get ...
- Bootstrap全局CSS样式之button和图片
.btn-default--button的默认样式. .btn-primary--button的首选样式: .btn-success--button的成功样式: .btn-info--button的一 ...
- 日常方便使用的Python脚本实现
目录 文件批量重命名 bin文件合并 正文 1.python根据不同条件批量实现文件重命名 因为下载的电视剧名字比较乱,但却按照下载时间顺序依次排列,而手动重命名或者找软件太麻烦,我就自己实现了个: ...
- 【转载】细聊分布式ID生成方法
一.需求缘起 几乎所有的业务系统,都有生成一个记录标识的需求,例如: (1)消息标识:message-id (2)订单标识:order-id (3)帖子标识:tiezi-id 这个记录标识往往就是数据 ...
- C开发人员眼中的SICP学习
谈谈自己看SICP的一些体会 第一章 构造过程抽象 这一章事实上和C语言全然等价, 不打算深入学习LISP的能够高速略过. 思想上没有太多新的东西. 这一章最核心的价值就是以下3句话, 理解了这一章 ...
- 项目Alpha冲刺(团队8/10)
项目Alpha冲刺(团队8/10) 团队名称: 云打印 作业要求: 项目Alpha冲刺(团队) 作业目标: 完成项目Alpha版本 团队队员 队员学号 队员姓名 个人博客地址 备注 221600412 ...
- 基于redis集群实现的分布式锁,可用于秒杀商品的库存数量管理,有測试代码(何志雄)
转载请标明出处. 在分布式系统中,常常会出现须要竞争同一资源的情况,本代码基于redis3.0.1+jedis2.7.1实现了分布式锁. redis集群的搭建,请见我的另外一篇文章:<>& ...
- js replace()实现全部替换
var r= "1\n2\n3\n"; //将字母\n替换成分号 alert(r.replace("\n",";")); 结果:1;2\n3 ...