void MoveToOperation(Operation operation) { this.operation = operation; operationBinding = null; foreach (OperationBinding b in binding.Operations) { if (operation.IsBoundBy(b)) { if (operationBinding != null) { throw OperationSyntaxException(Res.GetString(Res.DuplicateInputOutputNames0)); } operationBinding = b; } } if (operationBinding == null) { throw OperationSyntaxException(Res.GetString(Res.MissingBinding0)); } //NOTE: The following two excepions would never happen since IsBoundBy checks these conditions already. if (operation.Messages.Input != null && operationBinding.Input == null) { throw OperationSyntaxException(Res.GetString(Res.MissingInputBinding0)); } if (operation.Messages.Output != null && operationBinding.Output == null) { throw OperationSyntaxException(Res.GetString(Res.MissingOutputBinding0)); } this.inputMessage = operation.Messages.Input == null ? null : ServiceDescriptions.GetMessage(operation.Messages.Input.Message); this.outputMessage = operation.Messages.Output == null ? null : ServiceDescriptions.GetMessage(operation.Messages.Output.Message); }
void ImportHeader(CodeMemberMethod method, SoapHeaderBinding hb, SoapHeaderDirection direction) { Message msg = ServiceDescriptions.GetMessage(hb.Message); if (msg == null) { throw new InvalidOperationException("Message " + hb.Message + " not found"); } MessagePart part = msg.Parts [hb.Part]; if (part == null) { throw new InvalidOperationException("Message part " + hb.Part + " not found in message " + hb.Message); } XmlTypeMapping map; string hname; if (hb.Use == SoapBindingUse.Literal) { map = xmlImporter.ImportDerivedTypeMapping(part.Element, typeof(SoapHeader)); hname = part.Element.Name; xmlExporter.ExportTypeMapping(map); } else { map = soapImporter.ImportDerivedTypeMapping(part.Type, typeof(SoapHeader), true); hname = part.Type.Name; soapExporter.ExportTypeMapping(map); } string varName = headerVariables [map] as string; if (varName == null) { if (hname == map.TypeName) { varName = memberIds.AddUnique(CodeIdentifier.MakeValid(hname + "Value"), hb); } else { varName = memberIds.AddUnique(CodeIdentifier.MakeValid(hname), hb); } #if NET_2_0 string propName = varName; varName = varName + "Field"; #endif headerVariables.Add(map, varName); CodeMemberField codeField = new CodeMemberField(map.TypeFullName, varName); CodeTypeDeclaration.Members.Add(codeField); #if NET_2_0 codeField.Attributes = MemberAttributes.Private; CodeMemberProperty codeProperty = new CodeMemberProperty(); codeProperty.Name = propName; codeProperty.Type = new CodeTypeReference(map.TypeFullName); codeProperty.Attributes = MemberAttributes.Public | MemberAttributes.Final; codeProperty.HasGet = codeProperty.HasSet = true; CodeExpression ce = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), varName); codeProperty.SetStatements.Add(new CodeAssignStatement(ce, new CodePropertySetValueReferenceExpression())); codeProperty.GetStatements.Add(new CodeMethodReturnStatement(ce)); CodeTypeDeclaration.Members.Add(codeProperty); varName = propName; #else codeField.Attributes = MemberAttributes.Public; #endif } CodeAttributeDeclaration att = new CodeAttributeDeclaration("System.Web.Services.Protocols.SoapHeaderAttribute"); att.Arguments.Add(GetArg(varName)); #if ONLY_1_0 att.Arguments.Add(GetArg("Required", false)); #endif if (direction != SoapHeaderDirection.In) { att.Arguments.Add(GetEnumArg("Direction", "System.Web.Services.Protocols.SoapHeaderDirection", direction.ToString())); } AddCustomAttribute(method, att, true); }
void ClasifySchemas(ArrayList importInfo) { // I don't like this, but I could not find any other way of clasifying // schemas between encoded and literal. xmlSchemas = new XmlSchemas(); soapSchemas = new XmlSchemas(); foreach (ImportInfo info in importInfo) { foreach (Service service in info.ServiceDescription.Services) { foreach (Port port in service.Ports) { this.iinfo = info; this.port = port; binding = ServiceDescriptions.GetBinding(port.Binding); if (binding == null) { continue; } portType = ServiceDescriptions.GetPortType(binding.Type); if (portType == null) { continue; } foreach (OperationBinding oper in binding.Operations) { operationBinding = oper; operation = FindPortOperation(); if (operation == null) { continue; } foreach (OperationMessage omsg in operation.Messages) { Message msg = ServiceDescriptions.GetMessage(omsg.Message); if (msg == null) { continue; } if (omsg is OperationInput) { inputMessage = msg; } else { outputMessage = msg; } } if (GetMessageEncoding(oper.Input) == SoapBindingUse.Encoded) { AddMessageSchema(soapSchemas, oper.Input, inputMessage); } else { AddMessageSchema(xmlSchemas, oper.Input, inputMessage); } if (oper.Output != null) { if (GetMessageEncoding(oper.Output) == SoapBindingUse.Encoded) { AddMessageSchema(soapSchemas, oper.Output, outputMessage); } else { AddMessageSchema(xmlSchemas, oper.Output, outputMessage); } } } } } } XmlSchemas defaultList = xmlSchemas; if (xmlSchemas.Count == 0 && soapSchemas.Count > 0) { defaultList = soapSchemas; } // Schemas not referenced by any message foreach (XmlSchema sc in Schemas) { if (!soapSchemas.Contains(sc) && !xmlSchemas.Contains(sc)) { if (ImportsEncodedNamespace(sc)) { soapSchemas.Add(sc); } else { defaultList.Add(sc); } } } }
void ImportPortBinding(bool multipleBindings) { if (port != null) { if (multipleBindings) { className = binding.Name; } else { className = service.Name; } } else { className = binding.Name; } className = classNames.AddUnique(CodeIdentifier.MakeValid(className), port); className = className.Replace("_x0020_", ""); // MS.NET seems to do this try { portType = ServiceDescriptions.GetPortType(binding.Type); if (portType == null) { throw new Exception("Port type not found: " + binding.Type); } CodeTypeDeclaration codeClass = BeginClass(); codeTypeDeclaration = codeClass; AddCodeType(codeClass, port != null ? port.Documentation : null); codeClass.Attributes = MemberAttributes.Public; if (service != null && service.Documentation != null && service.Documentation != "") { AddComments(codeClass, service.Documentation); } if (Style == ServiceDescriptionImportStyle.Client) { CodeAttributeDeclaration att = new CodeAttributeDeclaration("System.Diagnostics.DebuggerStepThroughAttribute"); AddCustomAttribute(codeClass, att, true); att = new CodeAttributeDeclaration("System.ComponentModel.DesignerCategoryAttribute"); att.Arguments.Add(GetArg("code")); AddCustomAttribute(codeClass, att, true); } else { codeClass.TypeAttributes = System.Reflection.TypeAttributes.Abstract | System.Reflection.TypeAttributes.Public; } if (binding.Operations.Count == 0) { warnings |= ServiceDescriptionImportWarnings.NoMethodsGenerated; return; } foreach (OperationBinding oper in binding.Operations) { operationBinding = oper; operation = FindPortOperation(); if (operation == null) { throw new Exception("Operation " + operationBinding.Name + " not found in portType " + PortType.Name); } inputMessage = null; outputMessage = null; foreach (OperationMessage omsg in operation.Messages) { Message msg = ServiceDescriptions.GetMessage(omsg.Message); if (msg == null) { throw new Exception("Message not found: " + omsg.Message); } if (omsg is OperationInput) { inputMessage = msg; } else { outputMessage = msg; } } CodeMemberMethod method = GenerateMethod(); if (method != null) { methodName = method.Name; if (operation.Documentation != null && operation.Documentation != "") { AddComments(method, operation.Documentation); } #if NET_2_0 if (Style == ServiceDescriptionImportStyle.Client) { AddAsyncMembers(method.Name, method); } #endif } } #if NET_2_0 if (Style == ServiceDescriptionImportStyle.Client) { AddAsyncTypes(); } #endif EndClass(); } catch (InvalidOperationException ex) { warnings |= ServiceDescriptionImportWarnings.NoCodeGenerated; UnsupportedBindingWarning(ex.Message); } }