5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2006 Novell, 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.
30 using System.Reflection;
31 using System.Web.Services;
32 using System.Web.Services.Description;
34 namespace System.Web.Services.Protocols
37 // This class has information abou a web service. Through providess
38 // access to the TypeStubInfo instances for each protocol.
45 class ServerType // It was LogicalTypeInfo until Mono 1.2.
47 LogicalMethodInfo[] logicalMethods;
49 internal string WebServiceName;
50 internal string WebServiceNamespace;
51 internal string WebServiceAbstractNamespace;
52 internal string Description;
56 TypeStubInfo soapProtocol;
57 TypeStubInfo httpGetProtocol;
58 TypeStubInfo httpPostProtocol;
60 public ServerType (Type t)
64 object [] o = Type.GetCustomAttributes (typeof (WebServiceAttribute), false);
66 WebServiceAttribute a = (WebServiceAttribute) o [0];
67 WebServiceName = (a.Name != string.Empty) ? a.Name : Type.Name;
68 WebServiceNamespace = (a.Namespace != string.Empty) ? a.Namespace : WebServiceAttribute.DefaultNamespace;
69 Description = a.Description;
71 WebServiceName = Type.Name;
72 WebServiceNamespace = WebServiceAttribute.DefaultNamespace;
75 // Determine the namespaces for literal and encoded schema types
79 o = t.GetCustomAttributes (typeof(SoapDocumentServiceAttribute), true);
81 SoapDocumentServiceAttribute at = (SoapDocumentServiceAttribute) o[0];
82 useEncoded = (at.Use == SoapBindingUse.Encoded);
84 else if (t.GetCustomAttributes (typeof(SoapRpcServiceAttribute), true).Length > 0)
87 string sep = WebServiceNamespace.EndsWith ("/") ? "" : "/";
89 WebServiceAbstractNamespace = WebServiceNamespace + sep + "AbstractTypes";
91 MethodInfo [] type_methods = Type.GetMethods (BindingFlags.Instance | BindingFlags.Public);
92 logicalMethods = LogicalMethodInfo.Create (type_methods, LogicalMethodTypes.Sync);
95 internal bool UseEncoded {
96 get { return useEncoded; }
99 internal LogicalMethodInfo[] LogicalMethods
101 get { return logicalMethods; }
104 internal TypeStubInfo GetTypeStub (string protocolName)
108 switch (protocolName)
111 if (soapProtocol == null) soapProtocol = CreateTypeStubInfo (typeof(SoapTypeStubInfo));
114 if (httpGetProtocol == null) httpGetProtocol = CreateTypeStubInfo (typeof(HttpGetTypeStubInfo));
115 return httpGetProtocol;
117 if (httpPostProtocol == null) httpPostProtocol = CreateTypeStubInfo (typeof(HttpPostTypeStubInfo));
118 return httpPostProtocol;
121 throw new InvalidOperationException ("Protocol " + protocolName + " not supported");
124 TypeStubInfo CreateTypeStubInfo (Type type)
126 TypeStubInfo tsi = (TypeStubInfo) Activator.CreateInstance (type, new object[] {this});
131 internal string GetWebServiceLiteralNamespace (string baseNamespace)
134 string sep = baseNamespace.EndsWith ("/") ? "" : "/";
135 return baseNamespace + sep + "literalTypes";
138 return baseNamespace;
141 internal string GetWebServiceEncodedNamespace (string baseNamespace)
144 return baseNamespace;
146 string sep = baseNamespace.EndsWith ("/") ? "" : "/";
147 return baseNamespace + sep + "encodedTypes";
151 internal string GetWebServiceNamespace (string baseNamespace, SoapBindingUse use)
153 if (use == SoapBindingUse.Literal) return GetWebServiceLiteralNamespace (baseNamespace);
154 else return GetWebServiceEncodedNamespace (baseNamespace);