public static void Main() { try { // <Snippet2> // Reference the schema document. string myStringUrl = "c:\\Inetpub\\wwwroot\\dataservice.xsd"; XmlSchema myXmlSchema; // Create the client protocol. DiscoveryClientProtocol myDiscoveryClientProtocol = new DiscoveryClientProtocol(); myDiscoveryClientProtocol.Credentials = CredentialCache.DefaultCredentials; // Create a schema reference. SchemaReference mySchemaReferenceNoParam = new SchemaReference(); SchemaReference mySchemaReference = new SchemaReference(myStringUrl); // Set the client protocol. mySchemaReference.ClientProtocol = myDiscoveryClientProtocol; // Access the default file name associated with the schema reference. Console.WriteLine("Default filename is : " + mySchemaReference.DefaultFilename); // Access the namespace associated with schema reference class. Console.WriteLine("Namespace is : " + SchemaReference.Namespace); FileStream myStream = new FileStream(myStringUrl, FileMode.OpenOrCreate); // Read the document in a stream. mySchemaReference.ReadDocument(myStream); // Get the schema of referenced document. myXmlSchema = mySchemaReference.Schema; Console.WriteLine("Reference is : " + mySchemaReference.Ref); Console.WriteLine("Target namespace (default empty) is : " + mySchemaReference.TargetNamespace); Console.WriteLine("URL is : " + mySchemaReference.Url); // Write the document in the stream. mySchemaReference.WriteDocument(myXmlSchema, myStream); myStream.Close(); mySchemaReference = null; // </Snippet2> } catch (Exception e) { Console.WriteLine(e.ToString()); } }
public override WebServiceDiscoveryResult Load(WebReferenceItem item) { FilePath basePath = item.MapFile.FilePath.ParentDirectory; ReferenceGroup resfile = ReferenceGroup.Read(item.MapFile.FilePath); // TODO: Read as MetadataSet var protocol = new DiscoveryClientProtocol(); foreach (MetadataFile dcr in resfile.Metadata) { DiscoveryReference dr; switch (dcr.MetadataType) { case "Wsdl": dr = new ContractReference(); break; case "Disco": dr = new DiscoveryDocumentReference(); break; case "Schema": dr = new SchemaReference(); break; default: continue; } dr.Url = dcr.SourceUrl; var fs = new FileStream(basePath.Combine(dcr.FileName), FileMode.Open, FileAccess.Read); protocol.Documents.Add(dr.Url, dr.ReadDocument(fs)); fs.Close(); protocol.References.Add(dr.Url, dr); } return(new WebServiceDiscoveryResultWCF(protocol, null, item, resfile, DefaultClientOptions)); }