コード例 #1
0
ファイル: ServiceI.asmx.cs プロジェクト: staherianYMCA/test
        public TestClassSimple MethodWithoutParameters()
        {
            TestClassSimple
                InputTestClassSimple  = new TestClassSimple(),
                OutputTestClassSimple = new TestClassSimple();

            try
            {
                string
                    param = Context.Request.QueryString["param"];

                StreamReader
                    StreamReader = new StreamReader(Context.Request.InputStream, Encoding.UTF8);

                XmlSerializer
                    XmlSerializer = new XmlSerializer(InputTestClassSimple.GetType());

                InputTestClassSimple = (TestClassSimple)XmlSerializer.Deserialize(StreamReader);

                int
                    delta = 100;

                OutputTestClassSimple.FInt      = InputTestClassSimple.FInt * delta;
                OutputTestClassSimple.FDecimal  = InputTestClassSimple.FDecimal * delta;
                OutputTestClassSimple.FDateTime = InputTestClassSimple.FDateTime.AddYears(delta);
                OutputTestClassSimple.FString   = InputTestClassSimple.FString + " " + InputTestClassSimple.FString + (!string.IsNullOrEmpty(param) ? " \"" + param + "\"" : string.Empty);
            }
            catch (Exception eException)
            {
                OutputTestClassSimple.FString = eException.GetType().FullName + Environment.NewLine + "Message: " + eException.Message + Environment.NewLine + "StackTrace:" + Environment.NewLine + eException.StackTrace;
            }

            return(OutputTestClassSimple);
        }
コード例 #2
0
        static void TestMethodWithoutParametersLow()
        {
            WebRequest
                request = WebRequest.Create(ConfigurationManager.AppSettings["URL"] + "/MethodWithoutParameters?param=ParamValue");

            request.ContentType = "text/xml";
            request.Method      = "POST";

            XmlDocument
                doc = CreateXmlDocument();

            byte[]
            bytes = System.Text.Encoding.UTF8.GetBytes(doc.InnerXml);

            request.ContentLength = bytes.Length;

            Stream
                os = request.GetRequestStream();

            os.Write(bytes, 0, bytes.Length);
            os.Close();

            WebResponse
                response = request.GetResponse();

            StreamReader
                sr = new StreamReader(response.GetResponseStream());

                                #if !USE_SERIALIZE
            string
                result = sr.ReadToEnd().Trim();

            doc = new XmlDocument();
            doc.LoadXml(result);

            XmlNodeList
                nodes = doc.GetElementsByTagName("TestClassSimple");

            for (int i = 0; i < nodes.Count; ++i)
            {
                for (int j = 0; j < nodes[i].ChildNodes.Count; ++j)
                {
                    Console.WriteLine("\"{0}\"=\"{1}\"", nodes[i].ChildNodes[j].Name, nodes[i].ChildNodes[j].FirstChild.Value);
                }
            }
                                #else
            TestClassSimple
                TestClassSimple = new TestClassSimple();

            XmlSerializer
                XmlSerializer = new XmlSerializer(TestClassSimple.GetType());

            TestClassSimple.FInt      = 999;
            TestClassSimple.FDecimal  = 999.99m;
            TestClassSimple.FDateTime = DateTime.Now;
            TestClassSimple.FString   = "Test Тест";

            string
                FileName = Path.GetFullPath(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + "TestClassSimple.xml");

            if (File.Exists(FileName))
            {
                File.Delete(FileName);
            }

            StreamWriter
                sw = new StreamWriter(FileName, false, Encoding.UTF8);

            XmlSerializer.Serialize(sw, TestClassSimple);
            sw.Close();

            FileName = Path.GetFullPath(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + "TestClassSimpleFromService.xml");

            StreamReader
                StreamReader = new StreamReader(FileName, Encoding.UTF8);

            TestClassSimple = new TestClassSimple();
            TestClassSimple = (TestClassSimple)XmlSerializer.Deserialize(StreamReader);

            TestClassSimple = new TestClassSimple();
            TestClassSimple = (TestClassSimple)XmlSerializer.Deserialize(sr);
                                #endif
        }