protected override CodeMemberMethod GenerateMethod()
        {
            try
            {
                HttpOperationBinding httpOper = OperationBinding.Extensions.Find(typeof(HttpOperationBinding)) as HttpOperationBinding;
                if (httpOper == null)
                {
                    throw new Exception("Http operation binding not found");
                }

                XmlMembersMapping inputMembers = ImportInMembersMapping(InputMessage);
                XmlTypeMapping    outputMember = ImportOutMembersMapping(OutputMessage);

                CodeMemberMethod met = GenerateMethod(memberIds, httpOper, inputMembers, outputMember);

                xmlExporter.ExportMembersMapping(inputMembers);
                if (outputMember != null)
                {
                    xmlExporter.ExportTypeMapping(outputMember);
                }

                return(met);
            }
            catch (Exception ex)
            {
                UnsupportedOperationBindingWarning(ex.Message);
                return(null);
            }
        }
 protected override bool ReflectMethod() {
     if (!ReflectUrlParameters()) return false;
     if (!ReflectMimeReturn()) return false;
     HttpOperationBinding httpOperationBinding = new HttpOperationBinding();
     httpOperationBinding.Location = MethodUrl;
     OperationBinding.Extensions.Add(httpOperationBinding);
     return true;
 }
 protected override bool ReflectMethod()
 {
     if (!base.ReflectMimeParameters())
     {
         return false;
     }
     if (!base.ReflectMimeReturn())
     {
         return false;
     }
     HttpOperationBinding extension = new HttpOperationBinding {
         Location = base.MethodUrl
     };
     base.OperationBinding.Extensions.Add(extension);
     return true;
 }
        protected override bool ReflectMethod()
        {
            if (!ReflectMimeParameters())
            {
                return(false);
            }
            if (!ReflectMimeReturn())
            {
                return(false);
            }
            HttpOperationBinding httpOperationBinding = new HttpOperationBinding();

            httpOperationBinding.Location = MethodUrl;
            OperationBinding.Extensions.Add(httpOperationBinding);
            return(true);
        }
Exemple #5
0
        protected override bool ReflectMethod()
        {
            if (!base.ReflectUrlParameters())
            {
                return(false);
            }
            if (!base.ReflectMimeReturn())
            {
                return(false);
            }
            HttpOperationBinding extension = new HttpOperationBinding {
                Location = base.MethodUrl
            };

            base.OperationBinding.Extensions.Add(extension);
            return(true);
        }
        internal override CodeExpression BuildInvokeAsync(string messageName, CodeArrayCreateExpression paramsArray, CodeExpression delegateField, CodeExpression userStateVar)
        {
            HttpOperationBinding httpOper = OperationBinding.Extensions.Find(typeof(HttpOperationBinding)) as HttpOperationBinding;

            CodeThisReferenceExpression ethis = new CodeThisReferenceExpression();

            CodeExpression               thisURlExp        = new CodeFieldReferenceExpression(ethis, "Url");
            CodePrimitiveExpression      metUrl            = new CodePrimitiveExpression(httpOper.Location);
            CodeBinaryOperatorExpression expMethodLocation = new CodeBinaryOperatorExpression(thisURlExp, CodeBinaryOperatorType.Add, metUrl);

            CodeMethodInvokeExpression inv2 = new CodeMethodInvokeExpression(ethis, "InvokeAsync");

            inv2.Parameters.Add(new CodePrimitiveExpression(messageName));
            inv2.Parameters.Add(expMethodLocation);
            inv2.Parameters.Add(paramsArray);
            inv2.Parameters.Add(delegateField);
            inv2.Parameters.Add(userStateVar);
            return(inv2);
        }
Exemple #7
0
        //

        protected override CodeMemberMethod GenerateMethod()
        {
            HttpOperationBinding httpOperationBinding = (HttpOperationBinding)OperationBinding.Extensions.Find(typeof(HttpOperationBinding));

            if (httpOperationBinding == null)
            {
                throw OperationBindingSyntaxException(Res.GetString(Res.MissingHttpOperationElement0));
            }

            HttpMethodInfo method = new HttpMethodInfo();

            if (hasInputPayload)
            {
                method.MimeParameters = ImportMimeParameters();
                if (method.MimeParameters == null)
                {
                    UnsupportedOperationWarning(Res.GetString(Res.NoInputMIMEFormatsWereRecognized0));
                    return(null);
                }
            }
            else
            {
                method.UrlParameters = ImportUrlParameters();
                if (method.UrlParameters == null)
                {
                    UnsupportedOperationWarning(Res.GetString(Res.NoInputHTTPFormatsWereRecognized0));
                    return(null);
                }
            }
            method.MimeReturn = ImportMimeReturn();
            if (method.MimeReturn == null)
            {
                UnsupportedOperationWarning(Res.GetString(Res.NoOutputMIMEFormatsWereRecognized0));
                return(null);
            }
            method.Name = MethodNames.AddUnique(MethodName, method);
            method.Href = httpOperationBinding.Location;
            return(GenerateMethod(method));
        }
        protected override CodeMemberMethod GenerateMethod()
        {
            HttpOperationBinding binding = (HttpOperationBinding)base.OperationBinding.Extensions.Find(typeof(HttpOperationBinding));

            if (binding == null)
            {
                throw base.OperationBindingSyntaxException(System.Web.Services.Res.GetString("MissingHttpOperationElement0"));
            }
            HttpMethodInfo info = new HttpMethodInfo();

            if (this.hasInputPayload)
            {
                info.MimeParameters = this.ImportMimeParameters();
                if (info.MimeParameters == null)
                {
                    base.UnsupportedOperationWarning(System.Web.Services.Res.GetString("NoInputMIMEFormatsWereRecognized0"));
                    return(null);
                }
            }
            else
            {
                info.UrlParameters = this.ImportUrlParameters();
                if (info.UrlParameters == null)
                {
                    base.UnsupportedOperationWarning(System.Web.Services.Res.GetString("NoInputHTTPFormatsWereRecognized0"));
                    return(null);
                }
            }
            info.MimeReturn = this.ImportMimeReturn();
            if (info.MimeReturn == null)
            {
                base.UnsupportedOperationWarning(System.Web.Services.Res.GetString("NoOutputMIMEFormatsWereRecognized0"));
                return(null);
            }
            info.Name = base.MethodNames.AddUnique(base.MethodName, info);
            info.Href = binding.Location;
            return(this.GenerateMethod(info));
        }
		CodeMemberMethod GenerateMethod (CodeIdentifiers memberIds, HttpOperationBinding httpOper, XmlMembersMapping inputMembers, XmlTypeMapping outputMember)
		{
			CodeIdentifiers pids = new CodeIdentifiers ();
			CodeMemberMethod method = new CodeMemberMethod ();
			CodeMemberMethod methodBegin = new CodeMemberMethod ();
			CodeMemberMethod methodEnd = new CodeMemberMethod ();
			method.Attributes = MemberAttributes.Public;
			methodBegin.Attributes = MemberAttributes.Public;
			methodEnd.Attributes = MemberAttributes.Public;
			
			// Find unique names for temporary variables
			
			for (int n=0; n<inputMembers.Count; n++)
				pids.AddUnique (inputMembers[n].MemberName, inputMembers[n]);

			string varAsyncResult = pids.AddUnique ("asyncResult","asyncResult");
			string varCallback = pids.AddUnique ("callback","callback");
			string varAsyncState = pids.AddUnique ("asyncState","asyncState");

			string messageName = memberIds.AddUnique(CodeIdentifier.MakeValid(Operation.Name),method);

			method.Name = Operation.Name;
			methodBegin.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("Begin" + Operation.Name),method);
			methodEnd.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("End" + Operation.Name),method);

			method.ReturnType = new CodeTypeReference (typeof(void));
			methodEnd.ReturnType = new CodeTypeReference (typeof(void));
			methodEnd.Parameters.Add (new CodeParameterDeclarationExpression (typeof (IAsyncResult),varAsyncResult));

			CodeExpression[] paramArray = new CodeExpression [inputMembers.Count];

			for (int n=0; n<inputMembers.Count; n++)
			{
				string ptype = GetSimpleType (inputMembers[n]);
				CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (ptype, inputMembers[n].MemberName);
				
				param.Direction = FieldDirection.In;
				method.Parameters.Add (param);
				methodBegin.Parameters.Add (param);
				paramArray [n] = new CodeVariableReferenceExpression (param.Name);
			}

			bool isVoid = true;
			if (outputMember != null)
			{
				method.ReturnType = new CodeTypeReference (outputMember.TypeFullName);
				methodEnd.ReturnType = new CodeTypeReference (outputMember.TypeFullName);
				xmlExporter.AddMappingMetadata (method.ReturnTypeCustomAttributes, outputMember, "");
				isVoid = false;
			}

			methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (AsyncCallback),varCallback));
			methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (object),varAsyncState));
			methodBegin.ReturnType = new CodeTypeReference (typeof(IAsyncResult));

			// Array of input parameters
			
			CodeArrayCreateExpression methodParams;
			if (paramArray.Length > 0)
				methodParams = new CodeArrayCreateExpression (typeof(object), paramArray);
			else
				methodParams = new CodeArrayCreateExpression (typeof(object), 0);

			// Generate method url
			
			CodeThisReferenceExpression ethis = new CodeThisReferenceExpression();
			
			CodeExpression thisURlExp = new CodeFieldReferenceExpression (ethis, "Url");
			CodePrimitiveExpression metUrl = new CodePrimitiveExpression (httpOper.Location);
			CodeBinaryOperatorExpression expMethodLocation = new CodeBinaryOperatorExpression (thisURlExp, CodeBinaryOperatorType.Add, metUrl);
			
			// Invoke call
			
			CodePrimitiveExpression varMsgName = new CodePrimitiveExpression (messageName);
			CodeMethodInvokeExpression inv;

			inv = new CodeMethodInvokeExpression (ethis, "Invoke", varMsgName, expMethodLocation, methodParams);
			if (!isVoid)
				method.Statements.Add (new CodeMethodReturnStatement (new CodeCastExpression (method.ReturnType, inv)));
			else
				method.Statements.Add (inv);
			
			// Begin Invoke Call
			
			CodeExpression expCallb = new CodeVariableReferenceExpression (varCallback);
			CodeExpression expAsyncs = new CodeVariableReferenceExpression (varAsyncState);
			inv = new CodeMethodInvokeExpression (ethis, "BeginInvoke", varMsgName, expMethodLocation, methodParams, expCallb, expAsyncs);
			methodBegin.Statements.Add (new CodeMethodReturnStatement (inv));
			
			// End Invoke call
			
			CodeExpression varAsyncr = new CodeVariableReferenceExpression (varAsyncResult);
			inv = new CodeMethodInvokeExpression (ethis, "EndInvoke", varAsyncr);
			if (!isVoid)
				methodEnd.Statements.Add (new CodeMethodReturnStatement (new CodeCastExpression (methodEnd.ReturnType, inv)));
			else
				methodEnd.Statements.Add (inv);
			
			// Attributes

			CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.Protocols.HttpMethodAttribute");
			att.Arguments.Add (new CodeAttributeArgument (new CodeTypeOfExpression(GetOutMimeFormatter ())));
			att.Arguments.Add (new CodeAttributeArgument (new CodeTypeOfExpression(GetInMimeFormatter ())));
			AddCustomAttribute (method, att, true);
		
			CodeTypeDeclaration.Members.Add (method);
			CodeTypeDeclaration.Members.Add (methodBegin);
			CodeTypeDeclaration.Members.Add (methodEnd);
			
			return method;
		}		
        CodeMemberMethod GenerateMethod(CodeIdentifiers memberIds, HttpOperationBinding httpOper, XmlMembersMapping inputMembers, XmlTypeMapping outputMember)
        {
            CodeIdentifiers  pids        = new CodeIdentifiers();
            CodeMemberMethod method      = new CodeMemberMethod();
            CodeMemberMethod methodBegin = new CodeMemberMethod();
            CodeMemberMethod methodEnd   = new CodeMemberMethod();

            method.Attributes      = MemberAttributes.Public;
            methodBegin.Attributes = MemberAttributes.Public;
            methodEnd.Attributes   = MemberAttributes.Public;

            // Find unique names for temporary variables

            for (int n = 0; n < inputMembers.Count; n++)
            {
                pids.AddUnique(inputMembers[n].MemberName, inputMembers[n]);
            }

            string varAsyncResult = pids.AddUnique("asyncResult", "asyncResult");
            string varCallback    = pids.AddUnique("callback", "callback");
            string varAsyncState  = pids.AddUnique("asyncState", "asyncState");

            string messageName = memberIds.AddUnique(CodeIdentifier.MakeValid(Operation.Name), method);

            method.Name      = Operation.Name;
            methodBegin.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("Begin" + Operation.Name), method);
            methodEnd.Name   = memberIds.AddUnique(CodeIdentifier.MakeValid("End" + Operation.Name), method);

            method.ReturnType    = new CodeTypeReference(typeof(void));
            methodEnd.ReturnType = new CodeTypeReference(typeof(void));
            methodEnd.Parameters.Add(new CodeParameterDeclarationExpression(typeof(IAsyncResult), varAsyncResult));

            CodeExpression[] paramArray = new CodeExpression [inputMembers.Count];

            for (int n = 0; n < inputMembers.Count; n++)
            {
                string ptype = GetSimpleType(inputMembers[n]);
                CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression(ptype, inputMembers[n].MemberName);

                param.Direction = FieldDirection.In;
                method.Parameters.Add(param);
                methodBegin.Parameters.Add(param);
                paramArray [n] = new CodeVariableReferenceExpression(param.Name);
            }

            bool isVoid = true;

            if (outputMember != null)
            {
                method.ReturnType    = new CodeTypeReference(outputMember.TypeFullName);
                methodEnd.ReturnType = new CodeTypeReference(outputMember.TypeFullName);
                xmlExporter.AddMappingMetadata(method.ReturnTypeCustomAttributes, outputMember, "");
                isVoid = false;
            }

            methodBegin.Parameters.Add(new CodeParameterDeclarationExpression(typeof(AsyncCallback), varCallback));
            methodBegin.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), varAsyncState));
            methodBegin.ReturnType = new CodeTypeReference(typeof(IAsyncResult));

            // Array of input parameters

            CodeArrayCreateExpression methodParams;

            if (paramArray.Length > 0)
            {
                methodParams = new CodeArrayCreateExpression(typeof(object), paramArray);
            }
            else
            {
                methodParams = new CodeArrayCreateExpression(typeof(object), 0);
            }

            // Generate method url

            CodeThisReferenceExpression ethis = new CodeThisReferenceExpression();

            CodeExpression               thisURlExp        = new CodeFieldReferenceExpression(ethis, "Url");
            CodePrimitiveExpression      metUrl            = new CodePrimitiveExpression(httpOper.Location);
            CodeBinaryOperatorExpression expMethodLocation = new CodeBinaryOperatorExpression(thisURlExp, CodeBinaryOperatorType.Add, metUrl);

            // Invoke call

            CodePrimitiveExpression    varMsgName = new CodePrimitiveExpression(messageName);
            CodeMethodInvokeExpression inv;

            inv = new CodeMethodInvokeExpression(ethis, "Invoke", varMsgName, expMethodLocation, methodParams);
            if (!isVoid)
            {
                method.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(method.ReturnType, inv)));
            }
            else
            {
                method.Statements.Add(inv);
            }

            // Begin Invoke Call

            CodeExpression expCallb  = new CodeVariableReferenceExpression(varCallback);
            CodeExpression expAsyncs = new CodeVariableReferenceExpression(varAsyncState);

            inv = new CodeMethodInvokeExpression(ethis, "BeginInvoke", varMsgName, expMethodLocation, methodParams, expCallb, expAsyncs);
            methodBegin.Statements.Add(new CodeMethodReturnStatement(inv));

            // End Invoke call

            CodeExpression varAsyncr = new CodeVariableReferenceExpression(varAsyncResult);

            inv = new CodeMethodInvokeExpression(ethis, "EndInvoke", varAsyncr);
            if (!isVoid)
            {
                methodEnd.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(methodEnd.ReturnType, inv)));
            }
            else
            {
                methodEnd.Statements.Add(inv);
            }

            // Attributes

            CodeAttributeDeclaration att = new CodeAttributeDeclaration("System.Web.Services.Protocols.HttpMethodAttribute");

            att.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(GetOutMimeFormatter())));
            att.Arguments.Add(new CodeAttributeArgument(new CodeTypeOfExpression(GetInMimeFormatter())));
            AddCustomAttribute(method, att, true);

            CodeTypeDeclaration.Members.Add(method);
            CodeTypeDeclaration.Members.Add(methodBegin);
            CodeTypeDeclaration.Members.Add(methodEnd);

            return(method);
        }
        protected override bool ReflectMethod()
        {
            LogicalTypeInfo      ti  = TypeStubManager.GetLogicalTypeInfo(ServiceType);
            HttpOperationBinding sob = new HttpOperationBinding();

            sob.Location = "/" + MethodStubInfo.Name;
            OperationBinding.Extensions.Add(sob);

            if (!Method.IsVoid)
            {
                MimeXmlBinding mxb = new MimeXmlBinding();
                mxb.Part = "Body";
                OperationBinding.Output.Extensions.Add(mxb);

                MessagePart part = new MessagePart();
                part.Name = "Body";

                XmlTypeMapping   map   = ReflectionImporter.ImportTypeMapping(Method.ReturnType, ti.GetWebServiceLiteralNamespace(ServiceDescription.TargetNamespace));
                XmlQualifiedName qname = new XmlQualifiedName(map.ElementName, map.Namespace);
                part.Element = qname;
                OutputMessage.Parts.Add(part);
                SchemaExporter.ExportTypeMapping(map);
            }

            XmlReflectionMember[] mems = new XmlReflectionMember [Method.Parameters.Length];
            for (int n = 0; n < Method.Parameters.Length; n++)
            {
                ParameterInfo       param = Method.Parameters [n];
                XmlReflectionMember mem   = new XmlReflectionMember();
                mem.MemberName = param.Name;
                Type ptype = param.ParameterType;
                if (ptype.IsByRef)
                {
                    ptype = ptype.GetElementType();
                }
                mem.MemberType = ptype;
                mems [n]       = mem;
            }

            XmlMembersMapping memap = ReflectionImporter.ImportMembersMapping("", ti.WebServiceAbstractNamespace, mems, false);
            bool allPrimitives      = true;

            for (int n = 0; n < memap.Count; n++)
            {
                XmlMemberMapping mem  = memap[n];
                MessagePart      part = new MessagePart();
                XmlQualifiedName pqname;

                if (mem.TypeNamespace == "")
                {
                    pqname = new XmlQualifiedName(mem.TypeName, XmlSchema.Namespace);
                }
                else
                {
                    pqname        = new XmlQualifiedName(mem.TypeName, mem.TypeNamespace);
                    allPrimitives = false;
                }

                part.Type = pqname;
                part.Name = mem.ElementName;
                InputMessage.Parts.Add(part);
            }

            if (!allPrimitives)
            {
                SoapSchemaExporter.ExportMembersMapping(memap);
            }

            return(true);
        }
 private void Write85_HttpOperationBinding(string n, string ns, HttpOperationBinding o, bool isNullable, bool needType)
 {
     if (o == null)
     {
         if (isNullable)
         {
             base.WriteNullTagLiteral(n, ns);
         }
     }
     else
     {
         if (!needType && !(o.GetType() == typeof(HttpOperationBinding)))
         {
             throw base.CreateUnknownTypeException(o);
         }
         base.WriteStartElement(n, ns, o, false, null);
         if (needType)
         {
             base.WriteXsiType("HttpOperationBinding", "http://schemas.xmlsoap.org/wsdl/http/");
         }
         if (o.Required)
         {
             base.WriteAttribute("required", "http://schemas.xmlsoap.org/wsdl/", XmlConvert.ToString(o.Required));
         }
         base.WriteAttribute("location", "", o.Location);
         base.WriteEndElement(o);
     }
 }
		protected override bool ReflectMethod ()
		{
			LogicalTypeInfo ti = TypeStubManager.GetLogicalTypeInfo (ServiceType);
			HttpOperationBinding sob = new HttpOperationBinding();
			sob.Location = "/" + MethodStubInfo.Name;
			OperationBinding.Extensions.Add (sob);
			
			if (!Method.IsVoid)
			{
				MimeXmlBinding mxb = new MimeXmlBinding ();
				mxb.Part = "Body";
				OperationBinding.Output.Extensions.Add (mxb);
			
				MessagePart part = new MessagePart ();
				part.Name = "Body";	
				
				XmlTypeMapping map = ReflectionImporter.ImportTypeMapping (Method.ReturnType, ti.GetWebServiceLiteralNamespace (ServiceDescription.TargetNamespace));
				XmlQualifiedName qname = new XmlQualifiedName (map.ElementName, map.Namespace);
				part.Element = qname;
				OutputMessage.Parts.Add (part);
				SchemaExporter.ExportTypeMapping (map);
			}
			
			XmlReflectionMember[] mems = new XmlReflectionMember [Method.Parameters.Length];
			for (int n=0; n<Method.Parameters.Length; n++)
			{
				ParameterInfo param = Method.Parameters [n];
				XmlReflectionMember mem = new XmlReflectionMember ();
				mem.MemberName = param.Name;
				Type ptype = param.ParameterType;
				if (ptype.IsByRef) ptype = ptype.GetElementType ();
				mem.MemberType = ptype;
				mems [n] = mem;
			}
			
			XmlMembersMapping memap = ReflectionImporter.ImportMembersMapping ("", ti.WebServiceAbstractNamespace, mems, false);
			bool allPrimitives = true;
			
			for (int n=0; n<memap.Count; n++)
			{
				XmlMemberMapping mem = memap[n];
				MessagePart part = new MessagePart ();
				XmlQualifiedName pqname;
				
				if (mem.TypeNamespace == "") 
					pqname = new XmlQualifiedName (mem.TypeName, XmlSchema.Namespace);
				else {
					pqname = new XmlQualifiedName (mem.TypeName, mem.TypeNamespace); 
					allPrimitives = false; 
				}

				part.Type = pqname;
				part.Name = mem.ElementName;
				InputMessage.Parts.Add (part);
			}

			if (!allPrimitives)
				SoapSchemaExporter.ExportMembersMapping (memap);
			
			return true;
		}