Dynamics CRM 2011 编程系列(23):用插件调用WCF
来源:互联网 发布:png软件图标 编辑:程序博客网 时间:2024/05/18 03:28
上篇博文介绍了用插件调用Web Service的方法,现在我们来试试用插件调用WCF吧。在.NET 4.0的体系结构里,已经把Web Service集成到WCF中了,在日常的开发中免不了需要用到这种方法来完成某些系统集成的开发。
具体的操作如下图:
图1 需要调用的服务
图2
图3
图4
图5
图6
图7
图8
插件代码
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.ServiceModel;using Microsoft.Xrm.Sdk;using Microsoft.Xrm.Sdk.Messages;namespace Plugin22{ public class CallWCF : IPlugin { public void Execute(IServiceProvider serviceProvider) { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); Entity curEntity = (Entity)context.InputParameters["Target"]; int num1 = (int)curEntity["new_num1"]; int num2 = (int)curEntity["new_num2"]; int result = 0; OptionSetValue optType = (OptionSetValue)curEntity["new_opt_type"]; var binding = new BasicHttpBinding(); var address = new EndpointAddress("http://localhost:83/Calculator.svc"); Plugin22.Service.CalculatorClient calculator = new Service.CalculatorClient(binding, address); switch (optType.Value) { case 100000000: result = calculator.ADD(num1, num2); break; case 100000001: result = calculator.SUB(num1, num2); break; case 100000002: result = calculator.MUL(num1, num2); break; case 100000003: result = calculator.DIV(num1, num2); break; } if (curEntity.Attributes.Contains("new_result")) { curEntity["new_result"] = result; } else { curEntity.Attributes.Add("new_result", result); } } }}
- Dynamics CRM 2011 编程系列(23):用插件调用WCF
- Dynamics CRM 2011 编程系列(16):插件
- Dynamics CRM 2011 编程系列(22):用插件调用Web Service
- Dynamics CRM 2011编程系列
- Dynamics CRM 2011编程系列
- Dynamics CRM 2011 编程系列(18):插件中的Read操作
- Dynamics CRM 2011 编程系列(19):插件中的事务
- Dynamics CRM 2011 编程系列(20):插件队列
- Dynamics CRM 2011 编程系列(21):插件调试
- Dynamics CRM 2011 编程系列(25):插件的依赖注入
- Dynamics CRM 2011 编程系列(17):用插件来实现实体的CRUD
- Dynamics CRM 2011编程系列(48): WCF Service 和 Web Service 程序的部署
- Dynamics CRM 2011 编程系列:自定义工作流
- Dynamics CRM 2011 编程系列(24):在插件中使用早期绑定
- Dynamics CRM 2011编程系列(37):调用报表的72般绝技
- Dynamics CRM 2011编程系列(38):调用报表的神器(GhostHook)
- Dynamics CRM 2011编程系列(55):Dynamics CRM 集成开发简述
- Dynamics CRM 2011 编程系列(26):自定义工作流
- 每日一练
- php安装程序的版本选择
- 《Effective C++》条款03:两个成员函数如果只是常量性不同可以被重载
- Dynamics CRM 2011 编程系列(22):用插件调用Web Service
- TTS Events Explanation
- Dynamics CRM 2011 编程系列(23):用插件调用WCF
- Short URL implement
- 日期格式参考extjs api文档中的Date类型
- Android界面基本属性
- windows开机出现‘应用程序正常初始化(0xc0000044)失败’进不了系统
- 各国插座标准
- The listenersupports no services
- Dynamics CRM 2011 编程系列(30):使用ASP.NET Ajax技术的自定义页面
- gridview排序