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); } }
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); } } } }
internal bool GenerateCode(CodeNamespace codeNamespace, ImportContext importContext, Hashtable exportContext) { bindingCount = 0; anyPorts = false; this.codeNamespace = codeNamespace; Hashtable supportedBindings = new Hashtable(); Hashtable unsupportedBindings = new Hashtable(); // look for ports with bindings foreach (ServiceDescription serviceDescription in ServiceDescriptions) { foreach (Service service in serviceDescription.Services) { foreach (Port port in service.Ports) { Binding binding = ServiceDescriptions.GetBinding(port.Binding); if (supportedBindings.Contains(binding)) { continue; } PortType portType = ServiceDescriptions.GetPortType(binding.Type); MoveToBinding(service, port, binding, portType); if (IsBindingSupported()) { bindingCount++; anyPorts = true; supportedBindings.Add(binding, binding); } else if (binding != null) { unsupportedBindings[binding] = binding; } } } } // no ports, look for bindings if (bindingCount == 0) { foreach (ServiceDescription serviceDescription in ServiceDescriptions) { foreach (Binding binding in serviceDescription.Bindings) { if (unsupportedBindings.Contains(binding)) { continue; } PortType portType = ServiceDescriptions.GetPortType(binding.Type); MoveToBinding(binding, portType); if (IsBindingSupported()) { bindingCount++; } } } } // give up if no bindings if (bindingCount == 0) { // if we generated comments return true so that the comments get written return(codeNamespace.Comments.Count > 0); } this.importContext = importContext; this.exportContext = exportContext; BeginNamespace(); supportedBindings.Clear(); foreach (ServiceDescription serviceDescription in ServiceDescriptions) { if (anyPorts) { foreach (Service service in serviceDescription.Services) { foreach (Port port in service.Ports) { Binding binding = ServiceDescriptions.GetBinding(port.Binding); PortType portType = ServiceDescriptions.GetPortType(binding.Type); MoveToBinding(service, port, binding, portType); if (IsBindingSupported() && !supportedBindings.Contains(binding)) { GenerateClassForBinding(); supportedBindings.Add(binding, binding); } } } } else { foreach (Binding binding in serviceDescription.Bindings) { PortType portType = ServiceDescriptions.GetPortType(binding.Type); MoveToBinding(binding, portType); if (IsBindingSupported()) { GenerateClassForBinding(); } } } } EndNamespace(); return(true); }