作为个人备忘,不做排版。此扩展函数用于DomainServices的Load及SubmitChanges时处理Error信息,包括验证消息、实体冲突。

 public static string ToErrorString(this System.ServiceModel.DomainServices.Client.OperationBase op)
{
//来自http://www.cnblogs.com/ainijiutian/p/3616198.html
if (op.HasError)
{
op.MarkErrorAsHandled(); System.Text.StringBuilder sb = new System.Text.StringBuilder();
if (op is System.ServiceModel.DomainServices.Client.LoadOperation)
{
var lo = op as System.ServiceModel.DomainServices.Client.LoadOperation;
if (lo.ValidationErrors != null && lo.ValidationErrors.Any())
{
sb.Append("Validation Errors:\r\n" + string.Join("\r\n", lo.ValidationErrors.Select(t => t.ErrorMessage)) + "\r\n\r\n");
}
sb.Append("Error message:\r\n" + lo.Error.ToString()); return sb.ToString();
}
else if (op is System.ServiceModel.DomainServices.Client.SubmitOperation)
{
var so = op as System.ServiceModel.DomainServices.Client.SubmitOperation;
if (so.EntitiesInError != null && so.EntitiesInError.Any())
{
foreach (var e in so.EntitiesInError)
{
sb.Append(so.EntitiesInError.First().GetType() + " " + e.ToString() + ":\r\n");
if (e.HasValidationErrors)
{
sb.Append("Validation Errors:\r\n" + string.Join("\r\n", e.ValidationErrors.Select(t => t.ErrorMessage)) + "\r\n");
}
if (!e.EntityConflict.IsDeleted && e.EntityConflict != null && e.EntityConflict.PropertyNames != null && e.EntityConflict.PropertyNames.Any())
{
sb.Append("Entity conflict:\r\n" + string.Join(", ", e.EntityConflict.PropertyNames) + "\r\n");
}
}
sb.Append("\r\n");
}
sb.Append("Error message:\r\n" + so.Error.ToString());
//if (sb.ToString().Contains("STAMP")) //timestamp
//{
// return "Document has been changed in other place,please undo the current changes and reopen .";
//}
//else
//{
// return sb.ToString();
//}
return sb.ToString();
}
}
return op.ToString();
}

[WCF]DomainServices客户端操作异常处理的更多相关文章

  1. WCF基础教程之异常处理:你的Try..Catch语句真的能捕获到异常吗?

    在上一篇WCF基础教程之开篇:创建.测试和调用WCF博客中,我们简单的介绍了如何创建一个WCF服务并调用这个服务.其实,上一篇博客主要是为了今天这篇博客做铺垫,考虑到网上大多数WCF教程都是从基础讲起 ...

  2. WCF 学习笔记之异常处理

    WCF 学习笔记之异常处理 1:WCF异常在配置文件 <configuration> <system.serviceModel> <behaviors> <s ...

  3. WCF学习之旅—WCF中传统的异常处理(十六)

    WCF中的异常处理 在软件开发过程中,不可能没有异常的出现,所以在开发过程中,对不可预知的异常进行解决时,异常处理显得尤为重要.对于一般的.NET系统来说,我们简单地借助try/catch可以很容易地 ...

  4. [WCF编程]10.操作:流操作

    一.流操作概述 在默认情况下,当客户端调用服务时,服务只有在接收到完整的消息后才会被调用,同样,客户端只有在包含了调用结果的返回消息被完整接受时,才会解除对它的阻塞. 对于数据量小的消息,这种交换模式 ...

  5. 重温WCF之WCF传输安全(十三)(4)基于SSL的WCF对客户端采用证书验证(转)

    转载地址:http://www.cnblogs.com/lxblog/archive/2012/09/20/2695397.html 前一篇我们演示了基于SSL的WCF 对客户端进行用户名和密码方式的 ...

  6. 重温WCF之构建一个简单的WCF(一)(2)通过Windows Service寄宿服务和WCF中实现操作重载

    参考地址:http://www.cnblogs.com/zhili/p/4039111.html 一.如何在Windows Services中寄宿WCF服务 第一步:创建Windows 服务项目,具体 ...

  7. 使用WCF测试客户端 z

    http://blog.csdn.net/u013036274/article/details/50570989 [是什么] WCF测试客户端(WCF Test Client)是一个用来测试WCF服务 ...

  8. WebService及WCF获取客户端IP,端口

    wcf获取客户端IP,端口 var context = OperationContext.Current; var properties = context.IncomingMessageProper ...

  9. 启用WCF测试客户端的相关技巧

    在Visual Studio之外打开WCF测试客户端有两种方法:第一种方法是到其所在路径(Visual Studio安装路径\Common7\IDE\WcfTestClient.exe)双击打开.第二 ...

随机推荐

  1. Python实战2( 接上):扫描多余中文

    还是接上一篇,扫描多余中文,支持自定义忽略字段 源代码,详看   http://pan.baidu.com/s/1ntC78Zv   ScanChinese.zip

  2. iostat命令学习

    iostat命令主要用于监控linux系统下cup和磁盘IO的统计信息 可以通过iostat --help获得该命令的帮助信息 [oracle@std ~]$ iostat --help Usage: ...

  3. PHP性能监测的工具介绍 - XHProf

    http://segmentfault.com/a/1190000003509917 http://www.cnblogs.com/casatwy/archive/2013/01/17/2865241 ...

  4. 前端开发与SEO

    前端开发中通过一些小习惯,可以有利于SEO,本着蚊子再小也是肉的原则,能抓住自然不能忽略. 1.控制首页链接数量,不能过多,也不要太少.更不要为了凑数而添加 2.扁平化层次,力争跳转三次可以到任何页面 ...

  5. Python强化训练笔记(七)——使用deque队列以及将对象保存为文件

    collections模块中的deque对象是一个队列,它有着正常队列的先进先出原则.我们可以利用这个对象来实现数据的保存功能. 例如,现有一个猜数字大小的游戏,系统开始会随机roll点一个0-100 ...

  6. Log4Net

    注意事项 <!-- The file log4Net.config is copied into bin/Debug /release by compiler 添加如下内容到 assemblyi ...

  7. javascript入门:prototype和面向对象的实现

    由于工作需要,需要大量使用javascript,于是对其进行了一下学习. 学习任何一个语言,最重要的是掌握其和其他语言不同的关键特性.对javascript来说,我总结就是prototype.就像me ...

  8. js 小知识

    在iframe 页面获取父级页面的 html var obj = window.parent.document.getElementById('modaliframe'); 解决Jquery 的在一个 ...

  9. Linux 基础命令-CURL 表单上传文件

    CURL -F, --form <name=content> (HTTP) This lets curl emulate a filled-in form in which a user ...

  10. QtAlgorithms

    qSort() qCopy() qFill() #include <QCoreApplication> #include<QDebug> #include<QVector ...