Esempio n. 1
0
        public model.WebSvcMessageResponse Work()
        {
            HttpWebResponse _webResponse  = null;
            StreamWriter    _streamWriter = null;
            StreamReader    _streamReader = null;

            try {
                HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.CreateDefault(new Uri(_webSvcMethod.ServiceURI));

                webRequest.Method      = "Post";
                webRequest.ContentType = _webSvcMethod.Request.Headers[model.WebSvcMessage.HEADER_NAME_CONTENT_TYPE];
                webRequest.Headers[model.WebSvcMessageRequest.HEADER_NAME_SOAP_ACTION] = _webSvcMethod.Request.Headers[model.WebSvcMessageRequest.HEADER_NAME_SOAP_ACTION];
                webRequest.ServicePoint.Expect100Continue = false;
                webRequest.Proxy = base.WebProxy;

                webRequest.Timeout = base.TimeoutInSec * 1000;

                _streamWriter = new StreamWriter(webRequest.GetRequestStream());

                _streamWriter.Write(_webSvcMethod.Request.Body);
                _streamWriter.Flush();
                _streamWriter.Close();

                _webResponse = (HttpWebResponse)webRequest.GetResponse();

                base.Log.Info("Work Response Process " + base.Name);

                _streamReader = new StreamReader(_webResponse.GetResponseStream());

                string body   = _streamReader.ReadToEnd();
                string status = ((int)_webResponse.StatusCode).ToString() + " " + _webResponse.StatusCode.ToString();
                Dictionary <string, string> headers = new Dictionary <string, string>();
                foreach (string key in _webResponse.Headers.Keys)
                {
                    headers[key] = _webResponse.Headers[key];
                }

                var response = new model.WebSvcMessageResponse();
                response.Body    = body;
                response.Status  = status;
                response.Headers = headers;

                return(response);
            }
            finally
            {
                if (_webResponse != null)
                {
                    _webResponse.Close();
                }
                if (_streamWriter != null)
                {
                    _streamWriter.Close();
                }
                if (_streamReader != null)
                {
                    _streamReader.Close();
                }
            }
        }
Esempio n. 2
0
 public CallAsyncResult(string body, string status, Dictionary<string, string> headers)
 {
     Response = new model.WebSvcMessageResponse();
     Response.Body = body;
     Response.Status = status;
     Response.Headers = headers;
 }
Esempio n. 3
0
 public CallAsyncResult(string body, string status, Dictionary <string, string> headers)
 {
     Response         = new model.WebSvcMessageResponse();
     Response.Body    = body;
     Response.Status  = status;
     Response.Headers = headers;
 }
Esempio n. 4
0
        public model.WebSvcMessageResponse Work()
        {
            HttpWebResponse _webResponse = null;
            StreamWriter _streamWriter = null;
            StreamReader _streamReader = null;

            try {

                HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.CreateDefault(new Uri(_webSvcMethod.ServiceURI));

                webRequest.Method = "Post";
                webRequest.ContentType = _webSvcMethod.Request.Headers[model.WebSvcMessage.HEADER_NAME_CONTENT_TYPE];
                webRequest.Headers[model.WebSvcMessageRequest.HEADER_NAME_SOAP_ACTION] = _webSvcMethod.Request.Headers[model.WebSvcMessageRequest.HEADER_NAME_SOAP_ACTION];
                webRequest.ServicePoint.Expect100Continue = false;
                webRequest.Proxy = base.WebProxy;

                webRequest.Timeout = base.TimeoutInSec * 1000;

                _streamWriter = new StreamWriter(webRequest.GetRequestStream());

                _streamWriter.Write(_webSvcMethod.Request.Body);
                _streamWriter.Flush();
                _streamWriter.Close();

                _webResponse = (HttpWebResponse)webRequest.GetResponse();

                base.Log.Info("Work Response Process " + base.Name);

                _streamReader = new StreamReader(_webResponse.GetResponseStream());

                string body = _streamReader.ReadToEnd();
                string status = ((int)_webResponse.StatusCode).ToString() + " " + _webResponse.StatusCode.ToString();
                Dictionary<string, string> headers = new Dictionary<string, string>();
                foreach (string key in _webResponse.Headers.Keys) {
                    headers[key] = _webResponse.Headers[key];
                }

                var response = new model.WebSvcMessageResponse();
                response.Body = body;
                response.Status = status;
                response.Headers = headers;

                return response;

            }
            finally
            {
                if (_webResponse != null) {
                    _webResponse.Close();
                }
                if (_streamWriter != null) {
                    _streamWriter.Close();
                }
                if (_streamReader != null) {
                    _streamReader.Close();
                }
            }
        }
Esempio n. 5
0
        public model.WebSvcMethodContainer GenerateSampleData()
        {
            Dictionary <string, model.WebSvcMethod> results = new Dictionary <string, model.WebSvcMethod>();

            List <string> methodList = GetMethodList();

            foreach (string method in methodList)
            {
                ServiceDescriptionCollection descCol = new ServiceDescriptionCollection();
                foreach (ServiceDescription sd in _descriptions)
                {
                    descCol.Add(sd);
                }

                XmlSchemas schemaCol;
                if (_schemas.Count > 0)
                {
                    schemaCol = new XmlSchemas();
                    foreach (XmlSchema sc in _schemas)
                    {
                        schemaCol.Add(sc);
                    }
                }
                else
                {
                    schemaCol = descCol[0].Types.Schemas;
                }

                string req;
                string resp;

                SampleGeneratorWebSvc sg = new SampleGeneratorWebSvc(descCol, schemaCol);
                sg.GenerateMessages(method, null, "Soap", out req, out resp);

                int    indexOfReqMsg = req.IndexOf(@"<soap:Envelope");
                string reqHeaderMsg  = req.Substring(0, indexOfReqMsg);
                string sampleReqMsg  = req.Substring(indexOfReqMsg);

                int    indexOfRespMsg = resp.IndexOf(@"<soap:Envelope");
                string respHeaderMsg  = resp.Substring(0, indexOfRespMsg);
                string sampleRespMsg  = resp.Substring(indexOfRespMsg);

                string[] reqHeaderLines = reqHeaderMsg.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                string   soapAction     = GetHeader(reqHeaderLines, "SOAPAction:");
                string   reqContentType = GetHeader(reqHeaderLines, "Content-Type:");

                string[] respHeaderLines = respHeaderMsg.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                string   respContentType = GetHeader(respHeaderLines, "Content-Type:");

                model.WebSvcMessageRequest messageRequest = new model.WebSvcMessageRequest();
                messageRequest.Body = sampleReqMsg;
                messageRequest.Headers[model.WebSvcMessage.HEADER_NAME_CONTENT_TYPE]       = reqContentType;
                messageRequest.Headers[model.WebSvcMessageRequest.HEADER_NAME_SOAP_ACTION] = soapAction;

                model.WebSvcMessageResponse messageResponse = new model.WebSvcMessageResponse();
                messageResponse.Body = sampleRespMsg;
                messageResponse.Headers[model.WebSvcMessage.HEADER_NAME_CONTENT_TYPE] = respContentType;

                model.WebSvcMethod webMethod = new model.WebSvcMethod(method, _serviceURI)
                {
                    Request  = messageRequest,
                    Response = messageResponse
                };


                results[method] = webMethod;
            }

            return(new model.WebSvcMethodContainer(results));
        }
Esempio n. 6
0
        public model.WebSvcMethodContainer GenerateSampleData()
        {
            Dictionary<string, model.WebSvcMethod> results = new Dictionary<string, model.WebSvcMethod>();

            List<string> methodList = GetMethodList();

            foreach (string method in methodList) {
                ServiceDescriptionCollection descCol = new ServiceDescriptionCollection();
                foreach (ServiceDescription sd in _descriptions) {
                    descCol.Add(sd);
                }

                XmlSchemas schemaCol;
                if (_schemas.Count > 0) {
                    schemaCol = new XmlSchemas();
                    foreach (XmlSchema sc in _schemas) {
                        schemaCol.Add(sc);
                    }
                }
                else {
                    schemaCol = descCol[0].Types.Schemas;
                }

                string req;
                string resp;

                SampleGeneratorWebSvc sg = new SampleGeneratorWebSvc(descCol, schemaCol);
                sg.GenerateMessages(method, null, "Soap", out req, out resp);

                int indexOfReqMsg = req.IndexOf(@"<soap:Envelope");
                string reqHeaderMsg = req.Substring(0, indexOfReqMsg);
                string sampleReqMsg = req.Substring(indexOfReqMsg);

                int indexOfRespMsg = resp.IndexOf(@"<soap:Envelope");
                string respHeaderMsg = resp.Substring(0, indexOfRespMsg);
                string sampleRespMsg = resp.Substring(indexOfRespMsg);

                string[] reqHeaderLines = reqHeaderMsg.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                string soapAction = GetHeader(reqHeaderLines, "SOAPAction:");
                string reqContentType = GetHeader(reqHeaderLines, "Content-Type:");

                string[] respHeaderLines = respHeaderMsg.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                string respContentType = GetHeader(respHeaderLines, "Content-Type:");

                model.WebSvcMessageRequest messageRequest = new model.WebSvcMessageRequest();
                messageRequest.Body = sampleReqMsg;
                messageRequest.Headers[model.WebSvcMessage.HEADER_NAME_CONTENT_TYPE] = reqContentType;
                messageRequest.Headers[model.WebSvcMessageRequest.HEADER_NAME_SOAP_ACTION] = soapAction;

                model.WebSvcMessageResponse messageResponse = new model.WebSvcMessageResponse();
                messageResponse.Body = sampleRespMsg;
                messageResponse.Headers[model.WebSvcMessage.HEADER_NAME_CONTENT_TYPE] = respContentType;

                model.WebSvcMethod webMethod = new model.WebSvcMethod(method, _serviceURI) {
                    Request = messageRequest,
                    Response = messageResponse
                };

                results[method] = webMethod;
            }

            return new model.WebSvcMethodContainer(results);
        }