无法在 wcf 示例中的 net.tcp 示例上成功运行 svcutil

nbo*_*wit 2 wcf net.tcp

我刚刚从 Microsoft WCF 示例中下载并运行了 net.tcp 绑定示例:WF_WCF_Samples\WCF\Basic\Binding\Net\Tcp\Default\CS

我打开解决方案并重建它,从 server/bin 目录启动服务器,从 client/bin 目录启动客户端,一切正常。

我向 service.cs 添加了一个新函数,然后从 client.cs 调用它。但是visual studio给出了这个错误:'Microsoft.Samples.NetTcp.CalculatorClient'不包含'AddAndDouble'的定义并且没有扩展方法'AddAndDouble'接受'Microsoft.Samples.NetTcp.CalculatorClient'类型的第一个参数可以找到(您是否缺少 using 指令或程序集引用?)

我假设它给出了这个错误,因为我的generatedClient.cs 文件现在已经过时了,所以我试图运行svcutil 来生成一个新的generatedClient.cs 文件。

但是当我运行 svc util 时,它是这样说的:


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

Microsoft (R) 服务模型元数据工具 [Microsoft (R) Windows (R) 通信基础,版本 3.0.4506.648] 版权所有 (c) Microsoft Corporation。版权所有。

尝试使用 WS-Metadata Exchange 从“net.tcp://localhost:9000/servicemodelsampl es/service/”下载元数据。此 URL 不支持 DISCO。Microsoft (R) 服务模型元数据工具 [Microsoft (R) Windows (R) 通信基础,版本 3.0.4506.648] 版权所有 (c) Microsoft Corporation。版权所有。

错误:无法从 net.tcp://localhost:9000/servicemodelsamples/service/ 获取元数据

如果这是您有权访问的 Windows (R) Communication Foundation 服务,请检查您是否已在指定的地址启用元数据发布。有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455上的 MSDN 文档。

WS 元数据交换错误 URI:net.tcp://localhost:9000/servicemodelsamples/service/

Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:
Run Code Online (Sandbox Code Playgroud)

9000/servicemodelsamples/service/'。

The socket connection was aborted. This could be caused by an error processi
Run Code Online (Sandbox Code Playgroud)

您的消息或远程主机超过接收超时,或潜在的网络资源问题。本地套接字超时为“00:04:59.9687500”。

An existing connection was forcibly closed by the remote host
Run Code Online (Sandbox Code Playgroud)

如果您需要更多帮助,请输入“svcutil /?”

因此,我通过执行以下操作检查服务器是否正在侦听:netstat /an | find /i "9000" TCP 0.0.0.0:9000 0.0.0.0:0 聆听

任何想法我做错了什么?

car*_*ira 5

该示例中的服务没有公开任何可由 svcutil 等工具使用的元数据端点。如果您更改服务实现以添加元数据端点(见下文),svcutil 应该可以使用它。

    // 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();
        }
    }
Run Code Online (Sandbox Code Playgroud)