本文整理汇总了C#中System.Web.Services.Discovery.DiscoveryClientProtocol.DiscoverAny方法的典型用法代码示例。如果您正苦于以下问题:C# DiscoveryClientProtocol.DiscoverAny方法的具体用法?C# DiscoveryClientProtocol.DiscoverAny怎么用?C# DiscoveryClientProtocol.DiscoverAny使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Services.Discovery.DiscoveryClientProtocol
的用法示例。
在下文中一共展示了DiscoveryClientProtocol.DiscoverAny方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DownloadFile
//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);
}
}
}
示例2: DiscoResolve
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;
}
示例3: DiscoverWebServiceMetadata
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);
}
示例4: GetServiceDescription
/// <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;
}
示例5: DiscoverDocuments
DiscoveryClientDocumentCollection DiscoverDocuments()
{
var protocol = new DiscoveryClientProtocol {
AllowAutoRedirect = true,
Credentials = credentials ?? CredentialCache.DefaultCredentials
};
protocol.DiscoverAny(uri);
protocol.ResolveAll();
return protocol.Documents;
}
示例6: Resolve
/// <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;
}
示例7: ReadWriteTest
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);
}
}
示例8: DownloadMetadata
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;
}
示例9: Generate
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);
}
示例10: GenerateWebServiceProxyAssembly
private Assembly GenerateWebServiceProxyAssembly(string NameSpace, string ClassName)
{
object obj = null;
Assembly assembly;
DiscoveryClientProtocol discoveryClientProtocol = new DiscoveryClientProtocol();
if (this._usedefaultcredential.IsPresent)
{
discoveryClientProtocol.UseDefaultCredentials = true;
}
if (base.ParameterSetName.Equals("Credential", StringComparison.OrdinalIgnoreCase))
{
discoveryClientProtocol.Credentials = this._credential.GetNetworkCredential();
}
try
{
discoveryClientProtocol.AllowAutoRedirect = true;
discoveryClientProtocol.DiscoverAny(this._uri.ToString());
discoveryClientProtocol.ResolveAll();
goto Label0;
}
catch (WebException webException1)
{
WebException webException = webException1;
ErrorRecord errorRecord = new ErrorRecord(webException, "WebException", ErrorCategory.ObjectNotFound, this._uri);
if (webException.InnerException != null)
{
errorRecord.ErrorDetails = new ErrorDetails(webException.InnerException.Message);
}
base.WriteError(errorRecord);
assembly = null;
}
catch (InvalidOperationException invalidOperationException1)
{
InvalidOperationException invalidOperationException = invalidOperationException1;
ErrorRecord errorRecord1 = new ErrorRecord(invalidOperationException, "InvalidOperationException", ErrorCategory.InvalidOperation, this._uri);
base.WriteError(errorRecord1);
assembly = null;
}
return assembly;
Label0:
CodeNamespace codeNamespace = new CodeNamespace();
if (!string.IsNullOrEmpty(NameSpace))
{
codeNamespace.Name = NameSpace;
}
if (!string.IsNullOrEmpty(ClassName))
{
CodeTypeDeclaration codeTypeDeclaration = new CodeTypeDeclaration(ClassName);
codeTypeDeclaration.IsClass = true;
codeTypeDeclaration.Attributes = MemberAttributes.Public;
codeNamespace.Types.Add(codeTypeDeclaration);
}
WebReference webReference = new WebReference(discoveryClientProtocol.Documents, codeNamespace);
WebReferenceCollection webReferenceCollection = new WebReferenceCollection();
webReferenceCollection.Add(webReference);
CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
codeCompileUnit.Namespaces.Add(codeNamespace);
WebReferenceOptions webReferenceOption = new WebReferenceOptions();
webReferenceOption.CodeGenerationOptions = CodeGenerationOptions.GenerateProperties | CodeGenerationOptions.GenerateNewAsync | CodeGenerationOptions.GenerateOldAsync;
webReferenceOption.Verbose = true;
CSharpCodeProvider cSharpCodeProvider = new CSharpCodeProvider();
StringCollection stringCollections = ServiceDescriptionImporter.GenerateWebReferences(webReferenceCollection, cSharpCodeProvider, codeCompileUnit, webReferenceOption);
StringBuilder stringBuilder = new StringBuilder();
StringWriter stringWriter = new StringWriter(stringBuilder, CultureInfo.InvariantCulture);
try
{
cSharpCodeProvider.GenerateCodeFromCompileUnit(codeCompileUnit, stringWriter, null);
}
catch (NotImplementedException notImplementedException1)
{
NotImplementedException notImplementedException = notImplementedException1;
ErrorRecord errorRecord2 = new ErrorRecord(notImplementedException, "NotImplementedException", ErrorCategory.ObjectNotFound, this._uri);
base.WriteError(errorRecord2);
}
this.sourceHash = stringBuilder.ToString().GetHashCode();
if (!NewWebServiceProxy.srccodeCache.ContainsKey(this.sourceHash))
{
CompilerParameters compilerParameter = new CompilerParameters();
CompilerResults compilerResult = null;
foreach (string str in stringCollections)
{
base.WriteWarning(str);
}
compilerParameter.ReferencedAssemblies.Add("System.dll");
compilerParameter.ReferencedAssemblies.Add("System.Data.dll");
compilerParameter.ReferencedAssemblies.Add("System.Xml.dll");
compilerParameter.ReferencedAssemblies.Add("System.Web.Services.dll");
compilerParameter.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);
this.GetReferencedAssemblies(typeof(Cmdlet).Assembly, compilerParameter);
compilerParameter.GenerateInMemory = true;
compilerParameter.TreatWarningsAsErrors = false;
compilerParameter.WarningLevel = 4;
compilerParameter.GenerateExecutable = false;
try
{
string[] strArrays = new string[1];
strArrays[0] = stringBuilder.ToString();
compilerResult = cSharpCodeProvider.CompileAssemblyFromSource(compilerParameter, strArrays);
}
catch (NotImplementedException notImplementedException3)
//.........这里部分代码省略.........
示例11: ImportServiceDescription
private static CodeCompileUnit ImportServiceDescription(string url)
{
ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
importer.ProtocolName = "Soap";
importer.Style = ServiceDescriptionImportStyle.Client;
DiscoveryClientProtocol dcc = new DiscoveryClientProtocol();
dcc.DiscoverAny(url);
dcc.ResolveAll();
foreach (object doc in dcc.Documents.Values)
{
if(doc is ServiceDescription)
importer.AddServiceDescription(doc as ServiceDescription, string.Empty, string.Empty);
else if(doc is XmlSchema)
importer.Schemas.Add(doc as XmlSchema);
}
if (importer.ServiceDescriptions.Count == 0)
{
throw new Exception("No WSDL document was found at the url " + url);
}
CodeCompileUnit ccu = new CodeCompileUnit();
ccu.Namespaces.Add(new CodeNamespace(RootNamespace));
ServiceDescriptionImportWarnings warnings = importer.Import(ccu.Namespaces[0], ccu);
if ((warnings & ServiceDescriptionImportWarnings.NoCodeGenerated) > 0)
{
throw new Exception("No code generated");
}
return ccu;
}
示例12: GetWsDocuments
/// <summary>
/// Gets XML Web Services documents from a Spring resource.
/// </summary>
private DiscoveryClientDocumentCollection GetWsDocuments(IResource resource)
{
try
{
if (ServiceUri is UrlResource ||
ServiceUri is FileSystemResource)
{
DiscoveryClientProtocol dcProtocol = new DiscoveryClientProtocol();
dcProtocol.AllowAutoRedirect = true;
dcProtocol.Credentials = CreateCredentials();
dcProtocol.Proxy = ConfigureProxy();
dcProtocol.DiscoverAny(resource.Uri.AbsoluteUri);
dcProtocol.ResolveAll();
return dcProtocol.Documents;
}
else
{
DiscoveryClientDocumentCollection dcdc = new DiscoveryClientDocumentCollection();
dcdc[resource.Description] = ServiceDescription.Read(resource.InputStream);
return dcdc;
}
}
catch (Exception ex)
{
throw new ArgumentException(String.Format("Couldn't retrieve the description of the web service located at '{0}'.", resource.Description), ex);
}
}
示例13: CheckForImports
/// <summary>
/// Checks the for imports.
/// </summary>
/// <param name="baseWSDLUrl">Base WSDL URL.</param>
private void CheckForImports(string baseWSDLUrl)
{
DiscoveryClientProtocol dcp = new DiscoveryClientProtocol();
//DEBUG code
try
{
dcp.DiscoverAny(baseWSDLUrl);
dcp.ResolveAll();
}
catch(UriFormatException ex)
{
throw new ApplicationException("Not a valid wsdl location: " + baseWSDLUrl, ex);
}
foreach (object osd in dcp.Documents.Values)
{
if (osd is ServiceDescription) sdi.AddServiceDescription((ServiceDescription)osd, null, null);
if (osd is XmlSchema)
{
// store in global schemas variable
if (schemas == null) schemas = new XmlSchemas();
schemas.Add((XmlSchema)osd);
sdi.Schemas.Add((XmlSchema)osd);
}
}
}
示例14: DoMex
//.........这里部分代码省略.........
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);
}
示例15: ResolveWithDisco
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;
}