2006-12-12 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Description / ProtocolImporter.cs
index a093cc4155a069779d7401fadd2e9bf125b0ab50..c6420a15569c4bfa674bcd1f1980be4fd10932d2 100644 (file)
@@ -185,7 +185,7 @@ namespace System.Web.Services.Description {
                        get { return descriptionImporter.CodeGenerationOptions; }
                }
                
-               internal ICodeGenerator CodeGenerator {
+               internal CodeDomProvider CodeGenerator {
                        get { return descriptionImporter.CodeGenerator; }
                }
 
@@ -309,7 +309,11 @@ namespace System.Web.Services.Description {
                                {
                                        operationBinding = oper;
                                        operation = FindPortOperation ();
-                                       if (operation == null) throw new Exception ("Operation " + operationBinding.Name + " not found in portType " + PortType.Name);
+                                       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)
                                        {
@@ -390,21 +394,42 @@ namespace System.Web.Services.Description {
                        else return msg.Name;
                }
                
-               internal string GetServiceUrl (string location)
+               internal void GenerateServiceUrl (string location, CodeStatementCollection stms)
                {
-                       if (ImportInfo.AppSettingUrlKey == null || ImportInfo.AppSettingUrlKey == string.Empty)
-                               return location;
+                       if (ImportInfo.AppSettingUrlKey == null || ImportInfo.AppSettingUrlKey == string.Empty) {
+                               if (location != null) {
+                                       CodeExpression ce = new CodeFieldReferenceExpression (new CodeThisReferenceExpression(), "Url");
+                                       CodeAssignStatement cas = new CodeAssignStatement (ce, new CodePrimitiveExpression (location));
+                                       stms.Add (cas);
+                               }
+                       }
                        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;
+                               CodeExpression prop = new CodePropertyReferenceExpression (new CodeTypeReferenceExpression ("System.Configuration.ConfigurationSettings"), "AppSettings");
+                               prop = new CodeIndexerExpression (prop, new CodePrimitiveExpression (ImportInfo.AppSettingUrlKey));
+                               stms.Add (new CodeVariableDeclarationStatement (typeof(string), "urlSetting", prop));
+                               
+                               CodeExpression urlSetting = new CodeVariableReferenceExpression ("urlSetting");
+                               CodeExpression thisUrl = new CodeFieldReferenceExpression (new CodeThisReferenceExpression(), "Url");
+                               
+                               CodeStatement[] trueStms = new CodeStatement [1];
+                               CodeExpression ce = urlSetting;
+                               CodeExpression cond = new CodeBinaryOperatorExpression (urlSetting, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression (null));
+                               
+                               if (ImportInfo.AppSettingBaseUrl != null)
+                                       ce = new CodeMethodInvokeExpression (new CodeTypeReferenceExpression (typeof(string)), "Concat", ce, new CodePrimitiveExpression (ImportInfo.AppSettingBaseUrl));
+                               trueStms [0] = new CodeAssignStatement (thisUrl, ce);
+                               
+                               if (location != null) {
+                                       CodeStatement[] falseStms = new CodeStatement [1];
+                                       falseStms [0] = new CodeAssignStatement (thisUrl, new CodePrimitiveExpression (location));
+                                       stms.Add (new CodeConditionStatement (cond, trueStms, falseStms));
+                               }
+                               else
+                                       stms.Add (new CodeConditionStatement (cond, trueStms));
                        }
                }
-
+               
                void ClasifySchemas (ArrayList importInfo)
                {
                        // I don't like this, but I could not find any other way of clasifying
@@ -520,7 +545,7 @@ namespace System.Web.Services.Description {
                        foreach (XmlSchemaObject ob in sc.Includes)
                        {
                                XmlSchemaImport import = ob as XmlSchemaImport;
-                               if (import.Namespace == SoapProtocolReflector.EncodingNamespace) return true;
+                               if (import != null && import.Namespace == SoapProtocolReflector.EncodingNamespace) return true;
                        }
                        return false;
                }