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. Flink的安装配置

    一. Flink的下载 安装包下载地址:http://flink.apache.org/downloads.html  ,选择对应Hadoop的Flink版本下载 [admin@node21 soft ...

  2. 9.Java web—JSP内置对象

    容器内置了9大对象,这些对象在jsp页无需实例化,可以直接使用. 分别为request. response .session. application .out. pageContext .confi ...

  3. 如何快速的知道Maven插件的命令行输入参数

    用命令行使用Maven的插件时,-D表示属性的输入,-P表示构建配置文件的输入. 比如要使用package生命周期阶段对Application项目进行打包jar时,查找方式如下: 1.由于packag ...

  4. 深入理解iPhone数据持久化(手把手教你iphone开发 – 基础篇)

    在所有的移动开发平台数据持久化都是很重要的部分:在j2me中是rms或保存在应用程序的目录中,在symbian中可以保存在相应的磁盘目录中和数据库中.symbian中因为权限认证的原因,在3rd上大多 ...

  5. BUPT复试专题—C翻转(2010)

    https://www.nowcoder.com/practice/74bdb725421c4f80b4aca7266818baf0?tpId=67&tqId=29639&rp=0&a ...

  6. linux find 命令查找 复制

    find 查找 find . -mtime -2 -a -path './.git*' -prune , -path './Cache' -prune -a -exec cp {} one \; rm ...

  7. app具体介绍界面-01

    在我们的上一篇博客中,我们介绍了首页中的app列表界面怎样完毕.这个ListView以及其Adapter会在我们后面的界面中重用,所以这个是比較重要的,在这一篇博客中,我们先完毕app具体介绍界面的一 ...

  8. php生成.php文件

    <?php // -- test.php -- // //搜集资料 $str_tmp="<?php\r\n"; //得到php的起始符.$str_tmp将累加 $str ...

  9. 文件宝局域网传输/播放功能使用帮助(Mac电脑用户)

    使用局域网账户密码登录,可以访问电脑上所有文件 使用游客无账户密码登录,只能访问电脑上指定共享文件夹的文件. 怎么设置共享文件夹请参考: 1.打开“共享”偏好设置(选取苹果菜单 >“系统偏好设置 ...

  10. SKStoreReviewController之程序内评价

    在iOS 10.3出现之前,App实现评价方式一般有两种: (一)deep link调用.在app 链接地址后面拼上action=write-review这种方式可以实现程序内评价: (二)App跳转 ...