Esempio n. 1
0
        private void CallWebService()
        {
            try
            {
                //general variables
                string[] lineKeys;
                //Create WS objets
                CAdxWebServiceXmlCC.CAdxCallContext cAdxCallContext = new CAdxCallContext();
                CAdxWebServiceXmlCC.CAdxResultXml cAdxResultXml = new CAdxResultXml();
                CAdxParamKeyValue[] objectKeys;
                // Grab settings
                string objectXml = txtParam.Text.ToString().Trim();
                string blockKey = txtBlockKey.Text.Trim();
                int listSize = String.IsNullOrEmpty(txtListSize.Text) ? 0 : int.Parse(txtListSize.Text);
                string actionCode = txtActionCode.Text.Trim();
                //Records application start time
                DateTime dt = DateTime.Now;

                // Clear results, messages, traces, etc and set url
                ClearOutputs(true);

                // Set URL, get call context and authenticate
                _x3Ws.Url = txtWebsite.Text.Trim() + "/soap-generic/syracuse/collaboration/syracuse/CAdxWebServiceXmlCC";
                cAdxCallContext = GetCallContext();

                //Trust all certificates
                System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

                // Trust our stagging server
                // System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, cert, chain, errors) => cert.Subject.Contains("sagex3.com"));

                //System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, cert, chain, errors) => cert.Subject.Contains("sageerpx3online.com"));

                // If you are using a third party certificate, add code here to validate it.

                // V9 requires prior authorization, establish the authorization method
                if (rdbBasic.Checked == true)
                {
                    //use basic authentication
                    _x3Ws.BasicAuth = true;
                    _x3Ws.Credentials = new System.Net.NetworkCredential(txtCodeUser.Text.ToString().Trim(), txtPassword.Text.ToString().Trim());
                }else
                {
                    //use Sage-ID OAuth authentication
                    _x3Ws.BasicAuth = false;
                    _x3Ws.AccessToken = GetAccessToken(txtRetrievalUrl.Text.Trim());
                }
                _x3Ws.PreAuthenticate = true;

                // Call appropiate WS method
                string wsName = cmbWebService.Text.ToUpper().Trim();
                string methodName = lstMethods.Text.ToUpper().Trim();
                switch (methodName)
                {
                    case "GETDESCRIPTION":
                        cAdxResultXml = _x3Ws.getDescription(cAdxCallContext, wsName);
                        break;
                    case "GETDATAXMLSCHEMA":
                        cAdxResultXml = _x3Ws.getDataXmlSchema(cAdxCallContext, wsName);
                        break;
                    case "RUN":
                        cAdxResultXml = _x3Ws.run(cAdxCallContext,wsName, objectXml);
                        break;
                    case "QUERY":
                        objectKeys = GetCriteria(cAdxCallContext);
                        cAdxResultXml = _x3Ws.query(cAdxCallContext, wsName, objectKeys, listSize);
                        break;
                    case "READ":
                        objectKeys = GetCriteria(cAdxCallContext);
                        cAdxResultXml = _x3Ws.read(cAdxCallContext,wsName, objectKeys);
                        break;
                    case "MODIFY":
                        objectKeys = GetCriteria(cAdxCallContext);
                        cAdxResultXml = _x3Ws.modify(cAdxCallContext,wsName, objectKeys, objectXml);
                        break;
                    case "SAVE":
                        cAdxResultXml = _x3Ws.save(cAdxCallContext, wsName, objectXml);
                        break;
                    case "DELETE":
                        objectKeys = GetCriteria(cAdxCallContext);
                        cAdxResultXml = _x3Ws.delete(cAdxCallContext,wsName, objectKeys);
                        break;
                    case "DELETELINES":
                        objectKeys = GetCriteria(cAdxCallContext);
                        lineKeys = GetDeleteLineKeys();
                        cAdxResultXml = _x3Ws.deleteLines(cAdxCallContext, wsName, objectKeys, blockKey, lineKeys);
                        break;
                    case "ACTIONOBJECT":
                        //**********************************************************************************************
                        cAdxResultXml = _x3Ws.actionObject(cAdxCallContext, wsName, actionCode, objectXml);
                        break;
                    default:
                        MessageBox.Show("Select a supported methods");
                        break;
                }

                ShowResults(cAdxResultXml, (DateTime.Now - dt).TotalMilliseconds.ToString());
            }
            catch (Exception ex)
            {
                ErrorHandler(ex.Message);
            }
        }