![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br>
|
|
|||||||
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||
|
Guest
Posts: n/a
|
Running the following code snippet with this line commented:
Form form = new Form(); Yields the expected results: writes "DisplayMessage" on the console. However, the call to MetadataResolver.Resolve() takes at least about 4 seconds to complete. Why? With the above line uncommented (i.e., with the form created), the call to MetadataResolver.Resolve() fails by timeout ("Metadata contains a reference that cannot be resolved"). Why? I suspect deadlock, but can't explain it. Visual Studio 2005 Microsoft .NET Framework, Version 2.0.50727.1433 System.ServiceModel 3.0.0.0 **** CODE FOLLOWS *** using System; using System.Diagnostics; using System.ServiceModel; using System.ServiceModel.Description; using System.Windows.Forms; namespace WcfForm { class Program { private static void Log(string message) { Console.Out.WriteLine(DateTime.Now + ": " + message); } static void Main(string[] args) { Log("Setup service..."); try { // Uncommenting this line will cause the // MetadataResolver.Resolve() call to fail. // Why? //Form form = new Form(); string localAddress = "net.pipe://localhost/IService"; string mex = "Mex"; Type serviceType = typeof(Service); Type contractType = typeof(IService); ServiceHost serviceHost = new ServiceHost( serviceType, new Uri[] { new Uri(localAddress) }); // add the named pipe service endpoint for local clients serviceHost.AddServiceEndpoint( contractType, new NetNamedPipeBinding(), localAddress); // add the metadata behavior ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior(); serviceHost.Description.Behaviors.Add(metadataBehavior); // add the metadata named pipe endpoint for local clients serviceHost.AddServiceEndpoint( typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexNamedPipeBinding(), mex); // start the service Log("Call serviceHost.Open()..."); serviceHost.Open(); Log("Service started."); // resolve the endpoints for the locally hosted service // this call takes at least about 4 seconds to complete when // the form is not created and fails with a timeouts out // when the form is created. why? Log("Call MetadataResolver.Resolve()..."); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); ServiceEndpointCollection endpoints = MetadataResolver.Resolve( contractType, new EndpointAddress(localAddress + "/" + mex)); stopwatch.Stop(); Log("Call to MetadataResolver.Resolve() took " + stopwatch.Elapsed.Seconds + " sec. " + stopwatch.Elapsed.Milliseconds + " ms."); if (endpoints != null) { foreach (ServiceEndpoint endpoint in endpoints) { Log(endpoint.Address.ToString()); } } // create proxy and call service Log("Create proxy ..."); ChannelFactory<IService> factory = new ChannelFactory<IService>(new NetNamedPipeBinding(), localAddress); IService plugin = factory.CreateChannel() as IService; if (plugin != null) { plugin.DisplayMessage(); } } catch (Exception ex) { // when form is created, this code fails by timeout // "Metadata contains a reference that cannot be resolved" Log(ex.Message); } Console.ReadKey(); } } [ServiceContract] public interface IService { [OperationContract] void DisplayMessage(); } public class Service : IService { public Service() { } public void DisplayMessage() { Console.WriteLine("DisplayMessage"); } } } **** END CODE *** |
||
|
|
|
|