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. perf stat 输出解读

    http://zhengheng.me/2015/11/12/perf-stat/ http://zhengheng.me/2015/08/30/perf-tools/

  2. [转] SQL Server中变量的声明和使用方法

    原文地址 SQL Server中变量的声明和使用方法 声明局部变量语法: DECLARE @variable_name DataType 其中 variable_name为局部变量的名称,DataTy ...

  3. 机器学习优化方法总结比较(SGD,Adagrad,Adadelta,Adam,Adamax,Nadam)

    SGD: 此处的SGD指mini-batch gradient descent,关于batch gradient descent, stochastic gradient descent, 以及 mi ...

  4. 【paddle学习】识别数字

    Softmax回归(Softmax Regression) 最简单的Softmax回归模型是先将输入层经过一个全连接层得到的特征,然后直接通过softmax 函数进行多分类 输入层的数据$X$传到输出 ...

  5. Python机器学习-分类

    监督学习下的分类模型,主要运用sklearn实践 kNN分类器 决策树 朴素贝叶斯 实战一:预测股市涨跌 # -*- coding: utf-8 -*- """ Crea ...

  6. 谷歌訪问之直接输入ip地址

    废话啥说.直接上IP: 173.194.121.51 173.194.43.19 173.194.65.147 74.125.235.148

  7. java学习笔记(四)面向对象

    一.形參长度可变的方法 当传入被调用的函数參数数量不确定时,在方法最后一个形參的类型后加上三个点号(...),表明该形參能够接受多个參数值.多个參数值被当做数组传入,这些參数必须为指定的类型. pac ...

  8. mmall 项目实战(一)项目初始化

    1.创建 数据库 及 表 数据脚本: /* Navicat Premium Data Transfer Source Server : 182.92.82.103 Source Server Type ...

  9. Classification and logistic regression

    logistic 回归 1.问题: 在上面讨论回归问题时.讨论的结果都是连续类型.但假设要求做分类呢?即讨论结果为离散型的值. 2.解答: 假设: 当中: g(z)的图形例如以下: 由此可知:当hθ( ...

  10. ruby rails

    http://www.zhihu.com/question/19552402   作者:陈振宇链接:http://www.zhihu.com/question/19552402/answer/1236 ...