2 // HttpSimpleMethodStubInfo.cs: Information about a method and its mapping to a SOAP web service.
5 // Lluis Sanchez Gual (lluis@ximian.com)
7 // (C) 2003 Ximian, Inc.
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System
.Reflection
;
32 using System
.Collections
;
34 using System
.Xml
.Serialization
;
35 using System
.Web
.Services
;
36 using System
.Web
.Services
.Description
;
38 namespace System
.Web
.Services
.Protocols
48 internal abstract class HttpSimpleMethodStubInfo
: MethodStubInfo
50 public MimeFormatterInfo ParameterWriterType
;
51 public MimeFormatterInfo ParameterReaderType
;
52 public MimeFormatterInfo ReturnReaderType
;
53 public MimeFormatterInfo ReturnWriterType
;
55 public MimeFormatterInfo
GetFormatterInfo (FormatterKind kind
)
59 case FormatterKind
.ParameterWriter
: return ParameterWriterType
;
60 case FormatterKind
.ParameterReader
: return ParameterReaderType
;
61 case FormatterKind
.ReturnReader
: return ReturnReaderType
;
62 case FormatterKind
.ReturnWriter
: return ReturnWriterType
;
67 public HttpSimpleMethodStubInfo (TypeStubInfo parent
, LogicalMethodInfo source
): base (parent
, source
)
69 object[] atts
= source
.CustomAttributeProvider
.GetCustomAttributes (typeof(HttpMethodAttribute
), true);
72 HttpMethodAttribute at
= (HttpMethodAttribute
) atts
[0];
73 ParameterWriterType
= new MimeFormatterInfo (at
.ParameterFormatter
);
74 ReturnReaderType
= new MimeFormatterInfo (at
.ReturnFormatter
);
77 if (ReturnReaderType
== null) {
78 if (source
.IsVoid
) ReturnReaderType
= new MimeFormatterInfo (typeof(NopReturnReader
));
79 else ReturnReaderType
= new MimeFormatterInfo (typeof(XmlReturnReader
));
84 internal class MimeFormatterInfo
86 public MimeFormatterInfo (Type type
) {
90 public MimeFormatter
Create () {
91 return MimeFormatter
.CreateInstance (Type
, Initializer
);
95 public object Initializer
;
98 internal abstract class HttpSimpleTypeStubInfo
: TypeStubInfo
100 public HttpSimpleTypeStubInfo (LogicalTypeInfo logicalTypeInfo
): base (logicalTypeInfo
)
104 protected override void BuildTypeMethods ()
106 base.BuildTypeMethods ();
108 BuildInitializers (FormatterKind
.ParameterWriter
);
109 BuildInitializers (FormatterKind
.ParameterReader
);
110 BuildInitializers (FormatterKind
.ReturnReader
);
111 BuildInitializers (FormatterKind
.ReturnWriter
);
114 void BuildInitializers (FormatterKind formatter
)
116 Hashtable types
= new Hashtable ();
118 foreach (HttpSimpleMethodStubInfo met
in Methods
)
119 AddType (types
, met
.GetFormatterInfo (formatter
).Type
, met
);
121 foreach (DictionaryEntry ent
in types
)
123 Type t
= (Type
)ent
.Key
;
124 ArrayList list
= (ArrayList
)ent
.Value
;
125 LogicalMethodInfo
[] mets
= new LogicalMethodInfo
[list
.Count
];
126 for (int n
=0; n
<list
.Count
; n
++)
127 mets
[n
] = ((MethodStubInfo
)list
[n
]).MethodInfo
;
129 object[] inits
= MimeFormatter
.GetInitializers (t
, mets
);
131 for (int n
=0; n
<list
.Count
; n
++)
132 ((HttpSimpleMethodStubInfo
)list
[n
]).GetFormatterInfo (formatter
).Initializer
= inits
[n
];
136 void AddType (Hashtable types
, Type type
, HttpSimpleMethodStubInfo method
)
138 ArrayList list
= (ArrayList
) types
[type
];
141 list
= new ArrayList ();