示例#1
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));
        }
示例#2
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);
        }