Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums

Go Back   Vista Forums > Vista technology newsgroups > Indigo

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

Reply
 
Thread Tools Display Modes
Old 01-30-2008   #1
fstarnaud
Guest
 
Posts: n/a

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 ***
  Reply With Quote

Reply

Thread Tools
Display Modes









Vistax64.com 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.
© Vistax64.com 2005-2008

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 47 48