Exemplo n.º 1
0
 private void ValidateMissingField(BaseElement data, List <Node> nodeChildren, string path, int nodeCounter, List <string> errors)
 {
     if (nodeChildren[nodeCounter].IsMandatory && nodeChildren[nodeCounter].NodeName != "psp_SecureHash")
     {
         errors.Add("Missing field: " + path + nodeChildren[nodeCounter].NodeName);
     }
     if (nodeChildren[nodeCounter].NodeName == "psp_SecureHash" && data is RootElement &&
         !data.Children.Exists(x => x.Name == "psp_ClientSession"))
     {
         data.Children.Add(new SimpleElement("psp_SecureHash",
                                             ((RootElement)data).SecureHash(_wsdlHandlerConfiguration.SecretKey)));
     }
     if (nodeChildren[nodeCounter].NodeName == "SdkInfo")
     {
         data.Children.Add(new SimpleElement("SdkInfo", SdkVersion));
     }
     if (data is ComplexElement && nodeChildren[nodeCounter].NodeName == "psp_MerchantAdditionalDetails")
     {
         ((ComplexElement)data).Add("psp_MerchantAdditionalDetails", new ComplexElement {
             { "SdkInfo", SdkVersion }
         });
     }
 }
Exemplo n.º 2
0
        private static XmlDocument CreateSoapEnvelope(String url, String metodo, String nombreParametroInput, String tipoRequest, BaseElement data)
        {
            if (url.EndsWith(".php"))
            {
                url = url.Substring(0, url.Length - 4);
            }

            XmlDocument soapEnvelop = new XmlDocument();

            soapEnvelop.LoadXml(String.Format(@"<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/""><s:Body s:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:q2=""http://schemas.xmlsoap.org/soap/encoding/""><q1:{1} xmlns:q1=""{0}""><{2} href=""#id1""/></q1:{1}><q3:{3} id=""id1"" xsi:type=""q3:{3}"" xmlns:q3=""{0}"">{4}</q3:{3}></s:Body></s:Envelope>", url, metodo, nombreParametroInput, tipoRequest, data.Serialize()));

            return(soapEnvelop);
        }
Exemplo n.º 3
0
            internal RootElement Call(BaseElement data)
            {
                List <String> errors;

                if (!Validate(data, out errors))
                {
                    throw new Exception(String.Join("\n", errors));
                }

                HttpWebRequest webRequest      = null;
                XmlDocument    soapEnvelopeXml = null;

                if (_wsdlHandlerConfiguration.customEnvUrls != null)
                {
                    Int32 requestTimeoutLeft = _wsdlHandlerConfiguration.RequestTimeout;
                    foreach (string url in _wsdlHandlerConfiguration.customEnvUrls)
                    {
                        var watch = System.Diagnostics.Stopwatch.StartNew();
                        soapEnvelopeXml = CreateSoapEnvelope(url, ServiceName, InputParameterName, InputType, data);
                        try
                        {
                            webRequest = CreateWebRequest(url, requestTimeoutLeft);
                            InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
                            watch.Stop();
                            break;
                        }
                        catch (System.Net.WebException)
                        {
                            _wsdlHandlerConfiguration.Logger.Log(LogLevel.Info, String.Format("Could not connect to {0}", url));
                            watch.Stop();
                            var elapsedMs = watch.ElapsedMilliseconds;
                            requestTimeoutLeft = requestTimeoutLeft - (Int32)Math.Ceiling((double)elapsedMs / 1000);
                            continue;
                        }
                    }
                }
                else
                {
                    soapEnvelopeXml = CreateSoapEnvelope(_wsdlHandlerConfiguration.ServiceUrl, ServiceName, InputParameterName, InputType, data);
                    webRequest      = CreateWebRequest(_wsdlHandlerConfiguration.ServiceUrl, _wsdlHandlerConfiguration.RequestTimeout);
                    InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
                }

                _wsdlHandlerConfiguration.Logger.LogRequest(LogLevel.Info, soapEnvelopeXml);

                RootElement rootElement = new RootElement();

                // get the response from the completed web request.
                using (WebResponse webResponse = webRequest.GetResponse())
                {
                    string soapResponse;
                    var    responseStream = webResponse.GetResponseStream();
                    if (responseStream == null)
                    {
                        return(null);
                    }

                    using (StreamReader rd = new StreamReader(responseStream))
                    {
                        soapResponse = rd.ReadToEnd();
                    }

                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(soapResponse);

                    _wsdlHandlerConfiguration.Logger.LogResponse(LogLevel.Info, xmlDoc);

                    // Get elements
                    XmlNodeList outputElement = xmlDoc.GetElementsByTagName(OutputParameterName);
                    if (outputElement.Count != 1)
                    {
                        return(null);
                    }

                    foreach (XmlNode childNode in outputElement[0].ChildNodes)
                    {
                        rootElement.Add(childNode.Name, Deserialize(childNode));
                    }
                }
                return(rootElement);
            }
Exemplo n.º 4
0
 private Boolean Validate(BaseElement data, out List <String> errorMessage)
 {
     return(Validate(data, Input, String.Empty, out errorMessage));
 }