通过JavaScript调用SOAP终结点执行实体消息
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复148或者20150813可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me!
//Add the code you want to test here:
// You must use the SoapLoggerOrganizationService 'slos' proxy rather than the IOrganizationService proxy you would normally use.
就是在这里写你要执行的消息,我这里以分享一个客户记录的读取权限给一个CRM的用户为例,C#版本的代码是这么写的:
var request = new GrantAccessRequest()
{
PrincipalAccess = new PrincipalAccess()
{
AccessMask = AccessRights.ReadAccess,
Principal = new EntityReference("systemuser", new Guid("CC06819E-9AD3-E411-80BC-00155D09F02E"))
},
Target = new EntityReference("account", new Guid("FB9A903E-FC3F-E511-80DF-00155D1D7B07"))
};
slos.Execute(request);
确保编译能通过后调试起来,我这里按 F5 启动起来,弹出如下窗口,我输入如下,我这个CRM环境没有做IFD,但是是使用HTTS绑定的,所以第二个选项我输入了Y,大家根据自己的环境做选择啊。

HTTP REQUEST
--------------------------------------------------
POST https://crm2015.luoyong.com/SuGeGeDev/XRMServices/2011/Organization.svc/web
Content-Type: text/xml; charset=utf-8
SOAPAction: http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<request i:type="b:GrantAccessRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">
<a:Parameters xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<a:KeyValuePairOfstringanyType>
<c:key>Target</c:key>
<c:value i:type="a:EntityReference">
<a:Id>fb9a903e-fc3f-e511-80df-00155d1d7b07</a:Id>
<a:LogicalName>account</a:LogicalName>
<a:Name i:nil="true" />
</c:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<c:key>PrincipalAccess</c:key>
<c:value i:type="b:PrincipalAccess">
<b:AccessMask>ReadAccess</b:AccessMask>
<b:Principal>
<a:Id>cc06819e-9ad3-e411-80bc-00155d09f02e</a:Id>
<a:LogicalName>systemuser</a:LogicalName>
<a:Name i:nil="true" />
</b:Principal>
</c:value>
</a:KeyValuePairOfstringanyType>
</a:Parameters>
<a:RequestId i:nil="true" />
<a:RequestName>GrantAccess</a:RequestName>
</request>
</Execute>
</s:Body>
</s:Envelope>
-------------------------------------------------- HTTP RESPONSE
--------------------------------------------------
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<ExecuteResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ExecuteResult i:type="b:GrantAccessResponse" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">
<a:ResponseName>GrantAccess</a:ResponseName>
<a:Results xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
</ExecuteResult>
</ExecuteResponse>
</s:Body>
</s:Envelope>
--------------------------------------------------
可以知道这个文件既记载了请求的消息文本,也记载了返回的消息文本。

这个工具怎么使用,官方有一篇文章:CRM 2011 Jscript Soap Request Formatter RELEASED!! 不过国内不能阅读到,原因你懂的,不懂的话你可能是比较少在中国大陆生活。我这里直接上用法了。


function ShareAccountReadRightRequest(AccountId,SystemUserId)
{
var requestMain = ""
requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">
";
requestMain += " <s:Body>
";
requestMain += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">
";
requestMain += " <request i:type=\"b:GrantAccessRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">
";
requestMain += " <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">
";
requestMain += " <a:KeyValuePairOfstringanyType>
";
requestMain += " <c:key>Target</c:key>";
requestMain += " <c:value i:type=\"a:EntityReference\">
";
requestMain += " <a:Id>
";
requestMain += AccountId;
requestMain += "
</a:Id>";
requestMain += " <a:LogicalName>account</a:LogicalName>";
requestMain += " <a:Name i:nil=\"true\" />";
requestMain += "
</c:value>";
requestMain += "
</a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>
";
requestMain += " <c:key>PrincipalAccess</c:key>";
requestMain += " <c:value i:type=\"b:PrincipalAccess\">
";
requestMain += " <b:AccessMask>ReadAccess</b:AccessMask>";
requestMain += " <b:Principal>
";
requestMain += " <a:Id>
";
requestMain += SystemUserId;
requestMain += "
</a:Id>";
requestMain += " <a:LogicalName>systemuser</a:LogicalName>";
requestMain += " <a:Name i:nil=\"true\" />";
requestMain += "
</b:Principal>";
requestMain += "
</c:value>";
requestMain += "
</a:KeyValuePairOfstringanyType>";
requestMain += "
</a:Parameters>";
requestMain += " <a:RequestId i:nil=\"true\" />";
requestMain += " <a:RequestName>GrantAccess</a:RequestName>";
requestMain += "
</request>";
requestMain += "
</Execute>";
requestMain += "
</s:Body>";
requestMain += "
</s:Envelope>";
var req = new XMLHttpRequest();
//req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", true);
req.open("POST", GetGlobalContext().getClientUrl() + "/XRMServices/2011/Organization.svc/web", true);
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
req.onreadystatechange = function () { CallSOAPResponse(req); };
req.send(requestMain);
} function CallSOAPResponse(req)
{
if (req.readyState == 4) {
req.onreadystatechange = null; //avoids memory leaks
if (req.status == 200) {
//成功我这里什么都不做
}
else {
Xrm.Utility.alertDialog("共享客户失败。请确保共享给的用户对客户实体至少具有最低级别的读取权限。");
}
}
}
这样就可以方便的在JavaScript中调用了。
通过JavaScript调用SOAP终结点执行实体消息的更多相关文章
- JavaScript 究竟是怎样执行的?
摘要: 理解 JS 引擎运行原理. 作者:前端小智 原文:搞懂 JavaScript 引擎运行原理 Fundebug经授权转载,版权归原作者所有. 一些名词 JS 引擎 - 一个读取代码并运行的引擎, ...
- 翻译-使用Spring调用SOAP Web Service
原文链接: http://spring.io/guides/gs/consuming-web-service/ 调用SOAP web service 本指南将指导你使用Spring调用一个基于SOAP ...
- 使用IPostBackEventHandler让JavaScript“调用”回传事件
在由ASP.NET所谓前台调用后台.后台调用前台想到HTTP——实践篇(二)通过自己模拟HTML标签事件与服务器交互,讲了ASP.NET的服务器控件是怎么render成HTML后市怎么“调用”后台方法 ...
- [转]Javascript中的自执行函数表达式
[转]Javascript中的自执行函数表达式 本文转载自:http://www.ghugo.com/javascript-auto-run-function/ 以下是正文: Posted on 20 ...
- 深入理解javascript中的立即执行函数(function(){…})()
投稿:junjie 字体:[增加 减小] 类型:转载 时间:2014-06-12 我要评论 这篇文章主要介绍了深入理解javascript中的立即执行函数,立即执行函数也叫立即调用函数,通常它的写法是 ...
- Axis2(10):使用soapmonitor模块监视soap请求与响应消息
在Axis2中提供了一个Axis2模块(soapmonitor),该模块实现了与<WebService大讲堂之Axis2(9):编写Axis2模块(Module)>中实现的logging模 ...
- javascript 作用域链与执行环境
前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! 作用域.作用域链.执行环境.执行环境栈以及this的概念在javascript中非常重要,本人经常弄混淆, ...
- 怎么样加快JavaScript加载和执行效率
概览 无论当前 JavaScript 代码是内嵌还是在外链文件中,页面的下载和渲染都必须停下来等待脚本执行完成.JavaScript 执行过程耗时越久,浏览器等待响应用户输入的时间就越长.浏览器在下载 ...
- javascript调用Flash里对象的方法(函数)搞了五个小时。
搞了几个小时后,才发现,之前走的路是错的. 今天在Firefox浏览器上测试一个javascript调用Flash中的一个对象的方法时遇到问题了, 一搞就整整搞了一个下午. 我记得之前我用Flash8 ...
随机推荐
- 3-1.Hadoop单机模式安装
Hadoop单机模式安装 一.实验介绍 1.1 实验内容 hadoop三种安装模式介绍 hadoop单机模式安装 测试安装 1.2 实验知识点 下载解压/环境变量配置 Linux/shell 测试Wo ...
- ReactNative问题随记1 Exception in thread "main" java.lang.RuntimeException: gradle-2.14.1-all.zip
ReactNative问题随记 想运行在真机上,在运行命令react-native run-android遇到错误如下: Scanning 559 folders for symlinks in D: ...
- [Swift]LeetCode326. 3的幂 | Power of Three
Given an integer, write a function to determine if it is a power of three. Example 1: Input: 27 Outp ...
- [Swift]LeetCode473. 火柴拼正方形 | Matchsticks to Square
Remember the story of Little Match Girl? By now, you know exactly what matchsticks the little match ...
- java面向对象三大特性:封装、继承、多态
一.封装 封装也称信息隐藏,是指利用抽象数据类型把数据和基于数据的操作封装起来,使其成为一个不可分割的整体,数据隐藏在抽象数据内部,尽可能的隐藏数据细节,只保留一些接口使其与外界发生联系.也就是说用户 ...
- Javaweb编程中的乱码问题
程序中的乱码问题,主要出现在我们处理中文数据的过程中出现.从浏览器向服务器请求数据,服务器返回的数据在浏览器中显示为乱码.或者是服务器中的java文件用到中文,也有可能会出现乱码.数据库在处理数据的时 ...
- Python内置函数(11)——classmethod
英文文档: classmethod(function) Return a class method for function. A class method receives the class as ...
- 「造个轮子」——cicada 源码分析
前言 两天前写了文章<「造个轮子」--cicada(轻量级 WEB 框架)> 向大家介绍了 cicada 之后收到很多反馈,也有许多不错的建议. 同时在 GitHub 也收获了 80 几颗 ...
- qt delete
在写博文之前,先推荐一篇文章,我觉着挺不错,也是qt中delete相关:QT父子与QT对象delete 学习C++的童鞋都知道new和delete必须是同时出现的,否则就会导致内存泄露 ...
- 知识小罐头03(idea+maven+部署war包到tomcat 上)
自学的的小伙伴第一就要用maven!自学的的小伙伴第一就要用maven!自学的的小伙伴第一就要用maven! 重要的事说三遍!maven本质上,其实就是一种目录的格式,没有什么特别的地方!而且,你可以 ...