Call SOAP service like this:
vNewVar:=selfVM.SoapCall('http://www.webserviceX.NET/stockquote.asmx','GetQuote','http://www.webserviceX.NET/','','','NestingWParams')
SoapCall returns the body of the soap-envelope that is returned from the called service.
SoapCalls take a action (above 'GetQuote') and set this as SOAPAction header, the action is also included in the request body.
We build the soapEnvelope for the request with code like below - if you send in a action namespace we use it accordingly
StringBuilder soapenvelopebuilder = new StringBuilder(); soapenvelopebuilder.Append(@"<?xml version = '1.0' encoding='utf-8' ?>"); soapenvelopebuilder.Append(@"<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">"); soapenvelopebuilder.Append(soapheaderbuilder); soapenvelopebuilder.Append(" <soap:Body " + @" xmlns:nsAction=""" + actionnamespace + @""">"); soapenvelopebuilder.Append(@" <nsAction:" + action + ">"); soapenvelopebuilder.Append(parametersForSoapCall); soapenvelopebuilder.Append(@" </nsAction:" + action + @">"); soapenvelopebuilder.Append(" </soap:Body>"); soapenvelopebuilder.Append("</soap:Envelope>");
In the code above we see the parametersForSoapCall
private StringBuilder GetParamsForSoapCall(ViewModelReferenceType vmref, string nestingWithParams) { StringBuilder parametersForSoapCall = new StringBuilder(); if (!string.IsNullOrEmpty(nestingWithParams)) { ViewModelClass vmc; if ((vmref.Value as ViewModel).AllViewModelClasses.TryGetValue(nestingWithParams, out vmc)) { var root = (vmref.Value as ViewModel).GetOclVariableValueFromName(vmc.NameOfCurrentVariable_Ocl()); if (root != null && root.AsObject == null && (vmref.Value as ViewModel).RootObject != null) root = (vmref.Value as ViewModel).RootObject.AsIObject(); DoSoapCallParamForRoot(vmref, root, vmc, parametersForSoapCall); } } return parametersForSoapCall; } private void DoSoapCallParamForRoot(ViewModelReferenceType vmref, IElement root, ViewModelClass vmc, StringBuilder parametersForSoapCall) { // find potential namespace columns Dictionary<string, string> namespaces = new Dictionary<string, string>(); foreach (var col in vmc.ViewModel.RootViewModelClass.Columns) { if (col.RuntimeName.StartsWith("ns") && col.ExpressionResultType != null && col.ExpressionResultType.ObjectType == typeof(string)) { namespaces.Add(col.RuntimeName, EcoServiceHelper.GetEcoService<IOclService>((vmref.Value as ViewModel).EcoServiceProvider).Evaluate(root, col.Expression, (vmref.Value as ViewModel).GetIExternalVariableList()).AsObject as string); } } foreach (var col in vmc.Columns) { var colresult = EcoServiceHelper.GetEcoService<IOclService>((vmref.Value as ViewModel).EcoServiceProvider).Evaluate(root, col.Expression, (vmref.Value as ViewModel).GetIExternalVariableList()); if (colresult != null) { var nsForParam = "nsAction:"; var colnamewithoutns = col.RuntimeName; var nsdef = ""; var nameparts = colnamewithoutns.Split('_'); if (nameparts.Count() > 1) { if (namespaces.ContainsKey(nameparts[0])) { nsForParam = nameparts[0] + ":"; colnamewithoutns = colnamewithoutns.Replace(nameparts[0] + "_", ""); nsdef = " xmlns:" + nameparts[0] + "=" + @"""" + namespaces[nameparts[0]] + @""""; } } if (col.DetailAssociation != null) { // Allow for structures in input string paramline = ""; StringBuilder parametersForNesting = new StringBuilder(); DoSoapCallParamForRoot(vmref, root, col.DetailAssociation, parametersForNesting); paramline = "<" + nsForParam + colnamewithoutns + nsdef + ">" + parametersForNesting.ToString() + "</" + nsForParam + colnamewithoutns + ">"; parametersForSoapCall.Append(paramline); } else { string paramline = ""; //<SomeParam xsi:type=""xsd:integer"">12</SomeParam> var value = colresult.AsObject; if (value != null) { paramline = value.ToString(); } paramline = "<" + nsForParam + colnamewithoutns + nsdef + ">" + paramline + "</" + nsForParam + colnamewithoutns + ">"; parametersForSoapCall.Append(paramline); } } } }
special variables
ViewModel variable named vSoapDebug – when we find this in the ViewModel – we assign the complete SoapEnvelope to this prior to sending it.