//MetadataExchangeClient can only download data from a local wsdl file, if it is a file we user the DiscoveryClientProtocol void DownloadFile(out List<wsdlDescription.ServiceDescription> descriptions, out List<XmlSchema> schemas) { descriptions = new List<wsdlDescription.ServiceDescription>(); schemas = new List<XmlSchema>(); DiscoveryClientProtocol client = new DiscoveryClientProtocol(); //download document client.AllowAutoRedirect = true; client.Timeout = _timeoutInSeconds * 1000; client.Documents.Clear(); client.DiscoverAny(_wsdlEndpoint); client.ResolveAll(); foreach (var v in client.Documents.Values) { if (v is wsdlDescription.ServiceDescription) { descriptions.Add((wsdlDescription.ServiceDescription)v); } else if (v is XmlSchema) { schemas.Add((XmlSchema)v); } } }
public override void FixtureSetUp() { base.FixtureSetUp(); project = WebReferenceTestHelper.CreateTestProject("C#"); project.FileName = FileName.Create("C:\\projects\\test\\foo.csproj"); protocol = new DiscoveryClientProtocol(); DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference(); discoveryRef.Url = updateFromUrl; protocol.References.Add(discoveryRef); ContractReference contractRef = new ContractReference(); contractRef.Url = "http://localhost/test.asmx?wsdl"; contractRef.ClientProtocol = new DiscoveryClientProtocol(); ServiceDescription desc = new ServiceDescription(); contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc); protocol.References.Add(contractRef); WebReferenceTestHelper.InitializeProjectBindings(); webReference = new Gui.WebReference(project, updateFromUrl, name, proxyNamespace, protocol); foreach (ProjectItem item in webReference.Items) { ProjectService.AddProjectItem(project, item); } webReferencesProjectItem = webReference.WebReferencesProjectItem; }
public override void FixtureSetUp() { base.FixtureSetUp(); // Set up the project. MSBuildBasedProject project = WebReferenceTestHelper.CreateTestProject("C#"); project.FileName = FileName.Create("c:\\projects\\test\\foo.csproj"); // Web references item. WebReferencesProjectItem webReferencesItem = new WebReferencesProjectItem(project); webReferencesItem.Include = "Web References\\"; ProjectService.AddProjectItem(project, webReferencesItem); // Web reference url. WebReferenceUrl webReferenceUrl = new WebReferenceUrl(project); webReferenceUrl.Include = "http://localhost/test.asmx"; webReferenceUrl.UpdateFromURL = "http://localhost/test.asmx"; webReferenceUrl.RelPath = "Web References\\localhost"; ProjectService.AddProjectItem(project, webReferenceUrl); FileProjectItem discoFileItem = new FileProjectItem(project, ItemType.None); discoFileItem.Include = "Web References\\localhost\\test.disco"; ProjectService.AddProjectItem(project, discoFileItem); FileProjectItem wsdlFileItem = new FileProjectItem(project, ItemType.None); wsdlFileItem.Include = "Web References\\localhost\\test.wsdl"; ProjectService.AddProjectItem(project, wsdlFileItem); // Proxy FileProjectItem proxyItem = new FileProjectItem(project, ItemType.Compile); proxyItem.Include = "Web References\\localhost\\Reference.cs"; proxyItem.DependentUpon = "Reference.map"; ProjectService.AddProjectItem(project, proxyItem); // Reference map. FileProjectItem mapItem = new FileProjectItem(project, ItemType.None); mapItem.Include = "Web References\\localhost\\Reference.map"; ProjectService.AddProjectItem(project, mapItem); // System.Web.Services reference. ReferenceProjectItem webServicesReferenceItem = new ReferenceProjectItem(project, "System.Web.Services"); ProjectService.AddProjectItem(project, webServicesReferenceItem); // Set up the web reference. DiscoveryClientProtocol protocol = new DiscoveryClientProtocol(); DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference(); discoveryRef.Url = "http://localhost/new.asmx"; protocol.References.Add(discoveryRef); ContractReference contractRef = new ContractReference(); contractRef.Url = "http://localhost/new.asmx?wsdl"; contractRef.ClientProtocol = new DiscoveryClientProtocol(); ServiceDescription desc = new ServiceDescription(); contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc); protocol.References.Add(contractRef); WebReferenceTestHelper.InitializeProjectBindings(); var webReference = new Gui.WebReference(project, "http://localhost/new.asmx", "localhost", "ProxyNamespace", protocol); changes = webReference.GetChanges(project); }
protected DiscoveryClientProtocol DiscoResolve (string url) { // Checks the availablity of any services var protocol = new DiscoveryClientProtocol (); var creds = new AskCredentials (); protocol.Credentials = creds; bool unauthorized; do { unauthorized = false; creds.Reset (); try { protocol.DiscoverAny (url); } catch (WebException wex) { var wr = wex.Response as HttpWebResponse; if (!creds.Canceled && wr != null && wr.StatusCode == HttpStatusCode.Unauthorized) { unauthorized = true; continue; } throw; } } while (unauthorized); if (protocol != null) { creds.Store (); if (protocol.References.Count == 0) return null; } return protocol; }
private static DiscoveryDocument GetDocumentNoParse(ref string url, DiscoveryClientProtocol client) { DiscoveryDocument document2; DiscoveryDocument document = (DiscoveryDocument) client.Documents[url]; if (document != null) { return document; } string contentType = null; Stream stream = client.Download(ref url, ref contentType); try { XmlTextReader xmlReader = new XmlTextReader(new StreamReader(stream, RequestResponseUtils.GetEncoding(contentType))) { WhitespaceHandling = WhitespaceHandling.Significant, XmlResolver = null, DtdProcessing = DtdProcessing.Prohibit }; if (!DiscoveryDocument.CanRead(xmlReader)) { ArgumentException innerException = new ArgumentException(System.Web.Services.Res.GetString("WebInvalidFormat")); throw new InvalidOperationException(System.Web.Services.Res.GetString("WebMissingDocument", new object[] { url }), innerException); } document2 = DiscoveryDocument.Read(xmlReader); } finally { stream.Close(); } return document2; }
static void Generate(string url, TextWriter writer) { var cr = new ContractReference(); cr.Url = url; var protocol = new DiscoveryClientProtocol(); var wc = new WebClient(); using (var stream = wc.OpenRead(cr.Url)) protocol.Documents.Add(cr.Url, cr.ReadDocument(stream)); var mset = ToMetadataSet(protocol); var importer = new WsdlImporter(mset); var xsdImporter = new XsdDataContractImporter(); var options = new ImportOptions(); options.ReferencedCollectionTypes.Add(typeof(LinkedList<>)); xsdImporter.Options = options; importer.State.Add(typeof(XsdDataContractImporter), xsdImporter); Collection<ContractDescription> contracts = importer.ImportAllContracts(); CodeCompileUnit ccu = new CodeCompileUnit(); CodeNamespace cns = new CodeNamespace("TestNamespace"); ccu.Namespaces.Add(cns); var generator = new ServiceContractGenerator(ccu); foreach (var cd in contracts) generator.GenerateServiceContractType(cd); var provider = new CSharpCodeProvider(); provider.GenerateCodeFromCompileUnit(ccu, writer, null); }
public void SetUpFixture() { project = WebReferenceTestHelper.CreateTestProject("C#"); project.FileName = FileName.Create("C:\\projects\\test\\foo.csproj"); protocol = new DiscoveryClientProtocol(); DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference(); discoveryRef.Url = updateFromUrl; protocol.References.Add(discoveryRef); ContractReference contractRef = new ContractReference(); contractRef.Url = "http://localhost/test.asmx?wsdl"; contractRef.ClientProtocol = new DiscoveryClientProtocol(); ServiceDescription desc = new ServiceDescription(); contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc); protocol.References.Add(contractRef); WebReferenceTestHelper.InitializeProjectBindings(); webReference = new SD.WebReference(project, updateFromUrl, name, proxyNamespace, protocol); webReferenceUrl = webReference.WebReferenceUrl; discoFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost\\test.disco", ItemType.None); referenceMapFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost\\Reference.map", ItemType.None); wsdlFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost\\test.wsdl", ItemType.None); proxyFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost\\Reference.cs", ItemType.Compile); webReferencesProjectItem = (WebReferencesProjectItem)WebReferenceTestHelper.GetProjectItem(webReference.Items, "Web References\\", ItemType.WebReferences); webServicesReferenceProjectItem = (ReferenceProjectItem)WebReferenceTestHelper.GetProjectItem(webReference.Items, ItemType.Reference); }
public WebServiceDiscoveryResultWCF (DiscoveryClientProtocol protocol, MetadataSet metadata, WebReferenceItem item, ReferenceGroup refGroup, ClientOptions defaultOptions): base (WebReferencesService.WcfEngine, item) { this.refGroup = refGroup; this.protocol = protocol; this.metadata = metadata; this.defaultOptions = defaultOptions; }
public void SetUpFixture() { project = WebReferenceTestHelper.CreateTestProject("C#"); project.FileName = "C:\\projects\\test\\foo.csproj"; ReferenceProjectItem referenceItem = new ReferenceProjectItem(project, "System.Web.Services"); ProjectService.AddProjectItem(project, referenceItem); protocol = new DiscoveryClientProtocol(); DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference(); discoveryRef.Url = updateFromUrl; protocol.References.Add(discoveryRef); ContractReference contractRef = new ContractReference(); contractRef.Url = "http://localhost/test.asmx?wsdl"; contractRef.ClientProtocol = new DiscoveryClientProtocol(); ServiceDescription desc = new ServiceDescription(); contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc); protocol.References.Add(contractRef); WebReferenceTestHelper.InitializeLanguageBindings(); webReference = new SD.WebReference(project, updateFromUrl, name, proxyNamespace, protocol); webServicesReferenceProjectItem = (ReferenceProjectItem)WebReferenceTestHelper.GetProjectItem(webReference.Items, ItemType.Reference); }
public override void FixtureSetUp() { base.FixtureSetUp(); project = WebReferenceTestHelper.CreateTestProject("C#"); WebReferencesProjectItem item = new WebReferencesProjectItem(project); item.Include = "Web References\\"; ProjectService.AddProjectItem(project, item); protocol = new DiscoveryClientProtocol(); DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference(); discoveryRef.Url = updateFromUrl; protocol.References.Add(discoveryRef); ContractReference contractRef = new ContractReference(); contractRef.Url = "http://localhost/test.asmx?wsdl"; contractRef.ClientProtocol = new DiscoveryClientProtocol(); ServiceDescription desc = new ServiceDescription(); contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc); protocol.References.Add(contractRef); WebReferenceTestHelper.InitializeProjectBindings(); webReference = new Gui.WebReference(project, updateFromUrl, name, proxyNamespace, protocol); webReferencesProjectItem = WebReferenceTestHelper.GetProjectItem(webReference.Items, "Web References\\", ItemType.WebReferences); }
public WebReference(IProject project, string url, string name, string proxyNamespace, DiscoveryClientProtocol protocol) { this.project = project; this.url = url; this.protocol = protocol; this.proxyNamespace = proxyNamespace; this.name = name; GetRelativePath(); }
void DiscoverWebServiceMetadata(object sender, DoWorkEventArgs e) { Uri url = (Uri)e.Argument; var client = new DiscoveryClientProtocol(); client.Credentials = GetCredentials(); DiscoveryDocument document = client.DiscoverAny(url.AbsoluteUri); client.ResolveOneLevel(); e.Result = new ServiceReferenceDiscoveryEventArgs(client.References); }
DiscoveryClientDocumentCollection DiscoverDocuments() { var protocol = new DiscoveryClientProtocol { AllowAutoRedirect = true, Credentials = credentials ?? CredentialCache.DefaultCredentials }; protocol.DiscoverAny(uri); protocol.ResolveAll(); return protocol.Documents; }
public static ServiceDescriptionCollection GetServiceDescriptions(DiscoveryClientProtocol protocol) { ServiceDescriptionCollection services = new ServiceDescriptionCollection(); protocol.ResolveOneLevel(); foreach (DictionaryEntry entry in protocol.References) { ContractReference contractRef = entry.Value as ContractReference; if (contractRef != null) { services.Add(contractRef.Contract); } } return services; }
public void SetupFixture() { project = WebReferenceTestHelper.CreateTestProject("C#"); project.FileName = "C:\\Projects\\Web.csproj"; WebReferencesProjectItem item = new WebReferencesProjectItem(project); item.Include = "Foo\\"; ProjectService.AddProjectItem(project, item); protocol = new DiscoveryClientProtocol(); WebReferenceTestHelper.InitializeProjectBindings(); webReference = new SD.WebReference(project, updateFromUrl, name, proxyNamespace, protocol); webReferenceUrl = (WebReferenceUrl)WebReferenceTestHelper.GetProjectItem(webReference.Items, ItemType.WebReferenceUrl); }
/// <summary>Read the specified protocol into an ServiceDescriptionImporter.</summary> /// <param name="protocol">A DiscoveryClientProtocol containing the service protocol detail.</param> /// <returns>A ServiceDescriptionImporter for the specified protocol.</returns> public static ServiceDescriptionImporter ReadServiceDescriptionImporter(DiscoveryClientProtocol protocol) { // Service Description Importer ServiceDescriptionImporter importer = new ServiceDescriptionImporter(); importer.ProtocolName = "Soap"; // Add all the schemas and service descriptions to the importer protocol.ResolveAll (); foreach (object doc in protocol.Documents.Values) { if (doc is ServiceDescription) importer.AddServiceDescription((ServiceDescription)doc, null, null); else if (doc is XmlSchema) importer.Schemas.Add((XmlSchema)doc); } return importer; }
/// <summary> /// Resolves metadata from the specified URL. /// </summary> /// <param name="url">The URL.</param> /// <returns>A list of metadata sections.</returns> public static IEnumerable<MetadataSection> Resolve(string url) { MetadataSet metadataSet = new MetadataSet(); DiscoveryClientProtocol discoveryClient = new DiscoveryClientProtocol { UseDefaultCredentials = true, AllowAutoRedirect = true }; discoveryClient.DiscoverAny(url); discoveryClient.ResolveAll(); foreach (object document in discoveryClient.Documents.Values) { AddDocumentToSet(metadataSet, document); } return metadataSet.MetadataSections; }
/// <summary> /// Gets the web service description from the supplied URL. /// </summary> /// <param name="url"> /// The URL where XML Web services discovery begins. /// </param> /// <param name="username"> /// The username. /// </param> /// <param name="password"> /// The password. /// </param> /// <returns> /// The <see cref="WebServiceDescription"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// The <paramref name="url"/> parameter is null. /// </exception> /// <exception cref="InvalidOperationException"> /// The <paramref name="url"/> parameter is a valid URL, but does not point to a valid discovery document, service description, or XSD schema. /// </exception> public WebServiceDescription GetServiceDescription(string url, string username, string password) { if (url == null) throw new ArgumentNullException("url"); url = url.Trim(); var protocol = new DiscoveryClientProtocol { AllowAutoRedirect = true, Credentials = CredentialCache.DefaultCredentials }; if (!string.IsNullOrEmpty(username)) protocol.Credentials = new NetworkCredential(username, password); try { protocol.DiscoverAny(url); } catch (InvalidOperationException) { if (!url.EndsWith("?WSDL", StringComparison.InvariantCultureIgnoreCase)) protocol.DiscoverAny(url + "?WSDL"); else throw; } protocol.ResolveAll(); var serviceDescription = new WebServiceDescription(); foreach (DictionaryEntry entry in protocol.References) { var contractReference = entry.Value as ContractReference; if (contractReference != null) serviceDescription.ServiceDescriptions.Add(contractReference.Contract); var schemaReference = entry.Value as SchemaReference; if (schemaReference != null) serviceDescription.XmlSchemas.Add(schemaReference.Schema); } return serviceDescription; }
/// <summary>Read the specified protocol into an ServiceDescriptionImporter.</summary> /// <param name="protocol">A DiscoveryClientProtocol containing the service protocol detail.</param> /// <returns>A ServiceDescriptionImporter for the specified protocol.</returns> public static ServiceDescriptionImporter ReadServiceDescriptionImporter(DiscoveryClientProtocol protocol) { // Service Description Importer var importer = new ServiceDescriptionImporter(); importer.ProtocolName = "Soap"; // Add all the schemas and service descriptions to the importer protocol.ResolveAll (); foreach (object doc in protocol.Documents.Values) { var serviceDescription = doc as ServiceDescription; if (serviceDescription != null) importer.AddServiceDescription (serviceDescription, null, null); else { var xmlSchema = doc as XmlSchema; if (xmlSchema != null) importer.Schemas.Add (xmlSchema); } } return importer; }
public void ReadWriteTest () { string directory = Path.Combine (Path.GetTempPath (), Path.GetRandomFileName ()); Directory.CreateDirectory (directory); try { string url = "http://www.w3schools.com/WebServices/TempConvert.asmx"; var p1 = new DiscoveryClientProtocol (); p1.DiscoverAny (url); p1.ResolveAll (); p1.WriteAll (directory, "Reference.map"); var p2 = new DiscoveryClientProtocol (); var results = p2.ReadAll (Path.Combine (directory, "Reference.map")); Assert.AreEqual (2, results.Count); Assert.AreEqual ("TempConvert.disco", results [0].Filename); Assert.AreEqual ("TempConvert.wsdl", results [1].Filename); } finally { Directory.Delete (directory, true); } }
public void SetUpFixture() { project = WebReferenceTestHelper.CreateTestProject("VBNet"); protocol = new DiscoveryClientProtocol(); DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference(); discoveryRef.Url = updateFromUrl; protocol.References.Add(discoveryRef); ContractReference contractRef = new ContractReference(); contractRef.Url = "http://localhost/test.asmx?wsdl"; contractRef.ClientProtocol = new DiscoveryClientProtocol(); ServiceDescription desc = new ServiceDescription(); contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc); protocol.References.Add(contractRef); WebReferenceTestHelper.InitializeProjectBindings(); webReference = new SD.WebReference(project, updateFromUrl, name, proxyNamespace, protocol); proxyFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost\\Reference.vb", ItemType.Compile); }
public Collection<MetadataSection> DownloadMetadata(string serviceUrl) { Uri serviceUri = new Uri(serviceUrl); Collection<MetadataSection> metadataSections; if (TryDownloadByMetadataExchangeClient(serviceUri, out metadataSections)) { return metadataSections; } else { if (TryDownloadByMetadataExchangeClient(GetDefaultMexUri(serviceUri), out metadataSections)) { return metadataSections; } } bool supporstDiscoveryClientProtocol = serviceUri.Scheme == Uri.UriSchemeHttp || serviceUri.Scheme == Uri.UriSchemeHttps; if (supporstDiscoveryClientProtocol) { DiscoveryClientProtocol disco = new DiscoveryClientProtocol(); disco.AllowAutoRedirect = true; disco.UseDefaultCredentials = true; disco.DiscoverAny(serviceUrl); disco.ResolveAll(); Collection<MetadataSection> result = new Collection<MetadataSection>(); if (disco.Documents.Values != null) { foreach (object document in disco.Documents.Values) { AddDocumentToResults(document, result); } } return result; } return null; }
internal static void LoadExternals(XmlSchema schema, string url, DiscoveryClientProtocol client, Hashtable loadedExternals) { if (schema != null) { foreach (XmlSchemaExternal external in schema.Includes) { if ((((external.SchemaLocation != null) && (external.SchemaLocation.Length != 0)) && (external.Schema == null)) && ((external is XmlSchemaInclude) || (external is XmlSchemaRedefine))) { string str = DiscoveryReference.UriToString(url, external.SchemaLocation); if (client.References[str] is SchemaReference) { SchemaReference reference = (SchemaReference) client.References[str]; external.Schema = reference.GetSchema(); if (external.Schema != null) { loadedExternals[str] = external.Schema; } reference.LoadExternals(loadedExternals); } } } } }
public override void FixtureSetUp() { base.FixtureSetUp(); project = WebReferenceTestHelper.CreateTestProject("C#"); project.FileName = FileName.Create("C:\\Projects\\Web.csproj"); WebReferencesProjectItem item = new WebReferencesProjectItem(project); item.Include = "Web References\\"; ProjectService.AddProjectItem(project, item); protocol = new DiscoveryClientProtocol(); DiscoveryDocumentReference discoveryRef = new DiscoveryDocumentReference(); discoveryRef.Url = updateFromUrl; protocol.References.Add(discoveryRef); ContractReference contractRef = new ContractReference(); contractRef.Url = "http://localhost/test.asmx?wsdl"; contractRef.ClientProtocol = new DiscoveryClientProtocol(); ServiceDescription desc = new ServiceDescription(); contractRef.ClientProtocol.Documents.Add(contractRef.Url, desc); protocol.References.Add(contractRef); WebReferenceTestHelper.InitializeProjectBindings(); webReference = new Gui.WebReference(project, updateFromUrl, oldName, proxyNamespace, protocol); // Force generation of items. List<ProjectItem> items = webReference.Items; // Change the web reference name. webReference.Name = name; webReferenceUrl = (WebReferenceUrl)WebReferenceTestHelper.GetProjectItem(webReference.Items, ItemType.WebReferenceUrl); discoFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost1\\test.disco", ItemType.None); referenceMapFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost1\\Reference.map", ItemType.None); wsdlFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost1\\test.wsdl", ItemType.None); proxyFileProjectItem = WebReferenceTestHelper.GetFileProjectItem(webReference.Items, "Web References\\localhost1\\Reference.cs", ItemType.Compile); }
public model.WebSvc Generate(string filePath) { List<wsdlDescription.ServiceDescription> descriptions = new List<wsdlDescription.ServiceDescription>(); List<XmlSchema> schemas = new List<XmlSchema>(); DiscoveryClientProtocol client = new DiscoveryClientProtocol(); //load Document from file client.AllowAutoRedirect = true; client.Documents.Clear(); client.DiscoverAny(filePath); client.ResolveAll(); foreach (var v in client.Documents.Values) { if (v is wsdlDescription.ServiceDescription) { descriptions.Add((wsdlDescription.ServiceDescription)v); } else if (v is XmlSchema) { schemas.Add((XmlSchema)v); } } return Generate(filePath, descriptions, schemas); }
private void DoMex() { string mexAddress; string mexBindingSectionName; string mexBindingConfiguration; string contract; string contractNamespace; string binding; string bindingNamespace; string address; string spnIdentity = null; string upnIdentity = null; string dnsIdentity = null; string mexSpnIdentity = null; string mexUpnIdentity = null; string mexDnsIdentity = null; string serializer = null; EndpointIdentity identity = null; EndpointIdentity mexIdentity = null; propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Contract, out contract); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.ContractNamespace, out contractNamespace); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.BindingNamespace, out bindingNamespace); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Binding, out binding); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexAddress, out mexAddress); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexBinding, out mexBindingSectionName); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexBindingConfiguration, out mexBindingConfiguration); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Address, out address); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.SpnIdentity, out spnIdentity); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.UpnIdentity, out upnIdentity); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.DnsIdentity, out dnsIdentity); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexSpnIdentity, out mexSpnIdentity); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexUpnIdentity, out mexUpnIdentity); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexDnsIdentity, out mexDnsIdentity); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Serializer, out serializer); if (string.IsNullOrEmpty(mexAddress)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerMexAddressNotSpecified))); } if (!string.IsNullOrEmpty(mexSpnIdentity)) { if ((!string.IsNullOrEmpty(mexUpnIdentity)) || (!string.IsNullOrEmpty(mexDnsIdentity))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentityForMex))); } mexIdentity = EndpointIdentity.CreateSpnIdentity(mexSpnIdentity); } else if (!string.IsNullOrEmpty(mexUpnIdentity)) { if ((!string.IsNullOrEmpty(mexSpnIdentity)) || (!string.IsNullOrEmpty(mexDnsIdentity))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentityForMex))); } mexIdentity = EndpointIdentity.CreateUpnIdentity(mexUpnIdentity); } else if (!string.IsNullOrEmpty(mexDnsIdentity)) { if ((!string.IsNullOrEmpty(mexSpnIdentity)) || (!string.IsNullOrEmpty(mexUpnIdentity))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentityForMex))); } mexIdentity = EndpointIdentity.CreateDnsIdentity(mexDnsIdentity); } else { mexIdentity = null; } if (string.IsNullOrEmpty(address)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerAddressNotSpecified))); } if (string.IsNullOrEmpty(contract)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerContractNotSpecified))); } if (string.IsNullOrEmpty(binding)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerBindingNotSpecified))); } if (string.IsNullOrEmpty(bindingNamespace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerBindingNamespacetNotSpecified))); } if (!string.IsNullOrEmpty(spnIdentity)) { if ((!string.IsNullOrEmpty(upnIdentity)) || (!string.IsNullOrEmpty(dnsIdentity))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentity))); } identity = EndpointIdentity.CreateSpnIdentity(spnIdentity); } else if (!string.IsNullOrEmpty(upnIdentity)) { if ((!string.IsNullOrEmpty(spnIdentity)) || (!string.IsNullOrEmpty(dnsIdentity))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentity))); } identity = EndpointIdentity.CreateUpnIdentity(upnIdentity); } else if (!string.IsNullOrEmpty(dnsIdentity)) { if ((!string.IsNullOrEmpty(spnIdentity)) || (!string.IsNullOrEmpty(upnIdentity))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentity))); } identity = EndpointIdentity.CreateDnsIdentity(dnsIdentity); } else { identity = null; } MetadataExchangeClient resolver = null; EndpointAddress mexEndpointAddress = new EndpointAddress(new Uri(mexAddress), mexIdentity); if (!string.IsNullOrEmpty(mexBindingSectionName)) { Binding mexBinding = null; try { mexBinding = ConfigLoader.LookupBinding(mexBindingSectionName, mexBindingConfiguration); } catch (System.Configuration.ConfigurationErrorsException) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MexBindingNotFoundInConfig, mexBindingSectionName))); } if (null == mexBinding) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MexBindingNotFoundInConfig, mexBindingSectionName))); } resolver = new MetadataExchangeClient(mexBinding); } else if (string.IsNullOrEmpty(mexBindingConfiguration)) { resolver = new MetadataExchangeClient(mexEndpointAddress); } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerMexBindingSectionNameNotSpecified))); } if (null != mexIdentity) { // To disable AllowNtlm warning. #pragma warning disable 618 resolver.SoapCredentials.Windows.AllowNtlm = false; #pragma warning restore 618 } bool removeXmlSerializerImporter = false; if (!String.IsNullOrEmpty(serializer)) { if ("xml" != serializer && "datacontract" != serializer) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorectSerializer))); } if ("xml" == serializer) { useXmlSerializer = true; } else { removeXmlSerializerImporter = true; // specifying datacontract will explicitly remove the Xml importer } // if this parameter is not set we will simply use indigo defaults } ServiceEndpoint endpoint = null; ServiceEndpointCollection serviceEndpointsRetrieved = null; WsdlImporter importer; try { MetadataSet metadataSet = resolver.GetMetadata(mexEndpointAddress); if (useXmlSerializer) { importer = CreateXmlSerializerImporter(metadataSet); } else { if (removeXmlSerializerImporter) { importer = CreateDataContractSerializerImporter(metadataSet); } else { importer = new WsdlImporter(metadataSet); } } serviceEndpointsRetrieved = this.ImportWsdlPortType(new XmlQualifiedName(contract, contractNamespace), importer); ComPlusMexChannelBuilderMexCompleteTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationMexMonikerMetadataExchangeComplete, SR.TraceCodeComIntegrationMexMonikerMetadataExchangeComplete, serviceEndpointsRetrieved); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } if (UriSchemeSupportsDisco(mexEndpointAddress.Uri)) { try { DiscoNS.DiscoveryClientProtocol discoClient = new DiscoNS.DiscoveryClientProtocol(); discoClient.UseDefaultCredentials = true; discoClient.AllowAutoRedirect = true; discoClient.DiscoverAny(mexEndpointAddress.Uri.AbsoluteUri); discoClient.ResolveAll(); MetadataSet metadataSet = new MetadataSet(); foreach (object document in discoClient.Documents.Values) { AddDocumentToSet(metadataSet, document); } if (useXmlSerializer) { importer = CreateXmlSerializerImporter(metadataSet); } else { if (removeXmlSerializerImporter) { importer = CreateDataContractSerializerImporter(metadataSet); } else { importer = new WsdlImporter(metadataSet); } } serviceEndpointsRetrieved = this.ImportWsdlPortType(new XmlQualifiedName(contract, contractNamespace), importer); ComPlusMexChannelBuilderMexCompleteTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationMexMonikerMetadataExchangeComplete, SR.TraceCodeComIntegrationMexMonikerMetadataExchangeComplete, serviceEndpointsRetrieved); } catch (Exception ex) { if (Fx.IsFatal(ex)) { throw; } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerFailedToDoMexRetrieve, ex.Message))); } } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerFailedToDoMexRetrieve, e.Message))); } } if (serviceEndpointsRetrieved.Count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerContractNotFoundInRetreivedMex))); } foreach (ServiceEndpoint retrievedEndpoint in serviceEndpointsRetrieved) { Binding bindingSelected = retrievedEndpoint.Binding; if ((bindingSelected.Name == binding) && (bindingSelected.Namespace == bindingNamespace)) { endpoint = retrievedEndpoint; break; } } if (endpoint == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerNoneOfTheBindingMatchedTheSpecifiedBinding))); } contractDescription = endpoint.Contract; this.serviceEndpoint = new ServiceEndpoint(contractDescription, endpoint.Binding, new EndpointAddress(new Uri(address), identity, (AddressHeaderCollection)null)); ComPlusMexChannelBuilderTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationMexChannelBuilderLoaded, SR.TraceCodeComIntegrationMexChannelBuilderLoaded, endpoint.Contract, endpoint.Binding, address); }
internal void ResolveInternal (DiscoveryClientProtocol prot, ServiceDescription wsdl) { if (wsdl.Imports == null) return; foreach (Import import in wsdl.Imports) { // Make relative uris to absoulte Uri uri = new Uri (BaseUri, import.Location); string url = uri.ToString (); if (prot.Documents.Contains (url)) // Already resolved continue; try { string contentType = null; Stream stream = prot.Download (ref url, ref contentType); XmlTextReader reader = new XmlTextReader (url, stream); reader.XmlResolver = null; reader.MoveToContent (); DiscoveryReference refe; if (ServiceDescription.CanRead (reader)) { ServiceDescription refWsdl = ServiceDescription.Read (reader); refe = new ContractReference (); refe.ClientProtocol = prot; refe.Url = url; ((ContractReference)refe).ResolveInternal (prot, refWsdl); prot.Documents.Add (url, refWsdl); } else { XmlSchema schema = XmlSchema.Read (reader, null); refe = new SchemaReference (); refe.ClientProtocol = prot; refe.Url = url; prot.Documents.Add (url, schema); } if (!prot.References.Contains (url)) prot.References.Add (refe); reader.Close (); } catch (Exception ex) { ReportError (url, ex); } } foreach (XmlSchema schema in wsdl.Types.Schemas) { // the schema itself is not added to the // references, but it has to resolve includes. Uri uri = BaseUri; string url = uri.ToString (); SchemaReference refe = new SchemaReference (); refe.ClientProtocol = prot; refe.Url = url; refe.ResolveInternal (prot, schema); } }
void DiscoveredWebServices(DiscoveryClientProtocol protocol) { if (protocol != null) { addButton.Enabled = true; namespaceTextBox.Text = GetDefaultNamespace(); referenceNameTextBox.Text = GetReferenceName(); webServicesView.Add(GetServiceDescriptions(protocol)); webReference = new WebReference(project, discoveryUri.AbsoluteUri, referenceNameTextBox.Text, namespaceTextBox.Text, protocol); } else { webReference = null; addButton.Enabled = false; webServicesView.Clear(); } }
public void Discover () { BindingInfo bnd = (BindingInfo) type_info.Bindings [0]; DiscoveryClientProtocol discoverer = new DiscoveryClientProtocol (); discoverer.Discover (Url); foreach (object info in discoverer.AdditionalInformation) { System.Web.Services.Discovery.SoapBinding sb = info as System.Web.Services.Discovery.SoapBinding; if (sb != null && sb.Binding.Name == bnd.Name && sb.Binding.Namespace == bnd.Namespace) { Url = sb.Address; return; } } string msg = string.Format ("The binding named '{0}' from namespace '{1}' was not found in the discovery document at '{2}'", bnd.Name, bnd.Namespace, Url); throw new Exception (msg); }
/// <summary>Generate a text description for the specified DiscoveryClientProtocol.</summary> /// <param name="protocol">A DiscoveryClientProtocol containing the information for the service.</param> /// <returns>An XmlDocument containing the generated xml for the specified discovery protocol.</returns> public static void GenerateWsdlXml (StringBuilder text, DiscoveryClientProtocol protocol) { // Code Namespace & Compile Unit CodeNamespace codeNamespace = new CodeNamespace(); CodeCompileUnit codeUnit = new CodeCompileUnit(); codeUnit.Namespaces.Add(codeNamespace); // Import and set the warning ServiceDescriptionImporter importer = ReadServiceDescriptionImporter(protocol); importer.Import(codeNamespace, codeUnit); foreach (CodeTypeDeclaration type in codeNamespace.Types) { if (type.BaseTypes.Count == 0 || type.BaseTypes[0].BaseType != "System.Web.Services.Protocols.SoapHttpClientProtocol") continue; text.AppendFormat ("<big><b><u>{0}</u></b></big>\n\n", type.Name); string coms = GetCommentElements (type); if (coms != null) text.Append (coms).Append ("\n\n"); foreach (CodeTypeMember mem in type.Members) { CodeMemberMethod met = mem as CodeMemberMethod; if (met != null && !(mem is CodeConstructor)) { // Method // Asynch Begin & End Results string returnType = met.ReturnType.BaseType; if (met.Name.StartsWith ("Begin") && returnType == "System.IAsyncResult") continue; // BeginXXX method if (met.Name.EndsWith ("Async")) continue; if (met.Name.StartsWith ("On") && met.Name.EndsWith ("Completed")) continue; if (met.Parameters.Count > 0) { CodeParameterDeclarationExpression par = met.Parameters [met.Parameters.Count-1]; if (met.Name.StartsWith ("End") && par.Type.BaseType == "System.IAsyncResult") continue; // EndXXX method } text.AppendFormat ("<b>{0}</b> (", met.Name); // Parameters for (int n=0; n < met.Parameters.Count; n++) { CodeParameterDeclarationExpression par = met.Parameters [n]; if (n > 0) text.Append (", "); text.AppendFormat ("{0}: <i>{1}</i>", par.Name, par.Type.BaseType); } text.Append (")"); if (returnType != "System.Void") text.AppendFormat (": <i>{0}</i>", returnType); // Comments coms = GetCommentElements (met); if (coms != null) text.Append ("\n").Append (coms); text.Append ("\n\n"); } } } }
MetadataSet ResolveWithDisco (string url) { DiscoveryClientProtocol prot = null; Console.WriteLine ("\nAttempting to download metadata from '{0}' using DISCO..", url); try { prot = new DiscoveryClientProtocol (); prot.DiscoverAny (url); prot.ResolveAll (); } catch (Exception e) { Console.WriteLine ("Disco failed for the url '{0}' with exception :\n {1}", url, e.Message); return null; } if (prot.References.Count > 0) { Console.WriteLine ("Disco found documents at the following URLs:"); foreach (DiscoveryReference refe in prot.References.Values) { if (refe is ContractReference) Console.Write ("- WSDL document at "); else if (refe is DiscoveryDocumentReference) Console.Write ("- DISCO document at "); else Console.Write ("- Xml Schema at "); Console.WriteLine (refe.Url); } } else { Console.WriteLine ("Disco didn't find any document at the specified URL"); return null; } MetadataSet metadata = new MetadataSet (); foreach (object o in prot.Documents.Values) { if (o is WSServiceDescrition) { metadata.MetadataSections.Add ( new MetadataSection (MetadataSection.ServiceDescriptionDialect, "", (WSServiceDescrition) o)); } if (o is XmlSchema) { metadata.MetadataSections.Add ( new MetadataSection (MetadataSection.XmlSchemaDialect, "", (XmlSchema) o)); } } return metadata; }