Search code examples
wcfnet.tcp

Cannot successfully run svcutil on net.tcp example in wcf examples


I just downloaded and ran the net.tcp binding example from the Microsoft WCF samples: WF_WCF_Samples\WCF\Basic\Binding\Net\Tcp\Default\CS

I opened the solution and rebuilt it, launched the server from the server/bin directory, launched the client from the client/bin directory and everything worked fine.

I added a new function to service.cs and then called it from client.cs. But visual studio gave this error: 'Microsoft.Samples.NetTcp.CalculatorClient' does not contain a definition for 'AddAndDouble' and no extension method 'AddAndDouble' accepting a first argument of type 'Microsoft.Samples.NetTcp.CalculatorClient' could be found (are you missing a using directive or an assembly reference?)

I'm assuming it's giving this error because my generatedClient.cs file is now out of date, so I'm trying to run svcutil to generate a new generatedClient.cs file.

But when I run svc util, this is what it says:


c:\Program Files\Microsoft Visual Studio 9.0\VC>svcutil.exe net.tcp://localhost: 9000/servicemodelsamples/service/

Microsoft (R) Service Model Metadata Tool [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.648] Copyright (c) Microsoft Corporation. All rights reserved.

Attempting to download metadata from 'net.tcp://localhost:9000/servicemodelsampl es/service/' using WS-Metadata Exchange. This URL does not support DISCO. Microsoft (R) Service Model Metadata Tool [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.648] Copyright (c) Microsoft Corporation. All rights reserved.

Error: Cannot obtain Metadata from net.tcp://localhost:9000/servicemodelsamples/ service/

If this is a Windows (R) Communication Foundation service to which you have acce ss, please check that you have enabled metadata publishing at the specified addr ess. For help enabling metadata publishing, please refer to the MSDN documentat ion at http://go.microsoft.com/fwlink/?LinkId=65455.

WS-Metadata Exchange Error URI: net.tcp://localhost:9000/servicemodelsamples/service/

Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:

9000/servicemodelsamples/service/'.

The socket connection was aborted. This could be caused by an error processi

ng your message or a receive timeout being exceeded by the remote host, or an un derlying network resource issue. Local socket timeout was '00:04:59.9687500'.

An existing connection was forcibly closed by the remote host

If you would like more help, type "svcutil /?"

So, I checked that the server was listening by doing this: netstat /an | find /i "9000" TCP 0.0.0.0:9000 0.0.0.0:0 LISTENING

Any ideas what I'm doing wrong?


Solution

  • The service in that sample doesn't expose any metadata endpoint which can be used by tools such as svcutil. If you change the service implementation to add a metadata endpoint (see below), svcutil should work with it.

        // Host the service within this EXE console application.
        public static void Main()
        {
            // Create a ServiceHost for the CalculatorService type.
            using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService),
                   new Uri("net.tcp://localhost:9000/servicemodelsamples/service")))
            {
                ServiceMetadataBehavior smb = 
                        serviceHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
                if (smb == null) serviceHost.Description.Behaviors.Add(
                                   new ServiceMetadataBehavior());
                serviceHost.AddServiceEndpoint(typeof(IMetadataExchange), 
                                 MetadataExchangeBindings.CreateMexTcpBinding(), "mex");
                serviceHost.AddServiceEndpoint(typeof(ICalculator), 
                                               new NetTcpBinding(), "");
                // Open the ServiceHost to create listeners
                    //  and start listening for messages.
                serviceHost.Open();
    
                // The service can now be accessed.
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();
            }
        }