* ProtocolImporter.cs: Moved some code to ServiceDescriptionImporter.
authorLluis Sanchez <lluis@novell.com>
Mon, 6 Oct 2003 21:52:08 +0000 (21:52 -0000)
committerLluis Sanchez <lluis@novell.com>
Mon, 6 Oct 2003 21:52:08 +0000 (21:52 -0000)
  WebServiceBindingAttribute addition moved to SoapProtocolImporter.
  Moved GetServiceUrl here (from SoapProtocolImporter).
* ServiceDescriptionImporter.cs: Added support for HttpGet and HttpPost
  importers.
* SoapProtocolImporter.cs: Minor fixes.
* HttpSimpleProtocolImporter.cs, HttpGetProtocolImporter.cs,
  HttpPostProtocolImporter.cs: new files that implement HttpGet and HttpPost
  importers.

svn path=/trunk/mcs/; revision=18691

mcs/class/System.Web.Services/System.Web.Services.Description/ChangeLog
mcs/class/System.Web.Services/System.Web.Services.Description/HttpGetProtocolImporter.cs [new file with mode: 0644]
mcs/class/System.Web.Services/System.Web.Services.Description/HttpPostProtocolImporter.cs [new file with mode: 0644]
mcs/class/System.Web.Services/System.Web.Services.Description/HttpSimpleProtocolImporter.cs [new file with mode: 0644]
mcs/class/System.Web.Services/System.Web.Services.Description/ProtocolImporter.cs
mcs/class/System.Web.Services/System.Web.Services.Description/ServiceDescriptionImporter.cs
mcs/class/System.Web.Services/System.Web.Services.Description/SoapProtocolImporter.cs

index bd9bed5448db7f48aa1391c88d1a8953daed676c..eeee103e3709c5914e83e19c9926f56237b40841 100644 (file)
@@ -1,3 +1,15 @@
+2003-10-06  Lluis Sanchez Gual <lluis@ximian.com>
+
+       * ProtocolImporter.cs: Moved some code to ServiceDescriptionImporter.
+         WebServiceBindingAttribute addition moved to SoapProtocolImporter.
+         Moved GetServiceUrl here (from SoapProtocolImporter).
+       * ServiceDescriptionImporter.cs: Added support for HttpGet and HttpPost
+         importers.
+       * SoapProtocolImporter.cs: Minor fixes.
+       * HttpSimpleProtocolImporter.cs, HttpGetProtocolImporter.cs,
+         HttpPostProtocolImporter.cs: new files that implement HttpGet and HttpPost
+         importers.
+
 2003-10-04  Lluis Sanchez Gual <lluis@ximian.com>
 
        * ProtocolReflector.cs: The ReflectionImporter property now creates a
diff --git a/mcs/class/System.Web.Services/System.Web.Services.Description/HttpGetProtocolImporter.cs b/mcs/class/System.Web.Services/System.Web.Services.Description/HttpGetProtocolImporter.cs
new file mode 100644 (file)
index 0000000..d655062
--- /dev/null
@@ -0,0 +1,65 @@
+// 
+// System.Web.Services.Description.HttpGetProtocolImporter.cs
+//
+// Author:
+//   Lluis Sanchez Gual (lluis@ximian.com)
+//
+// Copyright (C) 2003 Ximian, Inc.
+//
+
+using System;
+using System.CodeDom;
+using System.Web.Services;
+using System.Web.Services.Protocols;
+using System.Xml.Serialization;
+using System.Xml;
+using System.Collections;
+using System.Configuration;
+
+namespace System.Web.Services.Description 
+{
+       internal class HttpGetProtocolImporter : HttpSimpleProtocolImporter
+       {
+               #region Constructors
+       
+               public HttpGetProtocolImporter ()
+               {
+               }
+               
+               #endregion // Constructors
+
+               #region Properties
+
+               public override string ProtocolName {
+                       get { return "HttpGet"; }
+               }
+
+               #endregion // Properties
+
+               #region Methods
+               
+               protected override CodeTypeDeclaration BeginClass ()
+               {
+                       CodeTypeDeclaration codeClass = base.BeginClass ();
+                       CodeTypeReference ctr = new CodeTypeReference ("System.Web.Services.Protocols.HttpGetClientProtocol");
+                       codeClass.BaseTypes.Add (ctr);
+                       return codeClass;
+               }
+               
+               protected override Type GetInMimeFormatter ()
+               {
+                       HttpUrlEncodedBinding bin = OperationBinding.Input.Extensions.Find (typeof(HttpUrlEncodedBinding)) as HttpUrlEncodedBinding;
+                       if (bin == null) throw new Exception ("Http urlEncoded binding not found");
+                       return typeof (UrlParameterWriter);
+               }
+
+               protected override bool IsBindingSupported ()
+               {
+                       HttpBinding bin = (HttpBinding) Binding.Extensions.Find (typeof(HttpBinding));
+                       if (bin == null) return false;
+                       return bin.Verb == "GET";
+               }
+               
+               #endregion
+       }
+}
diff --git a/mcs/class/System.Web.Services/System.Web.Services.Description/HttpPostProtocolImporter.cs b/mcs/class/System.Web.Services/System.Web.Services.Description/HttpPostProtocolImporter.cs
new file mode 100644 (file)
index 0000000..375b79a
--- /dev/null
@@ -0,0 +1,66 @@
+// 
+// System.Web.Services.Description.HttpPostProtocolImporter.cs
+//
+// Author:
+//   Lluis Sanchez Gual (lluis@ximian.com)
+//
+// Copyright (C) 2003 Ximian, Inc.
+//
+
+using System;
+using System.CodeDom;
+using System.Web.Services;
+using System.Web.Services.Protocols;
+using System.Xml.Serialization;
+using System.Xml;
+using System.Collections;
+using System.Configuration;
+
+namespace System.Web.Services.Description 
+{
+       internal class HttpPostProtocolImporter : HttpSimpleProtocolImporter
+       {
+               #region Constructors
+       
+               public HttpPostProtocolImporter ()
+               {
+               }
+               
+               #endregion // Constructors
+
+               #region Properties
+
+               public override string ProtocolName {
+                       get { return "HttpPost"; }
+               }
+
+               #endregion // Properties
+
+               #region Methods
+               
+               protected override CodeTypeDeclaration BeginClass ()
+               {
+                       CodeTypeDeclaration codeClass = base.BeginClass ();
+                       CodeTypeReference ctr = new CodeTypeReference ("System.Web.Services.Protocols.HttpPostClientProtocol");
+                       codeClass.BaseTypes.Add (ctr);
+                       return codeClass;
+               }
+
+               protected override Type GetInMimeFormatter ()
+               {
+                       MimeContentBinding bin = OperationBinding.Input.Extensions.Find (typeof(MimeContentBinding)) as MimeContentBinding;
+                       if (bin == null) throw new Exception ("Http mime:content binding not found");
+                       if (bin.Type != "application/x-www-form-urlencoded") throw new Exception ("Encoding of mime:content binding not supported");
+                       return typeof (HtmlFormParameterWriter);
+               }
+
+               protected override bool IsBindingSupported ()
+               {
+                       HttpBinding bin = (HttpBinding) Binding.Extensions.Find (typeof(HttpBinding));
+                       if (bin == null) return false;
+                       return bin.Verb == "POST";
+               }
+               
+               #endregion
+       }
+}
diff --git a/mcs/class/System.Web.Services/System.Web.Services.Description/HttpSimpleProtocolImporter.cs b/mcs/class/System.Web.Services/System.Web.Services.Description/HttpSimpleProtocolImporter.cs
new file mode 100644 (file)
index 0000000..136a31b
--- /dev/null
@@ -0,0 +1,270 @@
+// 
+// System.Web.Services.Description.HttpSimpleProtocolImporter.cs
+//
+// Author:
+//   Lluis Sanchez Gual (lluis@ximian.com)
+//
+// Copyright (C) 2003 Ximian, Inc.
+//
+
+using System.CodeDom;
+using System.Web.Services;
+using System.Web.Services.Protocols;
+using System.Web.Services.Configuration;
+using System.Xml;
+using System.Xml.Serialization;
+using System.Configuration;
+using System.Collections;
+
+namespace System.Web.Services.Description 
+{
+       public abstract class HttpSimpleProtocolImporter : ProtocolImporter 
+       {
+
+               #region Fields
+
+               HttpBinding httpBinding;
+               
+               SoapCodeExporter soapExporter;
+               SoapSchemaImporter soapImporter;
+               XmlCodeExporter xmlExporter;
+               XmlSchemaImporter xmlImporter;
+               CodeIdentifiers memberIds;
+               
+               #endregion // Fields
+
+               #region Constructors
+
+               public HttpSimpleProtocolImporter ()
+               {
+               }
+               
+               #endregion // Constructors
+
+               #region Methods
+
+               protected override CodeTypeDeclaration BeginClass ()
+               {
+                       httpBinding = (HttpBinding) Binding.Extensions.Find (typeof(HttpBinding));
+
+                       CodeTypeDeclaration codeClass = new CodeTypeDeclaration (ClassName);
+
+                       string location = null;
+                       HttpAddressBinding sab = (HttpAddressBinding) Port.Extensions.Find (typeof(HttpAddressBinding));
+                       if (sab != null) location = sab.Location;
+                       string url = GetServiceUrl (location); 
+                       
+                       CodeConstructor cc = new CodeConstructor ();
+                       cc.Attributes = MemberAttributes.Public;
+                       CodeExpression ce = new CodeFieldReferenceExpression (new CodeThisReferenceExpression(), "Url");
+                       CodeAssignStatement cas = new CodeAssignStatement (ce, new CodePrimitiveExpression (url));
+                       cc.Statements.Add (cas);
+                       codeClass.Members.Add (cc);
+                       
+                       memberIds = new CodeIdentifiers ();
+                       return codeClass;
+               }
+
+               protected override void BeginNamespace ()
+               {
+                       xmlImporter = new XmlSchemaImporter (Schemas);
+                       soapImporter = new SoapSchemaImporter (Schemas);
+                       xmlExporter = new XmlCodeExporter (CodeNamespace, null);
+               }
+
+               protected override void EndClass ()
+               {
+               }
+
+               protected override void EndNamespace ()
+               {
+               }
+
+               protected override bool IsBindingSupported ()
+               {
+                       throw new NotImplementedException ();
+               }
+
+               [MonoTODO]
+               protected override bool IsOperationFlowSupported (OperationFlow flow)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               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);
+                               XmlMembersMapping outputMembers = ImportOutMembersMapping (OutputMessage);
+                               
+                               CodeMemberMethod met = GenerateMethod (memberIds, httpOper, inputMembers, outputMembers);
+                               
+                               xmlExporter.ExportMembersMapping (inputMembers);
+                               xmlExporter.ExportMembersMapping (outputMembers);
+
+                               return met;
+                       }
+                       catch (Exception ex)
+                       {
+                               Console.WriteLine (ex);
+                               UnsupportedOperationBindingWarning (ex.Message);
+                               return null;
+                       }
+               }
+
+               XmlMembersMapping ImportInMembersMapping (Message msg)
+               {
+                       XmlQualifiedName elem = null;
+                       SoapSchemaMember[] mems = new SoapSchemaMember [msg.Parts.Count];
+                       for (int n=0; n<mems.Length; n++)
+                       {
+                               SoapSchemaMember mem = new SoapSchemaMember();
+                               mem.MemberName = msg.Parts[n].Name;
+                               mem.MemberType = msg.Parts[n].Type;
+                               mems[n] = mem;
+                       }
+                       return soapImporter.ImportMembersMapping (Operation.Name, "", mems);
+               }
+               
+               XmlMembersMapping ImportOutMembersMapping (Message msg)
+               {
+                       XmlQualifiedName[] pnames = new XmlQualifiedName [msg.Parts.Count];
+                       for (int n=0; n<pnames.Length; n++)
+                               pnames[n] = msg.Parts[n].Element;
+                       return xmlImporter.ImportMembersMapping (pnames);
+               }
+               
+               CodeMemberMethod GenerateMethod (CodeIdentifiers memberIds, HttpOperationBinding httpOper, XmlMembersMapping inputMembers, XmlMembersMapping outputMembers)
+               {
+                       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]);
+
+                       for (int n=0; n<outputMembers.Count; n++)
+                               pids.AddUnique (outputMembers[n].MemberName, outputMembers[n]);
+                               
+                       string varAsyncResult = pids.AddUnique ("asyncResult","asyncResult");
+                       string varResults = pids.AddUnique ("results","results");
+                       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" + memberIds.MakeRightCase(Operation.Name)),method);
+                       methodEnd.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("End" + memberIds.MakeRightCase(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];
+                       CodeParameterDeclarationExpression[] outParams = new CodeParameterDeclarationExpression [outputMembers.Count];
+
+                       for (int n=0; n<inputMembers.Count; n++)
+                       {
+                               CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (inputMembers[n].TypeFullName, 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 (outputMembers.Count == 1)
+                       {
+                               method.ReturnType = new CodeTypeReference (outputMembers[0].TypeFullName);
+                               methodEnd.ReturnType = new CodeTypeReference (outputMembers[0].TypeFullName);
+                               xmlExporter.AddMappingMetadata (method.ReturnTypeCustomAttributes, outputMembers[0], outputMembers.Namespace, (outputMembers[0].ElementName != method.Name + "Result"));
+                               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 virtual Type GetInMimeFormatter ()
+               {
+                       return null;
+               }
+
+               protected virtual Type GetOutMimeFormatter ()
+               {
+                       MimeXmlBinding bin = OperationBinding.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
+                       if (bin == null) return typeof(NopReturnReader);
+                       return typeof (XmlReturnReader);
+               }
+
+               #endregion
+       }
+}
index 1749a28381a7b5172269ba371296ff0d676ca769..13dd673d5d1c701b580f7c938f100577cc4364f0 100644 (file)
@@ -145,45 +145,35 @@ namespace System.Web.Services.Description {
 
                #region Methods
                
-               internal void Import (ServiceDescriptionImporter descriptionImporter, CodeNamespace codeNamespace, CodeCompileUnit codeCompileUnit, ArrayList importInfo)
+               internal bool Import (ServiceDescriptionImporter descriptionImporter, CodeNamespace codeNamespace, CodeCompileUnit codeCompileUnit, ImportInfo info, Service service, Port port, CodeIdentifiers classNames)
                {
                        this.descriptionImporter = descriptionImporter;
+                       this.service = service;
+                       this.iinfo = info;
+                       this.port = port;
+                       binding = ServiceDescriptions.GetBinding (port.Binding);
+                       
+                       if (!IsBindingSupported ()) return false;
+                       
+                       this.classNames = classNames;
                        warnings = (ServiceDescriptionImportWarnings) 0;
                        
                        this.codeNamespace = codeNamespace;
                        this.codeCompileUnit = codeCompileUnit;
 
-                       bool classesGenerated = false;
-                       classNames = new CodeIdentifiers();
-                       
                        BeginNamespace ();
-                       
-                       foreach (ImportInfo info in importInfo)
-                       {
-                               iinfo = info;
-                               foreach (Service s in info.ServiceDescription.Services)
-                               {
-                                       service = s;
-                                       foreach (Port p in service.Ports)
-                                       {
-                                               port = p;
-                                               classesGenerated = ImportPortBinding () || classesGenerated;
-                                       }
-                               }
-                       }
-                       
+                       ImportPortBinding ();
                        EndNamespace ();
                        
-                       if (!classesGenerated) warnings |= ServiceDescriptionImportWarnings.NoCodeGenerated;
+                       return true;
                }
 
-               bool ImportPortBinding ()
+               void ImportPortBinding ()
                {
                        if (service.Ports.Count > 1) className = port.Name;
                        else className = service.Name;
                        
                        className = classNames.AddUnique (CodeIdentifier.MakeValid (className), port);
-                       binding = ServiceDescriptions.GetBinding (port.Binding);
                        
                        try
                        {
@@ -205,14 +195,9 @@ namespace System.Web.Services.Description {
                                att.Arguments.Add (GetArg ("code"));
                                AddCustomAttribute (codeClass, att, true);
 
-                               att = new CodeAttributeDeclaration ("System.Web.Services.WebServiceBinding");
-                               att.Arguments.Add (GetArg ("Name", port.Name));
-                               att.Arguments.Add (GetArg ("Namespace", port.Binding.Namespace));
-                               AddCustomAttribute (codeClass, att, true);
-       
                                if (binding.Operations.Count == 0) {
                                        warnings |= ServiceDescriptionImportWarnings.NoMethodsGenerated;
-                                       return true;
+                                       return;
                                }
                                
                                foreach (OperationBinding oper in binding.Operations) 
@@ -233,20 +218,22 @@ namespace System.Web.Services.Description {
                                        }
                                        
                                        CodeMemberMethod method = GenerateMethod ();
-                                       methodName = method.Name;
                                        
-                                       if (operation.Documentation != null && operation.Documentation != "")
-                                               AddComments (method, operation.Documentation);
+                                       if (method != null)
+                                       {
+                                               methodName = method.Name;
+                                               if (operation.Documentation != null && operation.Documentation != "")
+                                                       AddComments (method, operation.Documentation);
+                                       }
                                }
                                
                                EndClass ();
                        }
                        catch (Exception ex)
                        {
+                               warnings |= ServiceDescriptionImportWarnings.NoCodeGenerated;
                                UnsupportedBindingWarning (ex.Message);
-                               return false;
                        }
-                       return true;
                }
 
                Operation FindPortOperation ()
@@ -277,6 +264,22 @@ namespace System.Web.Services.Description {
                        else return msg.Name;
                }
                
+               internal string GetServiceUrl (string location)
+               {
+                       if (ImportInfo.AppSettingUrlKey == null || ImportInfo.AppSettingUrlKey == string.Empty)
+                               return location;
+                       else
+                       {
+                               string url;
+                               if (Style == ServiceDescriptionImportStyle.Server) throw new InvalidOperationException ("Cannot set appSettingUrlKey if Style is Server");
+                               url = ConfigurationSettings.AppSettings [ImportInfo.AppSettingUrlKey];
+                               if (ImportInfo.AppSettingBaseUrl != null && ImportInfo.AppSettingBaseUrl != string.Empty)
+                                       url += "/" + ImportInfo.AppSettingBaseUrl + "/" + location;
+                               return url;
+                       }
+               }
+
+               
                [MonoTODO]
                public void AddExtensionWarningComments (CodeCommentStatementCollection comments, ServiceDescriptionFormatExtensionCollection extensions) 
                {
index 0708d88683127f75ac46ede1cccd028af81011a9..bef325eae3d0d1b2a33d6b111119e8efb499d456 100644 (file)
@@ -87,20 +87,46 @@ namespace System.Web.Services.Description {
 \r
                public ServiceDescriptionImportWarnings Import (CodeNamespace codeNamespace, CodeCompileUnit codeCompileUnit)\r
                {\r
+                       ServiceDescriptionImportWarnings warns = 0;\r
+                       CodeIdentifiers classNames = new CodeIdentifiers();\r
                        ProtocolImporter importer = GetImporter ();\r
-                       importer.Import (this, codeNamespace, codeCompileUnit, importInfo);\r
+                       bool found = false;\r
                        \r
-                       return importer.Warnings;\r
+                       foreach (ImportInfo info in importInfo)\r
+                               foreach (Service service in info.ServiceDescription.Services)\r
+                                       foreach (Port port in service.Ports)\r
+                                       {\r
+                                               if (importer.Import (this, codeNamespace, codeCompileUnit, info, service, port, classNames)) {\r
+                                                       found = true;\r
+                                                       warns |= importer.Warnings;\r
+                                               }\r
+                                       }\r
+                               \r
+                       if (!found) throw new Exception ("None of the supported bindings was found");\r
+                       return warns;\r
                }\r
                \r
                ProtocolImporter GetImporter ()\r
                {\r
-                       switch ((protocolName != null && protocolName != "") ? protocolName : "Soap")\r
-                       {\r
-                               case "Soap": return new SoapProtocolImporter ();\r
-                               default: throw new NotSupportedException ();\r
+                       ArrayList importers = GetSupportedImporters ();\r
+                       if (protocolName == null || protocolName == "") protocolName = "Soap";\r
+                       foreach (ProtocolImporter importer in importers) {\r
+                               if (importer.ProtocolName == protocolName)\r
+                                       return importer;\r
                        }\r
+                       \r
+                       throw new Exception ("Protocol " + protocolName + " not supported");\r
                }\r
+               \r
+               ArrayList GetSupportedImporters ()\r
+               {\r
+                       ArrayList list = new ArrayList ();\r
+                       list.Add (new SoapProtocolImporter ());\r
+                       list.Add (new HttpGetProtocolImporter ());\r
+                       list.Add (new HttpPostProtocolImporter ());\r
+                       return list;\r
+               }\r
+               \r
 #endregion\r
        }\r
 \r
index dff7694e22495162883c43d186d452fbd1c00b71..f421d0ce1dc59d3e9d5bfba3dba968bb013c8914 100644 (file)
@@ -80,17 +80,23 @@ namespace System.Web.Services.Description {
                protected override CodeTypeDeclaration BeginClass ()
                {
                        soapBinding = (SoapBinding) Binding.Extensions.Find (typeof(SoapBinding));
-
-                       if (soapBinding == null) throw new Exception ("None of the supported bindings was found");
                        if (soapBinding.Style != SoapBindingStyle.Document) throw new Exception ("Binding style not supported");
                        
                        CodeTypeDeclaration codeClass = new CodeTypeDeclaration (ClassName);
                        
-                       string url = GetServiceUrl (); 
+                       string location = null;                 
+                       SoapAddressBinding sab = (SoapAddressBinding) Port.Extensions.Find (typeof(SoapAddressBinding));
+                       if (sab != null) location = sab.Location;
+                       string url = GetServiceUrl (location); 
 
                        CodeTypeReference ctr = new CodeTypeReference ("System.Web.Services.Protocols.SoapHttpClientProtocol");
                        codeClass.BaseTypes.Add (ctr);
                        
+                       CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.WebServiceBinding");
+                       att.Arguments.Add (GetArg ("Name", Port.Name));
+                       att.Arguments.Add (GetArg ("Namespace", Port.Binding.Namespace));
+                       AddCustomAttribute (codeClass, att, true);
+       
                        CodeConstructor cc = new CodeConstructor ();
                        cc.Attributes = MemberAttributes.Public;
                        CodeExpression ce = new CodeFieldReferenceExpression (new CodeThisReferenceExpression(), "Url");
@@ -103,26 +109,6 @@ namespace System.Web.Services.Description {
                        return codeClass;
                }
 
-               string GetServiceUrl ()
-               {
-                       string location = null;
-                       
-                       SoapAddressBinding sab = (SoapAddressBinding) Port.Extensions.Find (typeof(SoapAddressBinding));
-                       if (sab != null) location = sab.Location;
-                       
-                       if (ImportInfo.AppSettingUrlKey == null || ImportInfo.AppSettingUrlKey == string.Empty)
-                               return location;
-                       else
-                       {
-                               string url;
-                               if (Style == ServiceDescriptionImportStyle.Server) throw new InvalidOperationException ("Cannot set appSettingUrlKey if Style is Server");
-                               url = ConfigurationSettings.AppSettings [ImportInfo.AppSettingUrlKey];
-                               if (ImportInfo.AppSettingBaseUrl != null && ImportInfo.AppSettingBaseUrl != string.Empty)
-                                       url += "/" + ImportInfo.AppSettingBaseUrl + "/" + location;
-                               return url;
-                       }
-               }
-
                protected override void BeginNamespace ()
                {
                        xmlImporter = new XmlSchemaImporter (Schemas);
@@ -142,10 +128,9 @@ namespace System.Web.Services.Description {
                {
                }
 
-               [MonoTODO]
                protected override bool IsBindingSupported ()
                {
-                       throw new NotImplementedException ();
+                       return Binding.Extensions.Find (typeof(SoapBinding)) != null;
                }
 
                [MonoTODO]
@@ -154,31 +139,25 @@ namespace System.Web.Services.Description {
                        throw new NotImplementedException ();
                }
 
-               void AddComments (CodeTypeMember member, string comments)
-               {
-                       if (comments == null || comments == "") member.Comments.Add (new CodeCommentStatement ("<remarks/>", true));
-                       else member.Comments.Add (new CodeCommentStatement ("<remarks>\n" + comments + "\n</remarks>", true));
-               }
-
                protected override CodeMemberMethod GenerateMethod ()
                {
                        try
                        {
                                SoapOperationBinding soapOper = OperationBinding.Extensions.Find (typeof (SoapOperationBinding)) as SoapOperationBinding;
-                               if (soapOper == null) throw new Exception ("Soap operation binding not found in operation " + OperationBinding.Name);
-                               if (soapOper.Style != SoapBindingStyle.Document) throw new Exception ("Operation binding style not supported in operation " + OperationBinding.Name);
+                               if (soapOper == null) throw new Exception ("Soap operation binding not found");
+                               if (soapOper.Style != SoapBindingStyle.Document) throw new Exception ("Operation binding style not supported");
 
                                SoapBodyBinding isbb = OperationBinding.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
-                               if (isbb == null) throw new Exception ("Soap body binding not found in operation " + OperationBinding.Name);
+                               if (isbb == null) throw new Exception ("Soap body binding not found");
                                
                                SoapBodyBinding osbb = OperationBinding.Output.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
-                               if (osbb == null) throw new Exception ("Soap body binding not found in operation " + OperationBinding.Name);
+                               if (osbb == null) throw new Exception ("Soap body binding not found");
                                
                                XmlMembersMapping inputMembers = ImportMembersMapping (InputMessage, isbb, soapOper);
-                               if (inputMembers == null) throw new Exception ("Input message not declared in operation " + OperationBinding.Name);
+                               if (inputMembers == null) throw new Exception ("Input message not declared");
 
                                XmlMembersMapping outputMembers = ImportMembersMapping (OutputMessage, osbb, soapOper);
-                               if (outputMembers == null) throw new Exception ("Output message not declared in operation " + OperationBinding.Name);
+                               if (outputMembers == null) throw new Exception ("Output message not declared");
                                
                                CodeMemberMethod met = GenerateMethod (memberIds, soapOper, isbb, inputMembers, outputMembers);