public void ResolveBadUri() { MetadataResolver.Resolve( typeof(IEchoService), new EndpointAddress("http://localhost")); }
public static void Main() { try { SampleServiceClient wcfClient; // Client has an endpoint for metadata EndpointAddress metaAddress = new EndpointAddress(new Uri("http://localhost:8080/SampleService/mex")); EndpointAddress httpGetMetaAddress = new EndpointAddress(new Uri("http://localhost:8080/SampleService?wsdl")); // <snippet1> // Get the endpoints for such a service ServiceEndpointCollection endpoints = MetadataResolver.Resolve(typeof(SampleServiceClient), metaAddress); Console.WriteLine("Trying all available WS-Transfer metadata endpoints..."); foreach (ServiceEndpoint point in endpoints) { if (point != null) { // Create a new wcfClient using retrieved endpoints. wcfClient = new SampleServiceClient(point.Binding, point.Address); Console.WriteLine( wcfClient.SampleMethod("Client used the " + point.Address.ToString() + " address.") ); wcfClient.Close(); } } // </snippet1> // <snippet2> // Get the endpoints for such a service using Http/Get request endpoints = MetadataResolver.Resolve(typeof(SampleServiceClient), httpGetMetaAddress.Uri, MetadataExchangeClientMode.HttpGet); Client.WriteParameters(endpoints); ISampleService serviceChannel; Console.WriteLine( "\r\nTrying all endpoints from HTTP/Get and with direct service channels..."); foreach (ServiceEndpoint point in endpoints) { if (point != null) { ChannelFactory <ISampleService> factory = new ChannelFactory <ISampleService>(point.Binding); factory.Endpoint.Address = point.Address; serviceChannel = factory.CreateChannel(); Console.WriteLine("Client used the " + point.Address.ToString() + " address."); Console.WriteLine( serviceChannel.SampleMethod( "Client used the " + point.Address.ToString() + " address." ) ); factory.Close(); } } // </snippet2> // <snippet3> // Get metadata documents. Console.WriteLine("URI of the metadata documents retreived:"); MetadataExchangeClient metaTransfer = new MetadataExchangeClient(httpGetMetaAddress.Uri, MetadataExchangeClientMode.HttpGet); metaTransfer.ResolveMetadataReferences = true; MetadataSet otherDocs = metaTransfer.GetMetadata(); foreach (MetadataSection doc in otherDocs.MetadataSections) { Console.WriteLine(doc.Dialect + " : " + doc.Identifier); } // </snippet3> Console.WriteLine("Press ENTER to exit..."); Console.ReadLine(); } catch (TimeoutException timeProblem) { Console.WriteLine("The service operation timed out. " + timeProblem.Message); } catch (FaultException unkException) { Console.WriteLine(unkException.Message); Console.ReadLine(); } catch (CommunicationException commProblem) { Console.WriteLine("There was a communication problem. " + commProblem.Message); } }
public void ResolveNonContract() { MetadataResolver.Resolve( typeof(Int32), new EndpointAddress(url)); }
/// <summary> /// Gets the notification target method, market with a <see cref="NotifyTarget"/> attribute. /// </summary> /// <param name="typeDef">The type definition.</param> /// <returns>MethodReference.</returns> protected MethodReference GetNotifyTarget(TypeDefinition typeDef) { //Check each method for a NotifyTargetAttribute foreach (var methDef in typeDef.Methods) { if (methDef.ContainsAttribute(typeof(NotifyTarget))) { var isValid = false; switch (methDef.Parameters.Count) { //Passes nothing case 0: isValid = true; break; //Passes property name case 1: isValid = methDef.Parameters[0].ParameterType.FullName == typeof(string).FullName; break; //Passes property name & value being set case 2: isValid = methDef.Parameters[0].ParameterType.FullName == typeof(string).FullName && methDef.Parameters[1].ParameterType.FullName == typeof(object).FullName; break; } if (isValid) { return(methDef); } else { throw new InvalidNotifyTargetException(methDef.FullName); } } } //Notify target not found, search base type var baseType = typeDef.BaseType; if (baseType != null) { //Get the definition of the base type var baseTypeDef = metadataResolver.Resolve(baseType); //Search recursively for a target var rtn = GetNotifyTarget(baseTypeDef); if (rtn != null) { //A target has been found, import a reference to the target method; rtn = typeDef.Module.ImportReference(rtn); } return(rtn); } else { return(null); } }