File: MetadataFile.cs

package info (click to toggle)
mono 4.6.2.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 778,148 kB
  • ctags: 914,052
  • sloc: cs: 5,779,509; xml: 2,773,713; ansic: 432,645; sh: 14,749; makefile: 12,361; perl: 2,488; python: 1,434; cpp: 849; asm: 531; sql: 95; sed: 16; php: 1
file content (884 lines) | stat: -rw-r--r-- 27,380 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
#region Copyright (c) Microsoft Corporation
/// <copyright company='Microsoft Corporation'>
///    Copyright (c) Microsoft Corporation. All Rights Reserved.
///    Information Contained Herein is Proprietary and Confidential.
/// </copyright>
#endregion

using System;
using System.Diagnostics;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using Discovery = System.Web.Services.Discovery;
using Description = System.Web.Services.Description;
using MetadataSection = System.ServiceModel.Description.MetadataSection;
using XmlSerialization = System.Xml.Serialization;

#if WEB_EXTENSIONS_CODE
using System.Web.Resources;
#else
using Microsoft.VSDesigner.WCF.Resources;
#endif

#if WEB_EXTENSIONS_CODE
namespace System.Web.Compilation.WCFModel
#else
namespace Microsoft.VSDesigner.WCFModel
#endif
{
    /// <summary>
    /// This class presents a single metadata file in the ReferenceGroup
    /// </summary>
    /// <remarks></remarks>
#if WEB_EXTENSIONS_CODE
    internal class MetadataFile : ExternalFile
#else
    [CLSCompliant(true)]
    public class MetadataFile : ExternalFile
#endif
    {

        // Default File Name
        public const string DEFAULT_FILE_NAME = "service";

        private MetadataType m_MetadataType;
        private string m_SourceUrl;

        // A GUID string
        private string m_ID;

        private int m_SourceId;

        // properties to merge metadata
        private bool m_Ignore;
        private bool m_IsMergeResult;

        private int SOURCE_ID_NOT_SPECIFIED = 0;

        private MetadataContent m_CachedMetadata;

        // Content of the metadata file, one of them must be
        private byte[] m_BinaryContent;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <remarks> Must support a default construct for XmlSerializer</remarks>
        public MetadataFile()
        {
            m_ID = Guid.NewGuid().ToString();
            m_BinaryContent = new byte[] { };
        }


        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="Name">File Name</param>
        /// <param name="Url">SourceUrl</param>
        /// <param name="Content">File Content</param>
        /// <remarks></remarks>
        public MetadataFile(string name, string url, string content)
            : base(name)
        {
            m_ID = Guid.NewGuid().ToString();

            m_SourceUrl = url;

            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            LoadContent(content);
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="Name">File Name</param>
        /// <param name="Url">SourceUrl</param>
        /// <param name="byteContent">File Content</param>
        /// <remarks></remarks>
        public MetadataFile(string name, string url, byte[] byteContent)
            : base(name)
        {
            m_ID = Guid.NewGuid().ToString();

            m_SourceUrl = url;

            if (byteContent == null)
            {
                throw new ArgumentNullException("byteContent");
            }

            LoadContent(byteContent);
        }

        /// <summary>
        /// Retrieves the file content in binary format
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        public byte[] BinaryContent
        {
            get
            {
                return m_BinaryContent;
            }
        }

        /// <summary>
        /// Cached state
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        private MetadataContent CachedMetadata
        {
            get
            {
                if (m_CachedMetadata == null)
                {
                    m_CachedMetadata = LoadMetadataContent(m_MetadataType);
                }
                return m_CachedMetadata;
            }
        }


        /// <summary>
        /// Retrieves the file content
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        public string Content
        {
            get
            {
                StreamReader memReader = new StreamReader(new MemoryStream(m_BinaryContent));
                return memReader.ReadToEnd();
            }
        }

        /// <summary>
        /// The Type of Metadata
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        [XmlSerialization.XmlAttribute("MetadataType")]
        public MetadataType FileType
        {
            get
            {
                return m_MetadataType;
            }
            set
            {
                m_MetadataType = value;
            }
        }

        /// <summary>
        ///  GUID string, it is used to track a metadata item (when it is updated)
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        [XmlSerialization.XmlAttribute()]
        public string ID
        {
            get
            {
                return m_ID;
            }
            set
            {
                m_ID = value;
            }
        }

        /// <summary>
        /// If it is true, the metadata file will be ignored by the code generator
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        [XmlSerialization.XmlAttribute()]
        public bool Ignore
        {
            get
            {
                return m_Ignore;
            }
            set
            {
                m_Ignore = value;
            }
        }

        /// <summary>
        /// A special attribute used by XmlSerializer to decide whether Ignore attribute exists
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        [XmlSerialization.XmlIgnore()]
        public bool IgnoreSpecified
        {
            get
            {
                return m_Ignore;
            }
            set
            {
                if (!value)
                {
                    m_Ignore = false;
                }
            }
        }

        /// <summary>
        /// whether the metadata file is a result of merging
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        [XmlSerialization.XmlAttribute()]
        public bool IsMergeResult
        {
            get
            {
                return m_IsMergeResult;
            }
            set
            {
                m_IsMergeResult = value;
            }
        }

        /// <summary>
        /// A special attribute used by XmlSerializer to decide whether IsMergeResult attribute exists
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        [XmlSerialization.XmlIgnore()]
        public bool IsMergeResultSpecified
        {
            get
            {
                return m_IsMergeResult;
            }
            set
            {
                if (!value)
                {
                    m_IsMergeResult = false;
                }
            }
        }

        /// <summary>
        /// Retrieves the content of a discovery file
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        public Discovery.DiscoveryDocument MetadataDiscoveryDocument
        {
            get
            {
                return CachedMetadata.MetadataDiscoveryDocument;
            }
        }

        /// <summary>
        /// format error
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        [XmlSerialization.XmlIgnore()]
        public Exception MetadataFormatError
        {
            get
            {
                return CachedMetadata.MetadataFormatError;
            }
        }

        /// <summary>
        /// Retrieves the content of a WSDL file
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        public Description.ServiceDescription MetadataServiceDescription
        {
            get
            {
                return CachedMetadata.MetadataServiceDescription;
            }
        }

        /// <summary>
        /// Retrieves the content of a schema file
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        public XmlSchema MetadataXmlSchema
        {
            get
            {
                return CachedMetadata.MetadataXmlSchema;
            }
        }

        /// <summary>
        /// Retrieves the content of an Xml file
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        public XmlDocument MetadataXmlDocument
        {
            get
            {
                return CachedMetadata.MetadataXmlDocument;
            }
        }

        /// <summary>
        /// the SourceId links the the SourceId in the MetadataSource table
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        [XmlSerialization.XmlAttribute()]
        public int SourceId
        {
            get
            {
                return m_SourceId;
            }
            set
            {
                if (value < 0)
                {
                    Debug.Fail("Source ID shouldn't be a nagtive number");
                    throw new ArgumentException(WCFModelStrings.ReferenceGroup_InvalidSourceId);
                }
                m_SourceId = value;
            }
        }

        /// <summary>
        /// A special attribute used by XmlSerializer to decide whether SourceId attribute exists
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        [XmlSerialization.XmlIgnore()]
        public bool SourceIdSpecified
        {
            get
            {
                return m_SourceId != SOURCE_ID_NOT_SPECIFIED;
            }
            set
            {
                if (!value)
                {
                    m_SourceId = SOURCE_ID_NOT_SPECIFIED;
                }
            }
        }

        /// <summary>
        ///  The sourceUrl of the metadata file
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        [XmlSerialization.XmlAttribute()]
        public string SourceUrl
        {
            get
            {
                return m_SourceUrl;
            }
            set
            {
                m_SourceUrl = value;
            }
        }

        /// <summary>
        /// Retrieves the TargetNamespace when it is a schema item or a WSDL item
        /// </summary>
        /// <value></value>
        /// <remarks></remarks>
        public string TargetNamespace
        {
            get
            {
                return CachedMetadata.TargetNamespace;
            }
        }

        /// <summary>
        /// Detemine the type of a metadata item
        /// </summary>
        /// <param name="reader"></param>
        /// <returns>File Type</returns>
        /// <remarks></remarks>
        private MetadataType DetermineFileType(XmlReader reader)
        {
            try
            {
                if (reader.IsStartElement(XmlStrings.WSDL.Elements.Root, XmlStrings.WSDL.NamespaceUri))
                {
                    return MetadataType.Wsdl;
                }
                else if (reader.IsStartElement(XmlStrings.XmlSchema.Elements.Root, XmlStrings.XmlSchema.NamespaceUri))
                {
                    return MetadataType.Schema;
                }
                else if (reader.IsStartElement(XmlStrings.WSPolicy.Elements.Policy, XmlStrings.WSPolicy.NamespaceUri)
                         || reader.IsStartElement(XmlStrings.WSPolicy.Elements.Policy, XmlStrings.WSPolicy.NamespaceUri15))
                {
                    return MetadataType.Policy;
                }
                else if (reader.IsStartElement(XmlStrings.DISCO.Elements.Root, XmlStrings.DISCO.NamespaceUri))
                {
                    return MetadataType.Disco;
                }
                else if (reader.IsStartElement(XmlStrings.DataServices.Elements.Root, XmlStrings.DataServices.NamespaceUri))
                {
                    return MetadataType.Edmx;
                }
                else
                {
                    return MetadataType.Xml;
                }
            }
            catch (XmlException)
            {
                // This must mean that the document isn't an XML Document so we continue trying other things...
                return MetadataType.Unknown;
            }
        }

        /// <summary>
        /// return the default extension
        /// </summary>
        /// <return></return>
        /// <remarks></remarks>
        public string GetDefaultExtension()
        {
            switch (m_MetadataType)
            {
                case MetadataType.Disco:
                    return "disco";
                case MetadataType.Wsdl:
                    return "wsdl";
                case MetadataType.Schema:
                    return "xsd";
                case MetadataType.Xml:
                    return "xml";
                case MetadataType.Policy:
                    return "xml";
                case MetadataType.Edmx:
                    return "edmx";
                default:
                    return "data";
            }
        }

        /// <summary>
        /// return the default filename without extension
        /// </summary>
        /// <return></return>
        /// <remarks></remarks>
        public string GetDefaultFileName()
        {
            if (!String.IsNullOrEmpty(TargetNamespace))
            {
                string ns = TargetNamespace;
                if (!ns.EndsWith("/", StringComparison.Ordinal))
                {
                    int i = ns.LastIndexOfAny(Path.GetInvalidFileNameChars());
                    if (i >= 0)
                    {
                        ns = ns.Substring(i + 1);
                    }

                    string defaultExtension = "." + GetDefaultExtension();
                    if (ns.Length > defaultExtension.Length && ns.EndsWith(defaultExtension, StringComparison.OrdinalIgnoreCase))
                    {
                        ns = ns.Substring(0, ns.Length - defaultExtension.Length);
                    }

                    if (ns.Length > 0)
                    {
                        return ns;
                    }
                }
            }

            return DEFAULT_FILE_NAME;
        }

        /// <summary>
        /// Load the content of a Metadata item into the object model
        /// </summary>
        /// <param name="byteContent"></param>
        /// <remarks></remarks>
        internal void LoadContent(byte[] byteContent)
        {
            m_BinaryContent = byteContent;
            LoadContentFromTextReader(new StreamReader(new MemoryStream(byteContent)));
        }

        /// <summary>
        /// Load the content of a Metadata item into the object model
        /// </summary>
        /// <param name="content"></param>
        /// <remarks></remarks>
        internal void LoadContent(string content)
        {
            MemoryStream memStream = new MemoryStream();
            StreamWriter contentWriter = new StreamWriter(memStream);
            contentWriter.Write(content);
            contentWriter.Flush();
            m_BinaryContent = memStream.ToArray();

            LoadContentFromTextReader(new StringReader(content));
        }

        /// <summary>
        /// Load the content of a Metadata item into the object model
        /// </summary>
        /// <param name="contentReader"></param>
        /// <remarks></remarks>
        private void LoadContentFromTextReader(TextReader contentReader)
        {
            if (contentReader == null)
            {
                throw new ArgumentNullException("contentReader");
            }

            // reset...
            ErrorInLoading = null;

            m_CachedMetadata = null;

            using (XmlTextReader xmlReader = new XmlTextReader(contentReader))
            {
                if (m_MetadataType == MetadataType.Unknown)
                {
                    // If we don't know the metedata type, we try to sniff it...
                    MetadataType fileType = DetermineFileType(xmlReader);

                    // try
                    m_CachedMetadata = LoadMetadataContent(fileType, xmlReader);
                    if (m_CachedMetadata.MetadataFormatError == null)
                    {
                        m_MetadataType = fileType;
                    }
                }
            }
        }

        /// <summary>
        ///  the function is called when the metadata is removed, and we need clean up the content
        /// </summary>
        /// <remarks></remarks>
        internal void CleanUpContent()
        {
            ErrorInLoading = null;
            m_BinaryContent = new byte[] { };

            m_CachedMetadata = null;
        }

        /// <summary>
        /// Load schema/wsdl model from binary content.  -- Parse the metadata content 
        /// </summary>
        /// <return></return>
        /// <remarks></remarks>
        private MetadataContent LoadMetadataContent(MetadataType fileType)
        {
            if (ErrorInLoading != null)
            {
                return new MetadataContent(ErrorInLoading);
            }
            using (XmlTextReader xmlReader = new XmlTextReader(new StreamReader(new MemoryStream(m_BinaryContent))))
            {
                return LoadMetadataContent(fileType, xmlReader);
            }
        }

        /// <summary>
        /// Load schema/wsdl model from text reader.  -- it will parse the metadata content.
        /// </summary>
        /// <return></return>
        /// <remarks></remarks>
        private MetadataContent LoadMetadataContent(MetadataType fileType, XmlTextReader xmlReader)
        {
            MetadataContent cachedMetadata = new MetadataContent();

            try
            {
                switch (fileType)
                {
                    case MetadataType.Disco:
                        cachedMetadata = new MetadataContent(Discovery.DiscoveryDocument.Read(xmlReader));
                        break;
                    case MetadataType.Wsdl:
                        cachedMetadata = new MetadataContent(Description.ServiceDescription.Read(xmlReader));
                        cachedMetadata.MetadataServiceDescription.RetrievalUrl = GetMetadataSourceUrl();
                        break;
                    case MetadataType.Schema:
                        cachedMetadata = new MetadataContent(XmlSchema.Read(xmlReader, null));
                        cachedMetadata.MetadataXmlSchema.SourceUri = GetMetadataSourceUrl();
                        break;
                    case MetadataType.Unknown:
                        // For unknown types, we don't do nothing...
                        break;
                    default:
                        Debug.Assert(fileType == MetadataType.Xml || fileType == MetadataType.Policy || fileType == MetadataType.Edmx);
                        XmlDocument tempDoc = new XmlDocument();
                        tempDoc.Load(xmlReader);
                        cachedMetadata = new MetadataContent(tempDoc);
                        break;
                }
            }
            catch (Exception ex)
            {
                cachedMetadata = new MetadataContent(ex);
            }

            return cachedMetadata;
        }

        /// <summary>
        /// convert metadata file to MetadataSection (to feed code/proxy generator)
        ///  We don't reuse the buffered object model, because the generator could modify & corrupt them.
        /// </summary>
        /// <remarks></remarks>
        internal MetadataSection CreateMetadataSection()
        {
            MetadataContent metadata = LoadMetadataContent(m_MetadataType);
            if (metadata.MetadataFormatError != null)
            {
                throw metadata.MetadataFormatError;
            }

            MetadataSection metadataSection = null;

            switch (FileType)
            {
                case MetadataType.Unknown:
                    break;
                case MetadataType.Disco:
                    if (metadata.MetadataServiceDescription != null)
                    {
                        metadataSection = MetadataSection.CreateFromServiceDescription(metadata.MetadataServiceDescription);
                    }
                    break;
                case MetadataType.Wsdl:
                    // We need to make a copy of the WSDL object model since the act of importing it actuall
                    // modifies it, and we don't want the cached instance to be polluted...
                    System.Web.Services.Description.ServiceDescription description = metadata.MetadataServiceDescription;
                    if (description != null)
                    {
                        metadataSection = MetadataSection.CreateFromServiceDescription(description);
                    }
                    break;
                case MetadataType.Schema:
                    if (metadata.MetadataXmlSchema != null)
                    {
                        metadataSection = MetadataSection.CreateFromSchema(metadata.MetadataXmlSchema);
                    }
                    break;
                case MetadataFile.MetadataType.Policy:
                    if (metadata.MetadataXmlDocument != null)
                    {
                        metadataSection = MetadataSection.CreateFromPolicy(metadata.MetadataXmlDocument.DocumentElement, null);
                    }
                    break;
                case MetadataFile.MetadataType.Xml:
                case MetadataFile.MetadataType.Edmx:
                    if (metadata.MetadataXmlDocument != null)
                    {
                        metadataSection = new MetadataSection(null, null, metadata.MetadataXmlDocument.DocumentElement);
                    }
                    break;
                default:
                    System.Diagnostics.Debug.Fail("Unknown Type?");
                    break;
            }
            return metadataSection;
        }

        /// <summary>
        /// Metadata source Url is used in error messages
        /// </summary>
        /// <remarks></remarks>
        internal string GetMetadataSourceUrl()
        {
            if (String.IsNullOrEmpty(SourceUrl))
            {
                return FileName;
            }
            else
            {
                return SourceUrl;
            }
        }

        /// <summary>
        /// Metadata File Type Enum
        /// </summary>
        /// <remarks></remarks>
        public enum MetadataType
        {
            [XmlSerialization.XmlEnum(Name = "Unknown")]
            Unknown = 0,
            [XmlSerialization.XmlEnum(Name = "Disco")]
            Disco = 1,
            [XmlSerialization.XmlEnum(Name = "Wsdl")]
            Wsdl = 2,
            [XmlSerialization.XmlEnum(Name = "Schema")]
            Schema = 3,
            [XmlSerialization.XmlEnum(Name = "Policy")]
            Policy = 4,
            [XmlSerialization.XmlEnum(Name = "Xml")]
            Xml = 5,
            [XmlSerialization.XmlEnum(Name = "Edmx")]
            Edmx = 6,
        }

        /// <summary>
        /// Metadata contained inside the file. Only one of field is valid, which depends on the MetadataType
        /// </summary>
        /// <remarks></remarks>
        private class MetadataContent
        {

            private Discovery.DiscoveryDocument m_MetadataDiscoveryDocument;
            private Description.ServiceDescription m_MetadataServiceDescription;
            private XmlSchema m_MetadataXmlSchema;
            private XmlDocument m_MetadataXmlDocument;

            private Exception m_MetadataFormatError;

            private string m_TargetNamespace;

            internal MetadataContent()
            {
                m_TargetNamespace = String.Empty;
            }

            internal MetadataContent(Discovery.DiscoveryDocument discoveryDocument)
            {
                m_MetadataDiscoveryDocument = discoveryDocument;
                m_TargetNamespace = String.Empty;
            }

            internal MetadataContent(Description.ServiceDescription serviceDescription)
            {
                m_MetadataServiceDescription = serviceDescription;
                m_TargetNamespace = serviceDescription.TargetNamespace;
            }

            internal MetadataContent(XmlSchema schema)
            {
                m_MetadataXmlSchema = schema;
                m_TargetNamespace = schema.TargetNamespace;
            }

            internal MetadataContent(XmlDocument document)
            {
                m_MetadataXmlDocument = document;
                m_TargetNamespace = String.Empty;
            }

            internal MetadataContent(Exception metadataFormatError)
            {
                m_MetadataFormatError = metadataFormatError;
            }

            /// <summary>
            /// Retrieves the content of a discovery file
            /// </summary>
            /// <value></value>
            /// <remarks></remarks>
            public Discovery.DiscoveryDocument MetadataDiscoveryDocument
            {
                get
                {
                    return m_MetadataDiscoveryDocument;
                }
            }

            /// <summary>
            /// Error message if 
            /// </summary>
            /// <value></value>
            /// <remarks></remarks>
            public Exception MetadataFormatError
            {
                get
                {
                    return m_MetadataFormatError;
                }
            }

            /// <summary>
            /// Retrieves the content of a WSDL file
            /// </summary>
            /// <value></value>
            /// <remarks></remarks>
            public Description.ServiceDescription MetadataServiceDescription
            {
                get
                {
                    return m_MetadataServiceDescription;
                }
            }

            /// <summary>
            /// Retrieves the content of a schema file
            /// </summary>
            /// <value></value>
            /// <remarks></remarks>
            public XmlSchema MetadataXmlSchema
            {
                get
                {
                    return m_MetadataXmlSchema;
                }
            }

            /// <summary>
            /// Retrieves the content of an Xml file
            /// </summary>
            /// <value></value>
            /// <remarks></remarks>
            public XmlDocument MetadataXmlDocument
            {
                get
                {
                    return m_MetadataXmlDocument;
                }
            }

            /// <summary>
            /// Retrieves the TargetNamespace when it is a schema item or a WSDL item
            /// </summary>
            /// <value></value>
            /// <remarks></remarks>
            public string TargetNamespace
            {
                get
                {
                    return m_TargetNamespace;
                }
            }

        }
    }

}