Fix wsdl import wrt element qname (!= type name).
authorAtsushi Eno <atsushi@ximian.com>
Thu, 28 Jul 2011 04:03:31 +0000 (21:03 -0700)
committerAtsushi Eno <atsushi@ximian.com>
Thu, 28 Jul 2011 04:03:31 +0000 (21:03 -0700)
mcs/class/System.Runtime.Serialization/Test/System.Runtime.Serialization/XsdDataContractImporterTest.cs
mcs/class/System.ServiceModel/System.ServiceModel.Description/DataContractSerializerMessageContractImporter.cs
mcs/class/System.ServiceModel/System.ServiceModel/ClientRuntimeChannel.cs

index 917c827aca89c7443b083ef9557d181e095316ed..e0aed6824dc7f19cc5cde6e47b48cfe216f6769d 100644 (file)
@@ -422,6 +422,16 @@ namespace MonoTests.System.Runtime.Serialization
                        return ccu;
                }
 
+               void DoCanImport (bool result, params string [] schemaFiles)
+               {
+                       var ccu = new CodeCompileUnit ();
+                       var xdi = new XsdDataContractImporter (ccu);
+                       var xss = new XmlSchemaSet ();
+                       foreach (var schemaFile in schemaFiles)
+                               xss.Add (null, schemaFile);
+                       Assert.AreEqual (result, xdi.CanImport (xss));
+               }
+
                string GenerateCode (CodeCompileUnit ccu)
                {
                        var sw = new StringWriter ();
@@ -690,6 +700,12 @@ namespace MonoTests.System.Runtime.Serialization
                        DoImport (true, "Test/Resources/Schemas/ns34.xsd", "Test/Resources/Schemas/ns34_2.xsd");
                }
 
+               [Test]
+               public void CanImportTestX34 ()
+               {
+                       DoCanImport (false, "Test/Resources/Schemas/ns34.xsd", "Test/Resources/Schemas/ns34_2.xsd");
+               }
+
                /* Helper methods */
                private void CheckDC (CodeTypeDeclaration type, string name, Dictionary<string, string> members, string msg)
                {
index bc5610647f7a593215723b1e14f687e9c5bad4df..5b4b839bbc8525cb9681ff2d8c3f41e521564e47 100644 (file)
@@ -116,7 +116,7 @@ namespace System.ServiceModel.Description
                        }
                }
 
-               WsdlImporter importer;
+               internal WsdlImporter importer;
                WsdlContractConversionContext context;
 
                internal XmlSchemaSet schema_set_in_use;
@@ -207,7 +207,8 @@ namespace System.ServiceModel.Description
                                                ResolveType (part.Type, parts, body.WrapperNamespace);
                                        }
                                }
-                               //FIXME: non-parameters?
+                               else
+                                       throw new InvalidOperationException ("Only 'parameters' element in message part is supported"); // this should have been rejected by CanImportOperation().
                        }
                }
 
@@ -233,8 +234,7 @@ namespace System.ServiceModel.Description
                {
                        XmlSchemaElement element = (XmlSchemaElement) schema_set_in_use.GlobalElements [qname];
                        if (element == null)
-                               //FIXME: What to do here?
-                               throw new Exception ("Could not resolve : " + qname.ToString ());
+                               throw new InvalidOperationException ("Could not resolve : " + qname.ToString ()); // this should have been rejected by CanImportOperation().
 
                        var ct = element.ElementSchemaType as XmlSchemaComplexType;
                        if (ct == null) // simple type
@@ -263,7 +263,7 @@ namespace System.ServiceModel.Description
                        part.DataContractImporter = dc_importer;
                        if (dc_importer.CanImport (schema_set_in_use, elem)) {
                                var typeQName = dc_importer.Import (schema_set_in_use, elem);
-                               part.CodeTypeReference = dc_importer.GetCodeTypeReference (typeQName);
+                               part.CodeTypeReference = dc_importer.GetCodeTypeReference (elem.ElementSchemaType.QualifiedName, elem);
                        }
                        return part;
                }
@@ -279,11 +279,32 @@ namespace System.ServiceModel.Description
                        throw new NotImplementedException ();
                }
 
+               Message FindMessage (OperationMessage om)
+               {
+                       foreach (WSDL sd in importer.WsdlDocuments)
+                               if (sd.TargetNamespace == om.Message.Namespace)
+                                       foreach (Message msg in sd.Messages)
+                                               if (msg.Name == om.Message.Name)
+                                                       return msg;
+                       return null;
+               }
+
                protected override bool CanImportOperation (PortType portType, Operation op)
                {
-                       foreach (OperationMessage om in op.Messages)
-                               if (!dc_importer.CanImport (schema_set_in_use, om.Message))
+                       foreach (OperationMessage om in op.Messages) {
+                               var msg = FindMessage (om);
+                               if (msg == null)
                                        return false;
+                               foreach (MessagePart part in msg.Parts) {
+                                       if (part.Name == "parameters" && !part.Element.IsEmpty) {
+                                               var xe = schema_set_in_use.GlobalElements [part.Element] as XmlSchemaElement;
+                                               if (xe == null || !dc_importer.CanImport (schema_set_in_use, xe))
+                                                       return false;
+                                       }
+                                       else
+                                               return false;
+                               }
+                       }
                        return true;
                }
                
@@ -326,7 +347,6 @@ namespace System.ServiceModel.Description
                        // FIXME: use of ElementName is a hack!
                        part.CodeTypeReference = new CodeTypeReference (xmm.ElementName);
                        parts.Add (part);
-                       Console.Error.WriteLine ("CodeNamespace {1} in CCU {2} now contains {0} types.", ccu.Namespaces [0].Types.Count, ccu.Namespaces [0].GetHashCode (), ccu.GetHashCode ());
                }
 
                protected override void ResolveType (QName qname, List<MessagePartDescription> parts, string ns)
index 97d603be14e3e2681f6563ca25835c6f2c9367a3..4a309048bfcf9c783fae5e8dbb383658e4ad3089 100644 (file)
@@ -93,6 +93,8 @@ namespace System.ServiceModel.MonoInternal
                {
                        if (runtime == null)
                                throw new ArgumentNullException ("runtime");
+                       if (messageVersion == null)
+                               throw new ArgumentNullException ("messageVersion");
                        this.runtime = runtime;
                        this.remote_address = remoteAddress;
                        if (runtime.Via == null)
@@ -418,6 +420,8 @@ namespace System.ServiceModel.MonoInternal
 
                public T GetProperty<T> () where T : class
                {
+                       if (typeof (T) == typeof (MessageVersion))
+                               return (T) (object) message_version;
                        return OperationChannel.GetProperty<T> ();
                }