home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / dotNETSDK / SETUP.EXE / netfxsd1.cab / FL_SoapMessageClient_cs________.3643236F_FC70_11D3_A536_0090278A1BB8 < prev    next >
Encoding:
Text File  |  2001-06-25  |  3.9 KB  |  109 lines

  1. /*=====================================================================
  2.  
  3.   File:      SoapMessageClient.cs
  4.  
  5. ---------------------------------------------------------------------
  6. This file is part of the Microsoft .NET Framework SDK Code Samples.
  7.  
  8.   Copyright (C) Microsoft Corporation.  All rights reserved.
  9.  
  10. This source code is intended only as a supplement to Microsoft
  11. Development Tools and/or on-line documentation.  See these other
  12. materials for detailed information regarding Microsoft code samples.
  13.  
  14. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  15. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  16. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  17. PARTICULAR PURPOSE.
  18. =====================================================================*/
  19.  
  20. using System;
  21. using System.IO;
  22. using System.Runtime.Remoting;
  23. using System.Runtime.Remoting.Messaging;
  24. using System.Runtime.Serialization;
  25. using System.Runtime.Serialization.Formatters;
  26. using System.Runtime.Serialization.Formatters.Soap;
  27.  
  28. namespace Foo
  29. {
  30.     public class SoapMessageClient
  31.     {
  32.         public static void Main(string[] args)
  33.         {
  34.             SOAPMessageToStream();
  35.             StreamToSOAPMessage();
  36.         }
  37.  
  38.         public static void SOAPMessageToStream()
  39.         {
  40.             Console.WriteLine("SOAPMessageToStream\n");
  41.             SoapMessage soapMessage = new SoapMessage();
  42.             
  43.             soapMessage.XmlNameSpace = "Some-URI";
  44.             soapMessage.MethodName = "GetLastTradePrice";
  45.             soapMessage.ParamNames = new String[] {"symbol"};
  46.             soapMessage.ParamValues = new Object[] {"DIS"};
  47.  
  48.             soapMessage.Headers = new Header[1];
  49.             soapMessage.Headers[0] = new Header("Transaction", "tip://www.microsoft.com/?oletx-0000000-0000-0000-0000-000000000001");
  50.  
  51.             SoapFormatter formatter = new SoapFormatter();
  52.             formatter.TopObject = soapMessage;
  53.  
  54.             MemoryStream stream = new MemoryStream();
  55.             StreamWriter tw = new StreamWriter(stream);
  56.             formatter.Serialize(stream, soapMessage);
  57.             tw.Flush();
  58.  
  59.             stream.Position = 0;
  60.             StreamReader sr = new StreamReader(stream);
  61.             String line;
  62.             while ((line = sr.ReadLine()) != null)
  63.             {
  64.                 Console.WriteLine(line);
  65.             }
  66.  
  67.             Console.WriteLine("\n");
  68.         }
  69.  
  70.         public static void StreamToSOAPMessage()
  71.         {
  72.             Console.WriteLine("SOAPStreamToSOAPMessage\n");
  73.  
  74.             SoapFormatter formatter = new SoapFormatter();
  75.             MemoryStream stream = new MemoryStream();
  76.  
  77.             StreamWriter tw = new StreamWriter(stream);
  78.             tw.Write("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"");
  79.             tw.Write(" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">");
  80.             tw.Write("<SOAP-ENV:Body>");
  81.             tw.Write("<m:GetLastTradePrice xmlns:m=\"Some-URI\">");
  82.             tw.Write("<symbol>DIS</symbol>");
  83.             tw.Write("</m:GetLastTradePrice>");
  84.             tw.Write("</SOAP-ENV:Body>");
  85.             tw.Write("</SOAP-ENV:Envelope>");
  86.             tw.Flush();
  87.             stream.Position = 0;
  88.  
  89.             SoapMessage soapMessage = new SoapMessage();
  90.             formatter.TopObject = soapMessage;
  91.             soapMessage = (SoapMessage)formatter.Deserialize(stream);
  92.  
  93.             String xmlNameSpace = soapMessage.XmlNameSpace;
  94.             Console.WriteLine("XmlNameSpace "+ xmlNameSpace);
  95.             
  96.             String methodName = soapMessage.MethodName;
  97.             Console.WriteLine("methodName "+methodName);
  98.  
  99.             Object[] parameters = soapMessage.ParamValues;
  100.  
  101.             for (int i=0; i<parameters.Length; i++)
  102.                 Console.WriteLine("param "+i+" "+parameters[i]);
  103.  
  104.             Console.WriteLine("\n");
  105.         }
  106.     }
  107. }
  108.  
  109.