+2010-02-19 Atsushi Enomoto <atsushi@ximian.com>
+
+ * ServiceContractGenerator.cs, MessagePartDescription.cs,
+ DataContractSerializerMessageContractImporter.cs :
+ add alternative implementation to use XsdDataContractImporter
+ instead of XmlSchemaImporter hack.
+
+ It requires -d:USE_DATA_CONTRACT_IMPORTER and not enabled yet, as
+ it breaks some WSDL imports (such as memorabilia.hardrock.com).
+
2010-02-11 Atsushi Enomoto <atsushi@ximian.com>
* DataContractSerializerMessageContractImporter.cs : handle duration
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Web.Services.Description;
if (this.importer != null || this.context != null)
throw new SystemException ("INTERNAL ERROR: unexpected recursion of ImportContract method call");
+#if USE_DATA_CONTRACT_IMPORTER
+ dc_importer = new XsdDataContractImporter ();
+ dc_importer.Import (importer.XmlSchemas);
+#endif
+
this.importer = importer;
this.context = context;
try {
WsdlImporter importer;
WsdlContractConversionContext context;
+
+ XsdDataContractImporter dc_importer;
+
+#if !USE_DATA_CONTRACT_IMPORTER
XmlSchemaImporter schema_importer_;
XmlSchemaImporter schema_importer {
get {
return xml_schemas_;
}
}
+#endif
void DoImportContract ()
{
}
}
+#if USE_DATA_CONTRACT_IMPORTER
void resolveElement (QName qname, List<MessagePartDescription> parts, string ns)
{
- XmlSchemaElement element = (XmlSchemaElement) xml_schemas.Find (qname, typeof (XmlSchemaElement));
+ XmlSchemaElement element = (XmlSchemaElement) importer.XmlSchemas.GlobalElements [qname];
if (element == null)
//FIXME: What to do here?
throw new Exception ("Could not resolve : " + qname.ToString ());
+ var msg_part = new MessagePartDescription (qname.Name, qname.Namespace);
+ msg_part.Importer = dc_importer;
+ msg_part.CodeTypeReference = dc_importer.GetCodeTypeReference (dc_importer.Import (importer.XmlSchemas, element));
+ parts.Add (msg_part);
+ }
+#else
+ void resolveElement (QName qname, List<MessagePartDescription> parts, string ns)
+ {
+ XmlSchemaElement element = (XmlSchemaElement) xml_schemas.Find (qname, typeof (XmlSchemaElement));
+ if (element == null)
+ //FIXME: What to do here?
+ throw new Exception ("Could not resolve : " + qname.ToString ());
resolveParticle (schema_importer, element, parts, ns, 2);
}
+#endif
void resolveType (QName qname, List<MessagePartDescription> parts, string ns)
{
return null;
}
+#if !USE_DATA_CONTRACT_IMPORTER
void resolveParticle (XmlSchemaImporter schema_importer,
XmlSchemaParticle particle,
List<MessagePartDescription> parts,
parts.Add (msg_part);
}
+#endif
void IWsdlImportExtension.ImportEndpoint (WsdlImporter importer,
WsdlEndpointConversionContext context)
set { type = value; }
}
+#if !NET_2_1
+#if USE_DATA_CONTRACT_IMPORTER
+ internal XsdDataContractImporter Importer { get; set; }
+ internal System.CodeDom.CodeTypeReference CodeTypeReference { get; set; }
+#else
internal XmlQualifiedName TypeName {
get { return xml_schema_type_name; }
set { xml_schema_type_name = value; }
get { return xml_type_mapping; }
set { xml_type_mapping = value; }
}
-
+#endif
+#endif
}
}
ServiceContractGenerationContext contract_context;
List<OPair> operation_contexts = new List<OPair> ();
+ XsdDataContractImporter xsd_data_importer;
+
public ServiceContractGenerator ()
: this (null, null)
{
if ((Options & ServiceContractGenerationOptions.ClientClass) != 0)
GenerateProxyClass (contractDescription, cns);
+ if (xsd_data_importer != null)
+ MergeCompileUnit (xsd_data_importer.CodeCompileUnit, ccu);
+
// Process extensions. Class first, then methods.
// (built-in ones must present before processing class extensions).
foreach (var cb in contractDescription.Behaviors) {
foreach (MessageDescription md in messages) {
if (md.Direction == MessageDirection.Output) {
if (md.Body.ReturnValue != null) {
- ExportDataContract (md.Body.ReturnValue.XmlTypeMapping);
+ ExportDataContract (md.Body.ReturnValue);
+#if USE_DATA_CONTRACT_IMPORTER
+ method.ReturnType = md.Body.ReturnValue.CodeTypeReference;
+#else
method.ReturnType = new CodeTypeReference (GetCodeTypeName (md.Body.ReturnValue.TypeName));
+#endif
}
continue;
}
MessagePartDescriptionCollection parts = md.Body.Parts;
for (int i = 0; i < parts.Count; i++) {
- ExportDataContract (parts [i].XmlTypeMapping);
+ ExportDataContract (parts [i]);
method.Parameters.Add (
new CodeParameterDeclarationExpression (
+#if USE_DATA_CONTRACT_IMPORTER
+ parts [i].CodeTypeReference,
+#else
new CodeTypeReference (GetCodeTypeName (parts [i].TypeName)),
+#endif
parts [i].Name));
if (return_args)
throw new NotImplementedException ();
}
- private void ExportDataContract (XmlTypeMapping mapping)
+#if USE_DATA_CONTRACT_IMPORTER
+ void MergeCompileUnit (CodeCompileUnit from, CodeCompileUnit to)
+ {
+ foreach (CodeNamespace fns in from.Namespaces) {
+ foreach (CodeNamespace tns in to.Namespaces)
+ if (fns.Name == tns.Name) {
+ // namespaces are merged.
+ MergeNamespace (fns, tns);
+ continue;
+ }
+ to.Namespaces.Add (fns);
+ }
+ }
+
+ // existing type is skipped.
+ void MergeNamespace (CodeNamespace from, CodeNamespace to)
{
+ foreach (CodeTypeDeclaration ftd in from.Types) {
+ bool skip = false;
+ foreach (CodeTypeDeclaration ttd in to.Types)
+ if (ftd.Name == ttd.Name) {
+ skip = true;
+ break;
+ }
+ if (!skip)
+ to.Types.Add (ftd);
+ }
+ }
+#endif
+
+ private void ExportDataContract (MessagePartDescription md)
+ {
+#if USE_DATA_CONTRACT_IMPORTER
+ if (xsd_data_importer == null)
+ xsd_data_importer = md.Importer;
+#else
+ var mapping = md.XmlTypeMapping;
+
if (mapping == null)
return;
cns.Types.Remove (type);
ccu.Namespaces.Add (cns);
+#endif
}
private string GetXmlNamespace (CodeTypeDeclaration type)