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. NOIP前必须记住的30句话

    NOIP前必须记住的30句话 1.比赛前一天晚上请准备好你的各种证件,事先查好去往考场的路线2.比赛之前请先调整你的屏幕分辨率到你喜欢的大小3.比赛之前请把编译器的字体调为你平时惯用的字体,尤其是注意 ...

  2. Effective Java P2 Creating and Destroying Objects

    This chapter concerns creating and destorying objects : when and how to create them, when and how to ...

  3. Java搜索引擎选择: Elasticsearch与Solr(转)

    Elasticsearch简介 Elasticsearch是一个实时的分布式搜索和分析引擎.它可以帮助你用前所未有的速度去处理大规模数据. 它可以用于全文搜索,结构化搜索以及分析,当然你也可以将这三者 ...

  4. haproxy和nginx负载均衡分析

    https://my.oschina.net/zhuangweihong/blog/813231

  5. 详解 CSS 七种三栏布局技巧

    作者:林东洲 链接:https://zhuanlan.zhihu.com/p/25070186 来源:知乎 著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 三栏布局,顾名思义就是 ...

  6. IE8.0登录Oracle EBS后报Oracle error 1403错

    IE8.0登录Oracle EBS后报错,登录页面打开没有问题.只是输入username和password然后登录,遇到下面错误: <PRE>Oracle error 1403: java ...

  7. XMLHttpRequest是什么、如何完整地运行一次GET请求、如何检測错误。

    var xmlhttp; function LoadXmlDoc(url){ xmlhttp = null; if(window.XMLHttpRequest){ //code for all new ...

  8. 2014MadCon厦门分享会-笔记(下)

    32 <如何与百度互动,不知道这些就不要做SEO了>百度站长平台资深产品运营师 曹丽丽(飞鸟) 33 注意百度站长平台的提醒.如果你不留电话,不留其他联系方式,出问题了,百度怎么提醒你呢? ...

  9. 创建节点createElement

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  10. linux进程间通信消息队列:msgsnd: Invalid argument

    今天写了个消息队列的小测试程序结果send端程序总是出现:msgsnd: Invalid argument,搞了半个小时也没搞明白,后来查资料发现我将(st_msg_buf.msg_type = 0; ...