Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - Why does MetadataResolver.Resolve() timeout when creating a newWindows Form?

 
 
Old 01-30-2008   #1 (permalink)
fstarnaud


 
 

Why does MetadataResolver.Resolve() timeout when creating a newWindows Form?

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 ***

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Re: Cannot resolve www Vista networking & sharing
Creating new Printer Form Vista print fax & scan
problem with creating form with check boxes Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46