//
        // Extract all method information
        //
        protected virtual void BuildTypeMethods()
        {
            bool isClientProxy = typeof(WebClientProtocol).IsAssignableFrom(Type);

            ArrayList metStubs = new ArrayList();

            foreach (LogicalMethodInfo mi in logicalType.LogicalMethods)
            {
                if (!isClientProxy && mi.CustomAttributeProvider.GetCustomAttributes(typeof(WebMethodAttribute), true).Length == 0)
                {
                    continue;
                }

                MethodStubInfo msi = CreateMethodStubInfo(this, mi, isClientProxy);

                if (msi == null)
                {
                    continue;
                }

                if (name_to_method.ContainsKey(msi.Name))
                {
                    string msg = "Both " + msi.MethodInfo.ToString() + " and " + GetMethod(msi.Name).MethodInfo + " use the message name '" + msi.Name + "'. ";
                    msg += "Use the MessageName property of WebMethod custom attribute to specify unique message names for the methods";
                    throw new InvalidOperationException(msg);
                }

                name_to_method [msi.Name] = msi;
                metStubs.Add(msi);
            }
            methods = (MethodStubInfo[])metStubs.ToArray(typeof(MethodStubInfo));
        }
        IHttpHandler GetTypeHandler(HttpContext context, WebServiceHandler handler)
        {
            MethodStubInfo method = handler.GetRequestMethod(context);

            if (method == null)
            {
                return(null);
            }

            int cache_duration = method.MethodInfo.CacheDuration;

            if (cache_duration > 0)
            {
                context.Response.ExpiresAbsolute = DateTime.Now.AddSeconds(cache_duration);
            }
            if (method.MethodInfo.EnableSession)
            {
                return(new SessionWrapperHandler(handler));
            }
            else
            {
                return(handler);
            }
        }
Beispiel #3
0
		bool ImportBindingContent (ServiceDescription desc, TypeStubInfo typeInfo, string url, BindingInfo binfo)
		{
			serviceDescription = desc;
			
			// Look for an unused name
			
			int n=0;
			string name = binfo.Name;
			bool found;
			do
			{
				found = false;
				foreach (Binding bi in desc.Bindings)
					if (bi.Name == name) { found = true; n++; name = binfo.Name+n; break; }
			}
			while (found);
			
			// Create the binding
			
			binding = new Binding ();
			binding.Name = name;
			binding.Type = new XmlQualifiedName (binding.Name, binfo.Namespace);
			if (binfo.WebServiceBindingAttribute != null && binfo.WebServiceBindingAttribute.EmitConformanceClaims) {
				XmlDocument doc = new XmlDocument ();
				XmlElement docElement = doc.CreateElement ("wsdl", "documentation", "http://schemas.xmlsoap.org/wsdl/");
				XmlElement claimsElement = doc.CreateElement ("wsi", "Claim", "http://ws-i.org/schemas/conformanceClaim/");
				claimsElement.Attributes.Append (doc.CreateAttribute ("conformsTo")).Value = "http://ws-i.org/profiles/basic/1.1";
				docElement.AppendChild (claimsElement);
				binding.DocumentationElement = docElement;
			}
			
			portType = new PortType ();
			portType.Name = binding.Name;

			BeginClass ();

			foreach (SoapExtensionReflector reflector in extensionReflectors)
			{
				reflector.ReflectionContext = this;
				reflector.ReflectDescription ();
			}

			foreach (MethodStubInfo method in typeInfo.Methods)
			{
				methodStubInfo = method;
				
				string metBinding = ReflectMethodBinding ();
				if (typeInfo.GetBinding (metBinding) != binfo) continue;
				
				operation = new Operation ();
				operation.Name = method.OperationName;
				operation.Documentation = method.MethodAttribute.Description;

				// FIXME: SOAP 1.1 and SOAP 1.2 should share
				// the same message definitions.

				inputMessage = new Message ();
				inputMessage.Name = method.Name + ProtocolName + "In";
				ServiceDescription.Messages.Add (inputMessage);
				
				outputMessage = new Message ();
				outputMessage.Name = method.Name + ProtocolName + "Out";
				ServiceDescription.Messages.Add (outputMessage);

				OperationInput inOp = new OperationInput ();
				if (method.Name != method.OperationName) inOp.Name = method.Name;
				Operation.Messages.Add (inOp);
				inOp.Message = new XmlQualifiedName (inputMessage.Name, ServiceDescription.TargetNamespace);
				
				OperationOutput outOp = new OperationOutput ();
				if (method.Name != method.OperationName) outOp.Name = method.Name;
				Operation.Messages.Add (outOp);
				outOp.Message = new XmlQualifiedName (outputMessage.Name, ServiceDescription.TargetNamespace);
			
				portType.Operations.Add (operation);
				ImportOperationBinding ();
				
				if (!ReflectMethod ()) {
					// (It is somewhat hacky) If we don't
					// add input/output Messages, update
					// portType/input/@message and
					// porttype/output/@message.
					Message dupIn = Parent.MappedMessagesIn [method.MethodInfo];
					ServiceDescription.Messages.Remove (inputMessage);
					inOp.Message = new XmlQualifiedName (dupIn.Name, ServiceDescription.TargetNamespace);
					Message dupOut = Parent.MappedMessagesOut [method.MethodInfo];
					ServiceDescription.Messages.Remove (outputMessage);
					outOp.Message = new XmlQualifiedName (dupOut.Name, ServiceDescription.TargetNamespace);
				}

				foreach (SoapExtensionReflector reflector in extensionReflectors)
				{
					reflector.ReflectionContext = this;
					reflector.ReflectMethod ();
				}
			}
			
			EndClass ();
			
			if (portType.Operations.Count > 0)
			{
				desc.Bindings.Add (binding);
				desc.PortTypes.Add (portType);
				return true;
			}
			else
				return false;
		}
		bool ImportBindingContent (ServiceDescription desc, TypeStubInfo typeInfo, string url, BindingInfo binfo)
		{
			serviceDescription = desc;
			
			// Look for an unused name
			
			int n=0;
			string name = binfo.Name;
			bool found;
			do
			{
				found = false;
				foreach (Binding bi in desc.Bindings)
					if (bi.Name == name) { found = true; n++; name = binfo.Name+n; break; }
			}
			while (found);
			
			// Create the binding
			
			binding = new Binding ();
			binding.Name = name;
			binding.Type = new XmlQualifiedName (binding.Name, binfo.Namespace);
			
			portType = new PortType ();
			portType.Name = binding.Name;

			BeginClass ();
			
			foreach (MethodStubInfo method in typeInfo.Methods)
			{
				methodStubInfo = method;
				
				string metBinding = ReflectMethodBinding ();
				if (typeInfo.GetBinding (metBinding) != binfo) continue;
				
				operation = new Operation ();
				operation.Name = method.OperationName;
				operation.Documentation = method.MethodAttribute.Description;
				
				inputMessage = new Message ();
				inputMessage.Name = method.Name + ProtocolName + "In";
				ServiceDescription.Messages.Add (inputMessage);
				
				outputMessage = new Message ();
				outputMessage.Name = method.Name + ProtocolName + "Out";
				ServiceDescription.Messages.Add (outputMessage);

				OperationInput inOp = new OperationInput ();
				if (method.Name != method.OperationName) inOp.Name = method.Name;
				Operation.Messages.Add (inOp);
				inOp.Message = new XmlQualifiedName (inputMessage.Name, ServiceDescription.TargetNamespace);
				
				OperationOutput outOp = new OperationOutput ();
				if (method.Name != method.OperationName) outOp.Name = method.Name;
				Operation.Messages.Add (outOp);
				outOp.Message = new XmlQualifiedName (outputMessage.Name, ServiceDescription.TargetNamespace);
			
				portType.Operations.Add (operation);
				ImportOperationBinding ();
				
				ReflectMethod ();
				
				foreach (SoapExtensionReflector reflector in extensionReflectors)
				{
					reflector.ReflectionContext = this;
					reflector.ReflectMethod ();
				}
			}
			
			EndClass ();
			
			if (portType.Operations.Count > 0)
			{
				desc.Bindings.Add (binding);
				desc.PortTypes.Add (portType);
				return true;
			}
			else
				return false;
		}