本文整理汇总了C#中System.ServiceModel.Description.WsdlImporter.ImportAllEndpoints方法的典型用法代码示例。如果您正苦于以下问题:C# WsdlImporter.ImportAllEndpoints方法的具体用法?C# WsdlImporter.ImportAllEndpoints怎么用?C# WsdlImporter.ImportAllEndpoints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.Description.WsdlImporter
的用法示例。
在下文中一共展示了WsdlImporter.ImportAllEndpoints方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateCodeDomTree
private static void GenerateCodeDomTree(WsdlImporter wsdlImporter, ServiceContractGenerator contractGenerator)
{
Collection<ContractDescription> contracts = wsdlImporter.ImportAllContracts();
Collection<Binding> bindings = wsdlImporter.ImportAllBindings();
ServiceEndpointCollection endpoints = wsdlImporter.ImportAllEndpoints();
if (wsdlImporter.Errors.Any(e => !e.IsWarning))
{
throw new CodeGenerationException(wsdlImporter.Errors);
}
foreach (ContractDescription contract in contracts)
{
//TODO:Alex:Make the naming scheme customisable.
contract.Name = "I" + contract.Name.Replace("Interface", string.Empty);
contractGenerator.GenerateServiceContractType(contract);
}
foreach (Binding binding in bindings)
{
string bindingSectionName, configurationName;
contractGenerator.GenerateBinding(binding, out bindingSectionName, out configurationName);
}
foreach (ServiceEndpoint endpoint in endpoints)
{
ChannelEndpointElement channelElement;
contractGenerator.GenerateServiceEndpoint(endpoint, out channelElement);
}
}
示例2: UseWcf
static void UseWcf()
{
/*
动态下载服务元数据
*/
MetadataExchangeClient metaExchangeClient =
new MetadataExchangeClient(
new Uri("http://localhost:8002/ManualService"),
MetadataExchangeClientMode.HttpGet
);
//下载元数据
MetadataSet metadataSet = metaExchangeClient.GetMetadata();
WsdlImporter importer = new WsdlImporter(metadataSet);
ServiceEndpointCollection endpointCollection = importer.ImportAllEndpoints();
IManulService manulProxy = null;
foreach (ServiceEndpoint endPointItem in endpointCollection)
{
manulProxy = new ChannelFactory<IManulService>(
endPointItem.Binding,
endPointItem.Address
).CreateChannel();
((IChannel)manulProxy).Open();
Console.WriteLine("WCF调用结果为:{0}",
manulProxy.GetData());
((IChannel)manulProxy).Close();
}
}
示例3: QueryMexEndpoint
static ServiceEndpointCollection QueryMexEndpoint(string mexAddress, BindingElement bindingElement)
{
var binding = new CustomBinding(bindingElement);
var MEXClient = new MetadataExchangeClient(binding);
var metadata = MEXClient.GetMetadata(new EndpointAddress(mexAddress));
var importer = new WsdlImporter(metadata);
return importer.ImportAllEndpoints();
}
示例4: ImportMetadata
public ServiceMetadataInformation ImportMetadata(Collection<MetadataSection> metadataCollection, MetadataImporterSerializerFormatMode formatMode)
{
CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
CodeDomProvider codeDomProvider = m_CodeDomProviderFactory.CreateProvider();
WsdlImporter importer = new WsdlImporter(new MetadataSet(metadataCollection));
switch (formatMode)
{
case MetadataImporterSerializerFormatMode.DataContractSerializer:
AddStateForDataContractSerializerImport(importer, formatMode, codeCompileUnit, codeDomProvider);
break;
case MetadataImporterSerializerFormatMode.XmlSerializer:
AddStateForXmlSerializerImport(importer, codeCompileUnit, codeDomProvider);
break;
case MetadataImporterSerializerFormatMode.Auto:
AddStateForDataContractSerializerImport(importer, formatMode, codeCompileUnit, codeDomProvider);
AddStateForXmlSerializerImport(importer, codeCompileUnit, codeDomProvider);
break;
}
if (!importer.State.ContainsKey(typeof(WrappedOptions)))
{
importer.State.Add(typeof(WrappedOptions), new WrappedOptions
{
WrappedFlag = false
});
}
Collection<Binding> bindings = importer.ImportAllBindings();
Collection<ContractDescription> contracts = importer.ImportAllContracts();
ServiceEndpointCollection endpoints = importer.ImportAllEndpoints();
Collection<MetadataConversionError> importErrors = importer.Errors;
bool success = true;
if (importErrors != null)
{
foreach (MetadataConversionError error in importErrors)
{
if (!error.IsWarning)
{
success = false;
break;
}
}
}
if (!success)
{
//TODO: Throw exception
}
return new ServiceMetadataInformation(codeCompileUnit, codeDomProvider)
{
Bindings = bindings,
Contracts = contracts,
Endpoints = endpoints
};
}
示例5: Run
public static void Run(Uri uri, string cache)
{
ServicePointManager.ServerCertificateValidationCallback = Validator;
MetadataSet doc;
string tempfile = null;
bool needsDownload;
if (cache == null) {
needsDownload = true;
tempfile = Path.GetTempFileName ();
cache = tempfile;
} else {
needsDownload = !File.Exists (cache);
}
if (needsDownload) {
Console.WriteLine ("Downloading service metadata ...");
DownloadXml (uri, cache);
Console.WriteLine ("Downloaded service metadata into {0}.", cache);
}
try {
doc = LoadMetadata (uri, cache);
} finally {
if (tempfile != null)
File.Delete (tempfile);
}
var importer = new WsdlImporter (doc);
var bindings = importer.ImportAllBindings ();
var endpoints = importer.ImportAllEndpoints ();
foreach (var error in importer.Errors) {
if (error.IsWarning)
Console.WriteLine ("WARNING: {0}", error.Message);
else
Console.WriteLine ("ERROR: {0}", error.Message);
}
Console.WriteLine ("DONE IMPORTING: {0} {1}", bindings.Count, endpoints.Count);
foreach (var binding in bindings)
Console.WriteLine ("BINDING: {0}", binding);
foreach (var endpoint in endpoints)
Console.WriteLine ("ENDPOINT: {0}", endpoint.Address);
foreach (var endpoint in endpoints) {
try {
Run (endpoint);
} catch (Exception ex) {
Console.WriteLine ("ERROR ({0}): {1}", endpoint.Address, ex);
}
}
}
示例6: QueryMexEndpoint
static ServiceEndpointCollection QueryMexEndpoint(string mexAddress,Binding binding,TokenProvider tokenProvider)
{
dynamic extendedBinding = binding;
extendedBinding.MaxReceivedMessageSize *= MessageSizeMultiplier;
MetadataExchangeClient mexClient = new MetadataExchangeClient(extendedBinding);
mexClient.SetServiceBusCredentials(tokenProvider);
MetadataSet metadata = mexClient.GetMetadata(new EndpointAddress(mexAddress));
MetadataImporter importer = new WsdlImporter(metadata);
return importer.ImportAllEndpoints();
}
示例7: QueryMexEndpoint
static ServiceEndpointCollection QueryMexEndpoint(string mexAddress,BindingElement bindingElement)
{
dynamic element = bindingElement;
element.MaxReceivedMessageSize *= MessageSizeMultiplier;
CustomBinding binding = new CustomBinding(element);
MetadataExchangeClient mexClient = new MetadataExchangeClient(binding);
MetadataSet metadata = mexClient.GetMetadata(new EndpointAddress(mexAddress));
MetadataImporter importer = new WsdlImporter(metadata);
return importer.ImportAllEndpoints();
}
示例8: GenerateFromWsdl
public static void GenerateFromWsdl(Uri uri, string wsdlFilename,
string xmlFilename, string xsdFilename)
{
var doc = Utils.LoadMetadata (uri, wsdlFilename);
var importer = new WsdlImporter (doc);
var endpoints = importer.ImportAllEndpoints ();
var config = new Configuration ();
foreach (var endpoint in endpoints)
config.AddEndpoint (endpoint);
Generator.Write (xmlFilename, xsdFilename, config);
}
示例9: GenerateConfig
public static void GenerateConfig(MetadataSet metadata, Configuration config)
{
WsdlImporter importer = new WsdlImporter (metadata);
var endpoints = importer.ImportAllEndpoints ();
var generator = new ServiceContractGenerator (config);
generator.Options = ServiceContractGenerationOptions.None;
foreach (var endpoint in endpoints) {
ChannelEndpointElement channelElement;
generator.GenerateServiceEndpoint (endpoint, out channelElement);
}
}
示例10: Main
static void Main(string[] args)
{
Binding binding = MetadataExchangeBindings.CreateMexHttpBinding();
EndpointAddress address = new EndpointAddress("http://127.0.0.1:9999/calculatorservice/mex");
MetadataExchangeClient metadataExchangeClient = new MetadataExchangeClient(binding);
MetadataSet metadata = metadataExchangeClient.GetMetadata(address);
WsdlImporter wsdlImporter = new WsdlImporter(metadata);
//添加已知契约类型
ContractDescription contract = ContractDescription.GetContract(typeof(ICalculator));
wsdlImporter.KnownContracts.Add(new XmlQualifiedName(contract.Name, contract.Namespace), contract);
ServiceEndpointCollection endpoints = wsdlImporter.ImportAllEndpoints();
using (ChannelFactory<ICalculator> channelFactory = new ChannelFactory<ICalculator>(endpoints[0]))
{
ICalculator calculator = channelFactory.CreateChannel();
Console.WriteLine("x + y = {2} when x = {0} and y = {1}", 1, 2, calculator.Add(1, 2));
}
Console.Read();
}
示例11: WebService
public WebService(string path)
{
var metadataAddress = new EndpointAddress(path);
var mexClient = new MetadataExchangeClient(metadataAddress.Uri, MetadataExchangeClientMode.HttpGet);
mexClient.ResolveMetadataReferences = true;
var metadata = mexClient.GetMetadata(metadataAddress.Uri, MetadataExchangeClientMode.HttpGet);
var metadataSet = new MetadataSet(metadata.MetadataSections);
var importer = new WsdlImporter(metadataSet);
AllWsdlDocuments = importer.WsdlDocuments;
AllContracts = importer.ImportAllContracts();
AllBindings = importer.ImportAllBindings();
AllEndpoints = importer.ImportAllEndpoints();
//AllContracts.First().Operations.First().
}
示例12: QueryMexEndpoint
static ServiceEndpointCollection QueryMexEndpoint(string mexAddress,Binding binding,string issuer,string secret)
{
Binding extendedBinding = null;
if(binding is NetTcpRelayBinding)
{
NetTcpRelayBinding actualBinding = binding as NetTcpRelayBinding;
actualBinding.MaxReceivedMessageSize *= MessageSizeMultiplier;
extendedBinding = actualBinding;
}
if(binding is WS2007HttpRelayBinding)
{
WS2007HttpRelayBinding actualBinding = binding as WS2007HttpRelayBinding;
actualBinding.MaxReceivedMessageSize *= MessageSizeMultiplier;
extendedBinding = actualBinding;
}
MetadataExchangeClient mexClient = new MetadataExchangeClient(extendedBinding);
mexClient.SetServiceBusCredentials(issuer,secret);
MetadataSet metadata = mexClient.GetMetadata(new EndpointAddress(mexAddress));
MetadataImporter importer = new WsdlImporter(metadata);
return importer.ImportAllEndpoints();
}
示例13: Main
static void Main()
{
// Create a MetadataExchangeClient for retrieving metadata.
EndpointAddress mexAddress = new EndpointAddress(ConfigurationManager.AppSettings["mexAddress"]);
MetadataExchangeClient mexClient = new MetadataExchangeClient(mexAddress);
// Retrieve the metadata for all endpoints using metadata exchange protocol (mex).
MetadataSet metadataSet = mexClient.GetMetadata();
//Convert the metadata into endpoints
WsdlImporter importer = new WsdlImporter(metadataSet);
ServiceEndpointCollection endpoints = importer.ImportAllEndpoints();
CalculatorClient client = null;
ContractDescription contract = ContractDescription.GetContract(typeof(ICalculator));
// Communicate with each endpoint that supports the ICalculator contract.
foreach (ServiceEndpoint ep in endpoints)
{
if (ep.Contract.Namespace.Equals(contract.Namespace) && ep.Contract.Name.Equals(contract.Name))
{
// Create a client using the endpoint address and binding.
client = new CalculatorClient(ep.Binding, new EndpointAddress(ep.Address.Uri));
Console.WriteLine("Communicate with endpoint: ");
Console.WriteLine(" AddressPath={0}", ep.Address.Uri.PathAndQuery);
Console.WriteLine(" Binding={0}", ep.Binding.Name);
// call operations
DoCalculations(client);
//Closing the client gracefully closes the connection and cleans up resources
client.Close();
}
}
Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate client.");
Console.ReadLine();
}
示例14: ImportMetadata
private void ImportMetadata(WsdlImporter wsdlImporter,
out ServiceEndpointCollection endpoints,
out Collection<System.ServiceModel.Channels.Binding> bindings,
out Collection<ContractDescription> contracts)
{
endpoints = wsdlImporter.ImportAllEndpoints();
bindings = wsdlImporter.ImportAllBindings();
contracts = wsdlImporter.ImportAllContracts();
ThrowOnMetadataConversionErrors(wsdlImporter.Errors);
}
示例15: GetEndpoints
public static ServiceEndpoint[] GetEndpoints(string mexAddress)
{
if(string.IsNullOrWhiteSpace(mexAddress))
{
throw new ArgumentException("mexAddress");
}
Uri address = new Uri(mexAddress);
ServiceEndpointCollection endpoints = null;
BindingElement bindingElement = null;
//Try over HTTP-GET first
if(address.Scheme == Uri.UriSchemeHttp || address.Scheme == Uri.UriSchemeHttps)
{
string getAddress = mexAddress;
if(mexAddress.EndsWith("?wsdl") == false)
{
getAddress += "?wsdl";
}
if(address.Scheme == Uri.UriSchemeHttp)
{
HttpTransportBindingElement httpBindingElement = new HttpTransportBindingElement();
httpBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier;
bindingElement = httpBindingElement;
}
else
{
HttpsTransportBindingElement httpsBindingElement = new HttpsTransportBindingElement();
httpsBindingElement.MaxReceivedMessageSize *= MessageSizeMultiplier;
bindingElement = httpsBindingElement;
}
CustomBinding binding = new CustomBinding(bindingElement);
MetadataExchangeClient mexClient = new MetadataExchangeClient(binding);
MetadataSet metadata = mexClient.GetMetadata(new Uri(getAddress),MetadataExchangeClientMode.HttpGet);
MetadataImporter importer = new WsdlImporter(metadata);
endpoints = importer.ImportAllEndpoints();
return endpoints.ToArray();
}
//Try MEX endpoint:
if(address.Scheme == Uri.UriSchemeHttp)
{
bindingElement = new HttpTransportBindingElement();
}
if(address.Scheme == Uri.UriSchemeHttps)
{
bindingElement = new HttpsTransportBindingElement();
}
if(address.Scheme == Uri.UriSchemeNetTcp)
{
bindingElement = new TcpTransportBindingElement();
}
if(address.Scheme == Uri.UriSchemeNetPipe)
{
bindingElement = new NamedPipeTransportBindingElement();
}
endpoints = QueryMexEndpoint(mexAddress,bindingElement);
return endpoints.ToArray();
}