1 // created on 07/04/2003 at 17:16
\r
3 // System.Runtime.Serialization.Formatters.Soap.SoapFormatter
\r
6 // Jean-Marc Andre (jean-marc.andre@polymtl.ca)
\r
10 // Permission is hereby granted, free of charge, to any person obtaining
\r
11 // a copy of this software and associated documentation files (the
\r
12 // "Software"), to deal in the Software without restriction, including
\r
13 // without limitation the rights to use, copy, modify, merge, publish,
\r
14 // distribute, sublicense, and/or sell copies of the Software, and to
\r
15 // permit persons to whom the Software is furnished to do so, subject to
\r
16 // the following conditions:
\r
18 // The above copyright notice and this permission notice shall be
\r
19 // included in all copies or substantial portions of the Software.
\r
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
32 using System.Reflection;
\r
33 using System.Runtime.InteropServices;
\r
34 using System.Runtime.Remoting;
\r
35 using System.Runtime.Serialization;
\r
36 using System.Runtime.Remoting.Messaging;
\r
37 using System.Xml.Serialization;
\r
38 using System.Threading;
\r
39 using System.Globalization;
\r
42 namespace System.Runtime.Serialization.Formatters.Soap {
\r
43 enum RemMessageType {
\r
44 MethodCall, MethodResponse, ServerFault, NotRecognize
\r
47 public sealed class SoapFormatter: IRemotingFormatter, IFormatter {
\r
48 private SerializationBinder _binder;
\r
49 private StreamingContext _context;
\r
50 private ISurrogateSelector _selector;
\r
51 private FormatterAssemblyStyle _assemblyFormat = FormatterAssemblyStyle.Full;
\r
52 private FormatterTypeStyle _typeFormat = FormatterTypeStyle.TypesWhenNeeded;
\r
53 private ISoapMessage _topObject = null;
\r
55 TypeFilterLevel _filterLevel = TypeFilterLevel.Low;
\r
57 public SoapFormatter() {
\r
59 _context = new StreamingContext(StreamingContextStates.All);
\r
62 public SoapFormatter(ISurrogateSelector selector, StreamingContext context) {
\r
63 _selector = selector;
\r
67 public object Deserialize(Stream serializationStream) {
\r
68 return Deserialize(serializationStream, null);
\r
71 public object Deserialize(Stream serializationStream, HeaderHandler handler) {
\r
72 object objReturn = null;
\r
73 SoapReader soapReader = new SoapReader(_binder, _selector, _context);
\r
74 CultureInfo savedCi = CultureInfo.CurrentCulture;
\r
76 Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
\r
77 objReturn = soapReader.Deserialize(serializationStream, _topObject);
\r
80 Thread.CurrentThread.CurrentCulture = savedCi;
\r
87 public void Serialize(Stream serializationStream, object graph) {
\r
88 Serialize(serializationStream, graph, null);
\r
91 public void Serialize(Stream serializationStream, object graph, Header[] headers) {
\r
92 if(serializationStream == null)
\r
93 throw new ArgumentNullException("serializationStream");
\r
94 if(!serializationStream.CanWrite)
\r
95 throw new SerializationException("Can't write in the serialization stream");
\r
97 throw new ArgumentNullException("graph");
\r
98 SoapWriter soapWriter = new SoapWriter(serializationStream, _selector, _context, _topObject);
\r
99 CultureInfo savedCi = CultureInfo.CurrentCulture;
\r
101 Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
\r
102 soapWriter.Serialize (graph, headers, _typeFormat, _assemblyFormat);
\r
105 Thread.CurrentThread.CurrentCulture = savedCi;
\r
110 public ISurrogateSelector SurrogateSelector {
\r
120 public SerializationBinder Binder {
\r
129 public StreamingContext Context {
\r
138 public ISoapMessage TopObject {
\r
143 _topObject = value;
\r
147 [MonoTODO ("Interpret this")]
\r
148 public TypeFilterLevel FilterLevel {
\r
150 return _filterLevel;
\r
153 _filterLevel = value;
\r
157 public FormatterAssemblyStyle AssemblyFormat
\r
160 return _assemblyFormat;
\r
163 _assemblyFormat = value;
\r
167 public FormatterTypeStyle TypeFormat
\r
171 return _typeFormat;
\r
175 _typeFormat = value;
\r