Пример #1
0
        public string CreateSoapEnvelope(WfServiceOperationParameterCollection operationParams)
        {
            if (this._SvcOperationDef == null)
            {
                throw new ArgumentNullException("WfServiceOperationDefinition不能为空!");
            }

            if (this._SvcOperationDef.OperationName.IsNullOrEmpty())
            {
                throw new ArgumentNullException("OperationName不能为空!");
            }

            XNamespace methodNS         = this._SvcOperationDef.AddressDef.ServiceNS;
            XElement   operationElement = new XElement(methodNS + this._SvcOperationDef.OperationName);

            foreach (WfServiceOperationParameter paramDef in operationParams)
            {
                XElement paraElement = new XElement(paramDef.Name);

                if (paramDef.Type == WfSvcOperationParameterType.RuntimeParameter)
                {
                    Type           dataType  = paramDef.Value.GetType(); //mark 须从流程上下文取值,目前只是为了方便
                    PropertyInfo[] propsInfo = dataType.GetProperties();

                    //mark 用反射属性?还是用xml serialize?
                    foreach (PropertyInfo item in propsInfo)
                    {
                        object propVal = item.GetValue(paramDef.Value, null);

                        if (propVal == null)
                        {
                            continue;
                        }

                        paraElement.Add(new XElement(item.Name, propVal));
                    }
                }

                operationElement.Add(paraElement);
            }

            XElement envelopeElement = XElement.Parse(@"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""><soap:Body></soap:Body></soap:Envelope>");
            XElement bodyElement     = (XElement)envelopeElement.FirstNode;

            bodyElement.Add(operationElement);

            XDeclaration xmlDeclare = new XDeclaration("1.0", "utf-8", "");
            XDocument    doc        = new XDocument(xmlDeclare, envelopeElement);

            using (StringWriter writer = new StringWriter())
            {
                doc.Save(writer);
                writer.Flush();

                //mark
                string trashStr = @" xmlns=""""";

                return(writer.ToString().Replace("utf-16", "utf-8").Replace(trashStr, ""));
            }
        }
 public WfServiceOperationDefinition(WfServiceAddressDefinition address,
                                     string operationName, WfServiceOperationParameterCollection parameters,
                                     string xmlStoreParaName)
 {
     this._AddressDef          = address;
     this.OperationName        = operationName;
     this.Params               = parameters;
     this.RtnXmlStoreParamName = xmlStoreParaName;
 }
        public WfServiceOperationDefinition(string addressKey,
                                            string operationName,
                                            WfServiceOperationParameterCollection parameters,
                                            string xmlStoreParaName)
        {
            if (WfGlobalParameters.Default.ServiceAddressDefs[addressKey] == null)
            {
                throw new ArgumentException(string.Format("无法找到Key为{0}的服务地址定义", addressKey));
            }

            this._AddressDef          = WfGlobalParameters.Default.ServiceAddressDefs[addressKey];
            this.OperationName        = operationName;
            this.Params               = parameters;
            this.RtnXmlStoreParamName = xmlStoreParaName;
        }