// This class represents all the information we extract from a MethodInfo
// in the SoapHttpClientProtocol derivative stub class
//
- internal class MethodStubInfo {
- internal LogicalMethodInfo MethodInfo;
-
- // The name used bythe stub class to reference this method.
- internal string Name;
-
+ internal class SoapMethodStubInfo : MethodStubInfo
+ {
internal string Action;
internal string Binding;
internal string ResponseName;
internal string ResponseNamespace;
- internal WebMethodAttribute MethodAttribute;
internal bool OneWay;
internal SoapParameterStyle ParameterStyle;
internal SoapBindingStyle SoapBindingStyle;
internal SoapBindingUse Use;
- internal bool BufferResponse;
- internal int CacheDuration;
- internal string Description;
- internal bool EnableSession;
-
internal XmlSerializer RequestSerializer;
internal XmlSerializer ResponseSerializer;
//
// Constructor
//
- MethodStubInfo (TypeStubInfo parent, LogicalMethodInfo source, object kind, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter)
+ public SoapMethodStubInfo (TypeStubInfo typeStub, LogicalMethodInfo source, object kind, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter)
+ : base (typeStub, source)
{
- MethodInfo = source;
-
+ SoapTypeStubInfo parent = (SoapTypeStubInfo) typeStub;
XmlElementAttribute optional_ns = null;
if (kind == null) {
throw new Exception ("OneWay methods should not have out/ref parameters");
}
- object [] o = source.GetCustomAttributes (typeof (WebMethodAttribute));
- if (o.Length == 1){
- MethodAttribute = (WebMethodAttribute) o [0];
- BufferResponse = MethodAttribute.BufferResponse;
- CacheDuration = MethodAttribute.CacheDuration;
- Description = MethodAttribute.Description;
- EnableSession = MethodAttribute.EnableSession;
- Name = MethodAttribute.MessageName;
-
- if (Name == "")
- Name = source.Name;
- } else
- Name = source.Name;
-
if (RequestNamespace == "") RequestNamespace = parent.WebServiceNamespace;
if (ResponseNamespace == "") ResponseNamespace = parent.WebServiceNamespace;
if (RequestName == "") RequestName = Name;
if (ResponseName == "") ResponseName = Name + "Response";
- if (Binding == null) Binding = parent.DefaultBinding;
+ if (Binding == null || Binding == "") Binding = parent.DefaultBinding;
else if (parent.GetBinding (Binding) == null) throw new InvalidOperationException ("Type '" + parent.Type + "' is missing WebServiceBinding attribute that defines a binding named '" + Binding + "'");
if (Action == null || Action == "")
RequestSerializer = s [0];
ResponseSerializer = s [1];
- o = source.GetCustomAttributes (typeof (SoapHeaderAttribute));
+ object[] o = source.GetCustomAttributes (typeof (SoapHeaderAttribute));
Headers = new HeaderInfo[o.Length];
for (int i = 0; i < o.Length; i++) {
SoapHeaderAttribute att = (SoapHeaderAttribute) o[i];
SoapExtensions = SoapExtension.GetMethodExtensions (source);
}
- static internal MethodStubInfo Create (TypeStubInfo parent, LogicalMethodInfo lmi, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter)
- {
- object [] o = lmi.GetCustomAttributes (typeof (SoapDocumentMethodAttribute));
- if (o.Length == 0) o = lmi.GetCustomAttributes (typeof (SoapRpcMethodAttribute));
-
- if (o.Length == 0)
- {
- if (lmi.GetCustomAttributes (typeof (WebMethodAttribute)).Length == 0) return null;
- return new MethodStubInfo (parent, lmi, null, xmlImporter, soapImporter);
- }
- else
- return new MethodStubInfo (parent, lmi, o [0], xmlImporter, soapImporter);
- }
-
XmlReflectionMember [] BuildRequestReflectionMembers (XmlElementAttribute optional_ns)
{
ParameterInfo [] input = MethodInfo.InParameters;
public XmlNode detail;
}
- internal class BindingInfo
- {
- public BindingInfo (WebServiceBindingAttribute at, string ns)
- {
- Name = at.Name;
- Namespace = at.Namespace;
- if (Namespace == "") Namespace = ns;
- Location = at.Location;
- }
-
- public BindingInfo (string name, string ns)
- {
- Name = name;
- Namespace = ns;
- }
-
- public string Name;
- public string Namespace;
- public string Location;
- }
-
//
// Holds the metadata loaded from the type stub, as well as
// the metadata for all the methods in the type
//
- internal class TypeStubInfo {
- Hashtable name_to_method = new Hashtable ();
+ internal class SoapTypeStubInfo : TypeStubInfo
+ {
Hashtable header_serializers = new Hashtable ();
Hashtable header_serializers_byname = new Hashtable ();
- ArrayList bindings = new ArrayList ();
- ArrayList methods = new ArrayList ();
// Precomputed
internal SoapParameterStyle ParameterStyle;
internal SoapServiceRoutingStyle RoutingStyle;
internal SoapBindingUse Use;
- internal string WebServiceName;
- internal string WebServiceNamespace;
- internal string DefaultBinding;
- internal string Description;
internal XmlSerializer FaultSerializer;
internal SoapExtensionRuntimeConfig[][] SoapExtensions;
internal SoapBindingStyle SoapBindingStyle;
- internal XmlReflectionImporter XmlImporter;
- internal SoapReflectionImporter SoapImporter;
- internal Type Type;
+ internal XmlReflectionImporter xmlImporter;
+ internal SoapReflectionImporter soapImporter;
- void GetTypeAttributes (Type t)
+ public SoapTypeStubInfo (Type t)
+ : base (t)
{
- object [] o;
-
- o = t.GetCustomAttributes (typeof (WebServiceAttribute), false);
- if (o.Length == 1){
- WebServiceAttribute a = (WebServiceAttribute) o [0];
- WebServiceName = (a.Name != string.Empty) ? a.Name : t.Name;
- WebServiceNamespace = (a.Namespace != string.Empty) ? a.Namespace : WebServiceAttribute.DefaultNamespace;
- Description = a.Description;
- } else {
- WebServiceName = t.Name;
- WebServiceNamespace = WebServiceAttribute.DefaultNamespace;
- }
+ xmlImporter = new XmlReflectionImporter ();
+ soapImporter = new SoapReflectionImporter ();
- DefaultBinding = WebServiceName + "Soap";
- BindingInfo binfo = new BindingInfo (DefaultBinding, WebServiceNamespace);
- bindings.Add (binfo);
+ object [] o;
o = t.GetCustomAttributes (typeof (WebServiceBindingAttribute), false);
foreach (WebServiceBindingAttribute at in o)
- bindings.Add (new BindingInfo (at, WebServiceNamespace));
+ Bindings.Add (new BindingInfo (at, WebServiceNamespace));
o = t.GetCustomAttributes (typeof (SoapDocumentServiceAttribute), false);
if (o.Length == 1){
SoapExtensions = SoapExtension.GetTypeExtensions (t);
}
- //
- // Extract all method information
- //
- void GetTypeMethods (Type t, XmlReflectionImporter xmlImporter, SoapReflectionImporter soapImporter)
+ public override XmlReflectionImporter XmlImporter
{
- MethodInfo [] type_methods = t.GetMethods (BindingFlags.Instance | BindingFlags.Public);
- LogicalMethodInfo [] methods = LogicalMethodInfo.Create (type_methods, LogicalMethodTypes.Sync);
-
- foreach (LogicalMethodInfo mi in methods){
- MethodStubInfo msi = MethodStubInfo.Create (this, mi, xmlImporter, soapImporter);
-
- if (msi == null)
- continue;
+ get { return xmlImporter; }
+ }
- name_to_method [msi.Name] = msi;
- this.methods.Add (msi);
- }
+ public override SoapReflectionImporter SoapImporter
+ {
+ get { return soapImporter; }
}
- internal TypeStubInfo (Type t)
+ public override string ProtocolName
{
- this.Type = t;
- GetTypeAttributes (t);
-
- XmlImporter = new XmlReflectionImporter ();
- SoapImporter = new SoapReflectionImporter ();
- GetTypeMethods (t, XmlImporter, SoapImporter);
+ get { return "Soap"; }
}
-
- internal MethodStubInfo GetMethod (string name)
+
+ protected override MethodStubInfo CreateMethodStubInfo (TypeStubInfo parent, LogicalMethodInfo lmi, bool isClientProxy)
{
- return (MethodStubInfo) name_to_method [name];
- }
+ object [] ats = lmi.GetCustomAttributes (typeof (SoapDocumentMethodAttribute));
+ if (ats.Length == 0) ats = lmi.GetCustomAttributes (typeof (SoapRpcMethodAttribute));
+ if (ats.Length == 0 && isClientProxy)
+ return null;
+ else if (ats.Length == 0)
+ return new SoapMethodStubInfo (parent, lmi, null, xmlImporter, soapImporter);
+ else
+ return new SoapMethodStubInfo (parent, lmi, ats[0], xmlImporter, soapImporter);
+ }
+
internal void RegisterHeaderType (Type type)
{
XmlSerializer s = (XmlSerializer) header_serializers [type];
internal XmlSerializer GetHeaderSerializer (XmlQualifiedName qname)
{
return (XmlSerializer) header_serializers_byname [qname];
- }
-
- internal ArrayList Methods
- {
- get { return methods; }
- }
-
- internal ArrayList Bindings
- {
- get { return bindings; }
- }
-
- internal BindingInfo GetBinding (string name)
- {
- for (int n=0; n<bindings.Count; n++)
- if (((BindingInfo)bindings[n]).Name == name) return (BindingInfo)bindings[n];
- return null;
- }
- }
-
- //
- // Manages
- //
- internal class TypeStubManager {
- static Hashtable type_to_manager;
-
- static TypeStubManager ()
- {
- type_to_manager = new Hashtable ();
- }
-
- //
- // This needs to be thread safe
- //
- static internal TypeStubInfo GetTypeStub (Type t)
- {
- TypeStubInfo tm = (TypeStubInfo) type_to_manager [t];
-
- if (tm != null)
- return tm;
-
- lock (typeof (TypeStubInfo)){
- tm = (TypeStubInfo) type_to_manager [t];
-
- if (tm != null)
- return tm;
-
- tm = new TypeStubInfo (t);
- type_to_manager [t] = tm;
-
- return tm;
- }
- }
+ }
}
}