本文整理汇总了C#中System.ServiceModel.Description.WsdlImporter.ImportEndpoint方法的典型用法代码示例。如果您正苦于以下问题:C# WsdlImporter.ImportEndpoint方法的具体用法?C# WsdlImporter.ImportEndpoint怎么用?C# WsdlImporter.ImportEndpoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.Description.WsdlImporter
的用法示例。
在下文中一共展示了WsdlImporter.ImportEndpoint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BasicHttpBinding_ImportEndpoint
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 ());
}
示例2: ImportWCFModel
/// <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));
}
}
示例3: BasicHttpBinding_Error2
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 ();
}