2

我刚刚从 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 指令或程序集引用?)

我假设它给出了这个错误,因为我的 generateClient.cs 文件现在已经过时了,所以我试图运行 svcutil 来生成一个新的 generateClient.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) Communication Foundation,版本 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) Communication Foundation,版本 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:

9000/servicemodelsamples/service/'.

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

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

An existing connection was forcibly closed by the remote host

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

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

任何想法我做错了什么?

4

3 回答 3

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();
        }
    }
于 2011-10-25T06:04:54.693 回答
1

尝试通过配置公开元交换端点:

            <endpoint address="mexTcp"
                      binding="mexTcpBinding"
                      contract="IMetadataExchange" />
            <endpoint address="mexWS"
                      binding="mexHttpBinding"
                      contract="IMetadataExchange" />

而不是以编程方式。

于 2013-03-07T09:13:25.150 回答
0

这里只是一种预感,因为您没有发布任何代码。您的 Service.cs 文件是否实现了 IService?如果是这样,您是否将 AddAndDouble 方法添加到 IService 文件?

例子:

[ServiceContract]
public interface IService
{

    [OperationContract]
    double AddAndDouble(double x, double y);
}

public interface Service: IService
{

    // Implement the operation contract here
    public double AddAndDouble(double x, double y)
    {

        // Your code goes here
    }
}

如果没有,请进行这些更改,重新构建您的服务,然后运行 ​​svcutil.exe。

于 2011-10-25T05:06:41.740 回答