Пример #1
0
        /// <summary>
        /// 调用外部服务。对方会返回一个或一组流程ID。本函数返回这组ID对应的流程。
        /// </summary>
        /// <param name="startupParams"></param>
        /// <param name="template"></param>
        /// <returns></returns>
        private WfProcessCollection InvokeBranchProcess(WfServiceStartupProcessParams startupParams, IWfBranchProcessTemplateDescriptor template)
        {
            this.Process.ApplicationRuntimeParameters["serviceOP_Paramas"] = startupParams;

            WfServiceInvoker svcInvoker = new WfServiceInvoker(template.OperationDefinition);

            object obj = svcInvoker.Invoke();

            WfProcessCollection processes          = new WfProcessCollection();
            WfBranchProcessTemplateDescriptor temp = template as WfBranchProcessTemplateDescriptor;

            IList array = obj as IList;

            if (array != null)
            {
                IWfProcess process = null;
                foreach (string processID in array)
                {
                    process = WfRuntime.GetProcessByProcessID(processID);
                    processes.Add(process);
                }

                temp.BranchProcessKey = process.Descriptor.Key;
            }
            else
            {
                IWfProcess process = WfRuntime.GetProcessByProcessID(obj.ToString());
                processes.Add(process);
                temp.BranchProcessKey = process.Descriptor.Key;
            }

            return(processes);
        }
		protected void buttonCallBranchProcess_Click(object sender, EventArgs e)
		{
			WfServiceAddressDefinition address = new WfServiceAddressDefinition(WfServiceRequestMethod.Post,
				"http://localhost/MCSWebApp/WfFormTemplate/Services/WfProcessService.svc",
				WfServiceContentType.Json);

			WfServiceOperationDefinition definition = new WfServiceOperationDefinition(address, "StartBranchProcesses");

			WfServiceOperationParameter p1 = new WfServiceOperationParameter("ownerActivityID", UuidHelper.NewUuidString());

			IWfBranchProcessTemplateDescriptor template = new WfBranchProcessTemplateDescriptor("Test");
			WfBranchProcessTransferParams transferParams = new WfBranchProcessTransferParams(template);

			WfServiceOperationParameter p2 = new WfServiceOperationParameter("branchTransferParams", WfSvcOperationParameterType.RuntimeParameter, "transferParams");

			definition.Params.Add(p1);
			definition.Params.Add(p2);

			WfServiceInvoker invoker = new WfServiceInvoker(definition);

			WfServiceInvoker.InvokeContext["transferParams"] = transferParams;

			object result = invoker.Invoke();

			resultLabel.Text = Server.HtmlEncode(result.ToString());
		}
		protected void buttonGetServiceName_Click(object sender, EventArgs e)
		{
			WfServiceAddressDefinition address = new WfServiceAddressDefinition(WfServiceRequestMethod.Post,
				"http://localhost/MCSWebApp/WfFormTemplate/Services/WfProcessService.svc",
				WfServiceContentType.Json);

			WfServiceOperationDefinition definition = new WfServiceOperationDefinition(address, "GetServerTime");
			WfServiceInvoker invoker = new WfServiceInvoker(definition);

			object result = invoker.Invoke();

			resultLabel.Text = Server.HtmlEncode(result.ToString());
		}
        public void CallServiceTest()
        {
            WfServiceOperationDefinitionConfigurationElement operationElement =
                WfServiceDefinitionSettings.GetSection().Operations["PCGetVersion"];

            Assert.IsNotNull(operationElement);

            WfServiceOperationDefinition operation = new WfServiceOperationDefinition(operationElement);

            WfServiceInvoker.InvokeContext["Version"] = string.Empty;
            WfServiceInvoker.InvokeContext["callerID"] = "Zheng Shen";

            WfServiceInvoker invoker = new WfServiceInvoker(operation);

            invoker.Invoke();

            string result = WfServiceInvoker.InvokeContext.GetValue("Version", string.Empty);

            Console.WriteLine(result);

            Assert.IsTrue(result.IndexOf(WfServiceInvoker.InvokeContext.GetValue("callerID", string.Empty)) >= 0);
        }
		private void InvokeService()
		{
			WfServiceInvoker svcInvoker = new WfServiceInvoker(SvcOpDef);
			SvcOpDef.OperationName = "Add";
			SvcOpDef.Params.Clear();
			SvcOpDef.Params.Add(new WfServiceOperationParameter()
			{
				Name = "a",
				Type = WfSvcOperationParameterType.Int,
				Value = 50
			});
			SvcOpDef.Params.Add(new WfServiceOperationParameter()
			{
				Name = "b",
				Type = WfSvcOperationParameterType.Int,
				Value = 5
			});
			var result = svcInvoker.Invoke();
			Console.WriteLine(result.GetType().ToString() + result.ToString());

			SvcOpDef.OperationName = "AddDecimal";
			result = svcInvoker.Invoke();
			Console.WriteLine(result.GetType().ToString() + result.ToString());

			SvcOpDef.OperationName = "AddDouble";
			result = svcInvoker.Invoke();
			Console.WriteLine(result.GetType().ToString() + result.ToString());

			SvcOpDef.Params.Clear();

			SvcOpDef.OperationName = "GetDate";
			result = svcInvoker.Invoke();
			Console.WriteLine(result.GetType().ToString() + result.ToString());
			SvcOpDef.OperationName = "IsTrue";
			result = svcInvoker.Invoke();
			Console.WriteLine(result.GetType().ToString() + result.ToString());
			SvcOpDef.OperationName = "SayHelloWorld";
			result = svcInvoker.Invoke();
			Console.WriteLine(result.GetType().ToString() + result.ToString());

			SvcOpDef.OperationName = "GetDayTimeSpan";
			SvcOpDef.AddressDef.RequestMethod = WfServiceRequestMethod.Soap;
			result = svcInvoker.Invoke();
			Console.WriteLine(result.GetType().ToString() + result.ToString());
		}
		public void WcfServiceTest()
		{
			WfNetworkCredential credential = new WfNetworkCredential();
			string url = @"http://localhost/MCSWebApp/WcfServiceDemo/Service1.svc";
			string addressKey = "testaddress";
			WfServiceAddressDefinition addressDef =
				new WfServiceAddressDefinition(WfServiceRequestMethod.Post, credential, url);
			addressDef.Key = addressKey;
			addressDef.ContentType = WfServiceContentType.Json;

			WfGlobalParameters.Default.ServiceAddressDefs.Add(addressDef);

			string paraVal = @"{""BoolValue"":""true"",""StringValue"":""test""}";
			WfServiceOperationParameter operationParam =
				new WfServiceOperationParameter() { Name = "composite", Type = WfSvcOperationParameterType.String, Value = paraVal };
			WfServiceOperationDefinition operationDef =
				new WfServiceOperationDefinition(addressKey, "PostContract", new WfServiceOperationParameterCollection() { operationParam }, "");
			WfServiceInvoker invoker = new WfServiceInvoker(operationDef);
			var result = invoker.Invoke();
			Console.WriteLine(result.ToString());
		}
Пример #7
0
        /// <summary>
        /// 调用外部服务。对方会返回一个或一组流程ID。本函数返回这组ID对应的流程。
        /// </summary>
        /// <param name="startupParams"></param>
        /// <param name="template"></param>
        /// <returns></returns>
        private WfProcessCollection InvokeBranchProcess(WfServiceStartupProcessParams startupParams, IWfBranchProcessTemplateDescriptor template)
        {
            this.Process.ApplicationRuntimeParameters["serviceOP_Paramas"] = startupParams;

            WfServiceInvoker svcInvoker = new WfServiceInvoker(template.OperationDefinition);

            object obj = svcInvoker.Invoke();

            WfProcessCollection processes = new WfProcessCollection();
            WfBranchProcessTemplateDescriptor temp = template as WfBranchProcessTemplateDescriptor;

            IList array = obj as IList;

            if (array != null)
            {
                IWfProcess process = null;
                foreach (string processID in array)
                {
                    process = WfRuntime.GetProcessByProcessID(processID);
                    processes.Add(process);
                }

                temp.BranchProcessKey = process.Descriptor.Key;
            }
            else
            {
                IWfProcess process = WfRuntime.GetProcessByProcessID(obj.ToString());
                processes.Add(process);
                temp.BranchProcessKey = process.Descriptor.Key;
            }

            return processes;
        }