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中事务的操作的更多相关文章

  1. spring对数据库的操作、spring中事务管理的介绍与操作

    jdbcTemplate的入门 创建maven工程 此处省略 导入依赖 <!-- https://mvnrepository.com/artifact/org.springframework/s ...

  2. 跟我一起学WCF(10)——WCF中事务处理

    一.引言 好久没更新,总感觉自己欠了什么一样的,所以今天迫不及待地来更新了,因为后面还有好几个系列准备些,还有很多东西需要学习总结的.今天就来介绍下WCF对事务的支持. 二.WCF事务详解 2.1 事 ...

  3. WCF中事务处理

    一.引言 今天来介绍下WCF对事务的支持. 二.WCF事务详解 2.1 事务概念与属性 首先,大家在学习数据库的时候就已经接触到事务这个概念了.所谓事务,它是一个操作序列,这些操作要么都执行,要么都不 ...

  4. day18-事务与连接池 3.jdbc中事务操作介绍

    那么我们都是通过程序操作数据库.所以要了解jdbc下怎样对事务操作.jdbc如何操作事务? 自动事务false那就不开了呗相当于开启事务. package cn.itcast.transaction; ...

  5. PHP中使用PDO操作事务的一些小测试

    关于事务的问题,我们就不多解释了,以后在学习 MySQL 的相关内容时再深入的了解.今天我们主要是对 PDO 中操作事务的一些小测试,或许能发现一些比较好玩的内容. 在 MyISAM 上使用事务会怎么 ...

  6. PHP中的PDO操作学习(二)预处理语句及事务

    今天这篇文章,我们来简单的学习一下 PDO 中的预处理语句以及事务的使用,它们都是在 PDO 对象下的操作,而且并不复杂,简单的应用都能很容易地实现.只不过大部分情况下,大家都在使用框架,手写的机会非 ...

  7. WCF中常用的binding方式

    WCF中常用的binding方式: BasicHttpBinding: 用于把 WCF 服务当作 ASMX Web 服务.用于兼容旧的Web ASMX 服务.WSHttpBinding: 比 Basi ...

  8. 跟我一起学WCF(11)——WCF中队列服务详解

    一.引言 在前面的WCF服务中,它都要求服务与客户端两端都必须启动并且运行,从而实现彼此间的交互.然而,还有相当多的情况希望一个面向服务的应用中拥有离线交互的能力.WCF通过服务队列的方法来支持客户端 ...

  9. 游刃于MVC、WCF中的Autofac

    为了程序的健壮性.扩展性.可维护性,依赖抽象而不是具体实现类等等,于是我选择了Autofac依赖注入容器 就是这个工厂来降低耦合.之前买东西是自己去超市,现在呢 我需要什么东西,他们给送过来直接拿到了 ...

随机推荐

  1. Ubuntu 16.04下更新Atom

    在Ubuntu下Atom好像不会自动更新,但是可以通过这些方法去实现: 1.安装插件:https://atom.io/packages/up2date 2.使用apt源更新: sudo apt-get ...

  2. Cocoa开发中, 如何用全局变量

    比如在tabbar的开发中,可以某个页面的数据需要在back到此页面后依然有效. 可以用 appDelegate 这个对象来创建你的全局数据 这个内建的对象,在 APP 启动时产生,在 APP 退出时 ...

  3. XStream 数组(List)输出结构

    <!-- 期望的DOM树 --> <Articles> <item> <Title>微信SDK初步结构</Title> <Descri ...

  4. SolidEdge 如何绘制局部视图 局部放大图

    创建局部视图(局部放大图),先选择要创建局部放大图的视图,然后绘制一个小圆,然后绘制一个大圆即可.   如果要绘制不规则形状的局部放大图,则点击了局部放大图之后,点击绘制草图的按钮   随后可以用相切 ...

  5. C#中Queue&lt;T&gt;类的使用以及部分方法的源代码分析

    Queue<T>类 表示对象的先进先出集合. 队列在按接收顺序存储消息方面很实用,以便于进行顺序处理. 存储在 Queue,<T> 中的对象在一端插入,从还有一端移除. Que ...

  6. SpringBoot学习之@SpringBootApplication注解

    下面是我们经常见到SpringBoot启动类代码: @SpringBootApplicationpublic class DemoApplication extends SpringBootServl ...

  7. 聊聊高并发(三十二)实现一个基于链表的无锁Set集合

    Set表示一种没有反复元素的集合类,在JDK里面有HashSet的实现,底层是基于HashMap来实现的.这里实现一个简化版本号的Set,有下面约束: 1. 基于链表实现.链表节点依照对象的hashC ...

  8. 数组index

    1. 数组index与数组名的位置关系     a[b] = *(a + b) = *(b + a) = b[a] int a[5] = {1, 2, 3, 4, 5}; printf("% ...

  9. 对交换机VLAN及各种端口类型的理解

    每学习一种技术时,我们往往需要去了解why,即这个技术是为解决什么问题而出现的. VLAN全称为Virtual Local Area Network,即虚拟局域网,是逻辑上的一种划分.一般来说,如果交 ...

  10. 【iOS系列】-自定义Modar动画

    [iOS系列]-自定义Modar动画.md 我们需要做的最终的modar动画的效果是这样的, 就是点击cell,cell发生位移,慢慢的到第二个界面上的.为了做出这样的动画效果,我们需要以下的知识. ...