public void BasicHttpBinding_ImportEndpoint () { var label = new TestLabel ("BasicHttpBinding_ImportEndpoint"); var doc = TestContext.LoadMetadata ("BasicHttp"); var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata; label.EnterScope ("wsdl"); Assert.That (sd.Services, Is.Not.Null, label.Get ()); Assert.That (sd.Services.Count, Is.EqualTo (1), label.Get ()); var service = sd.Services [0]; Assert.That (service.Ports, Is.Not.Null, label.Get ()); Assert.That (service.Ports.Count, Is.EqualTo (1), label.Get ()); label.LeaveScope (); var importer = new WsdlImporter (doc); var port = importer.ImportEndpoint (service.Ports [0]); BindingTestAssertions.CheckImportErrors (importer, label); Assert.That (port, Is.Not.Null, label.Get ()); }
/// <summary> /// Given a WSDL importer, a set of metadata files and a compile unit, import the metadata /// files. /// </summary> /// <param name="importer"></param> /// <param name="compileUnit"></param> /// <param name="generationErrors"> /// Errors encountered whie importing the model. Any new errors will be appended to this list. /// </param> /// <param name="serviceEndpointList">List of endpoints imported</param> /// <param name="bindingCollection">The collection of bindings imported</param> /// <param name="contractCollection">The collection of contracts imported</param> protected static void ImportWCFModel(WsdlImporter importer, System.CodeDom.CodeCompileUnit compileUnit, IList<ProxyGenerationError> generationErrors, out List<ServiceEndpoint> serviceEndpointList, out IEnumerable<System.ServiceModel.Channels.Binding> bindingCollection, out IEnumerable<ContractDescription> contractCollection) { // We want to remove soap1.2 endpoints for ASMX references, but we can't use the "normal" way // of using a IWsdlImportExtension to do so since BeforeImport is called too late (DevDiv 7857) // If DevDiv 7857 is fixed, we can remove the following two lines and instead add the // AsmxEndpointPickerExtension to the importer's wsdl import extensions... IWsdlImportExtension asmxFixerUpper = new AsmxEndpointPickerExtension(); asmxFixerUpper.BeforeImport(importer.WsdlDocuments, null, null); // NOTE: we should import Endpoint before Contracts, otherwise some information (related to binding) will be lost in the model (devdiv: 22396) serviceEndpointList = new List<ServiceEndpoint>(); // // First we import all the endpoints (ports). This is required so that any WsdlImportExtension's BeforeImport // gets called before we actually try to import anything from the WSDL object model. // If we don't do this, we run into problems if any wsdl import extensions want to delete a specific port // and this port happens to be the first port we try to import (you can't interrupt the import) importer.ImportAllEndpoints(); // // We need to go through each endpoint element and "re-import" it in order to get the mapping // between the wsdlPort and the ServiceEndpoint... Importing the same endpoint twice is a no-op // as far as the endpoint collection is concerned - it is simply a hashtable lookup to retreive // the already generated information... // foreach (System.Web.Services.Description.ServiceDescription wsdlServiceDescription in importer.WsdlDocuments) { foreach (System.Web.Services.Description.Service wsdlService in wsdlServiceDescription.Services) { foreach (System.Web.Services.Description.Port servicePort in wsdlService.Ports) { try { ServiceEndpoint newEndpoint = importer.ImportEndpoint(servicePort); serviceEndpointList.Add(newEndpoint); } catch (InvalidOperationException) { // Invalid operation exceptions should already be in the errors collection for the importer, so we don't // need to add another generationError. The most probable cause for this is that the we failed to import // the endpoint... } catch (Exception ex) { // It is bad, because WsdlImporter.WsdlImportException is a private class generationErrors.Add(new ProxyGenerationError(ProxyGenerationError.GeneratorState.GenerateCode, wsdlServiceDescription.RetrievalUrl, ex)); } } } } bindingCollection = importer.ImportAllBindings(); System.Diagnostics.Debug.Assert(bindingCollection != null, "The importer should never return a NULL binding collection!"); contractCollection = importer.ImportAllContracts(); System.Diagnostics.Debug.Assert(contractCollection != null, "The importer should never return a NULL contract collection!"); foreach (MetadataConversionError error in importer.Errors) { generationErrors.Add(new ProxyGenerationError(error)); } }
public void BasicHttpBinding_Error2 () { var label = new TestLabel ("BasicHttpBinding_Error2"); var doc = TestContext.LoadMetadata ("http-error.xml"); var sd = (WS.ServiceDescription)doc.MetadataSections [0].Metadata; label.EnterScope ("wsdl"); Assert.That (sd.Services, Is.Not.Null, label.Get ()); Assert.That (sd.Services.Count, Is.EqualTo (1), label.Get ()); var service = sd.Services [0]; Assert.That (service.Ports, Is.Not.Null, label.Get ()); Assert.That (service.Ports.Count, Is.EqualTo (1), label.Get ()); label.LeaveScope (); var importer = new WsdlImporter (doc); label.EnterScope ("all"); var endpoints = importer.ImportAllEndpoints (); Assert.That (endpoints, Is.Not.Null, label.Get ()); Assert.That (endpoints.Count, Is.EqualTo (0), label.Get ()); label.EnterScope ("errors"); Assert.That (importer.Errors, Is.Not.Null, label.Get ()); Assert.That (importer.Errors.Count, Is.EqualTo (2), label.Get ()); Assert.That (importer.Errors [0].IsWarning, Is.False, label.Get ()); Assert.That (importer.Errors [1].IsWarning, Is.False, label.Get ()); label.LeaveScope (); label.LeaveScope (); label.EnterScope ("single"); try { importer.ImportEndpoint (service.Ports [0]); Assert.Fail (label.Get ()); } catch { ; } Assert.That (importer.Errors.Count, Is.EqualTo (2), label.Get ()); label.LeaveScope (); label.EnterScope ("single-first"); var importer2 = new WsdlImporter (doc); try { importer2.ImportEndpoint (service.Ports [0]); Assert.Fail (label.Get ()); } catch { ; } Assert.That (importer2.Errors.Count, Is.EqualTo (2), label.Get ()); try { importer2.ImportEndpoint (service.Ports [0]); Assert.Fail (label.Get ()); } catch { ; } var endpoints2 = importer.ImportAllEndpoints (); Assert.That (endpoints2, Is.Not.Null, label.Get ()); Assert.That (endpoints2.Count, Is.EqualTo (0), label.Get ()); label.LeaveScope (); }