Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF服务中的方法未显示在客户端应用程序中_C#_.net_Wcf - Fatal编程技术网

C# WCF服务中的方法未显示在客户端应用程序中

C# WCF服务中的方法未显示在客户端应用程序中,c#,.net,wcf,C#,.net,Wcf,我最新的C#coding项目是学习WCF服务。我试图做一个非常简单的服务。它有一个不是默认的方法,它只返回一个用户输入的整数乘以2的字符串。我已将该服务上载到aspspider.com,并创建了一个winforms客户端应用程序。但是,当查看服务类时,它只显示GetData方法。老实说,我对此感到困惑,我一辈子都不明白为什么我的方法不会出现。我在命令行中使用了svcutil.exe命令,但仍然没有任何结果。如果有人能帮我,我会非常感激的!这是我的密码: 服务代码: using System; u

我最新的C#coding项目是学习WCF服务。我试图做一个非常简单的服务。它有一个不是默认的方法,它只返回一个用户输入的整数乘以2的字符串。我已将该服务上载到aspspider.com,并创建了一个winforms客户端应用程序。但是,当查看服务类时,它只显示GetData方法。老实说,我对此感到困惑,我一辈子都不明白为什么我的方法不会出现。我在命令行中使用了svcutil.exe命令,但仍然没有任何结果。如果有人能帮我,我会非常感激的!这是我的密码:

服务代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Web.Services;

namespace WcfService1
{
    public class Service1 : IService1
    {        
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public string GetDouble(int value) //Method that isn't showing up
        {
            return (value * 2).ToString();
        }
     }
  }
服务接口:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfService1
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string GetData(int value);

        [OperationContract]
        public string GetDouble(int value); //Method that isn't showing up

        // TODO: Add your service operations here
    }   
}
Service1Client(注意这很混乱。仍在试图弄清楚如何在此处格式化代码):


这是正确的编译吗?接口不能声明其中方法的可见性。它们是公开的。那么这个,

[OperationContract]
public string GetDouble(int value);
应该是这样,

[OperationContract]
string GetDouble(int value);

因此,从操作契约中删除访问修饰符,如下所示

string GetData(int value)
{
    return string.Format("You entered: {0}", value);
}
string GetDouble(int value) 
{
    return (value * 2).ToString();
}

我解决了这个问题。显然我忘了编译更改。谢谢大家的帮助

您之所以得到答案,是因为(构建和编译)方向正确。如果您没有以正确的方式打开解决方案,它也可能在某个地方发生。

您在哪里定义了
Service1Client
?您只发布了名为
Service1
的类的代码。我现在发布该代码。很抱歉您是否碰巧最初仅使用GetData方法部署服务?考虑到其他人已经注意到的情况,您的最新版本似乎不可供客户端使用。您没有看到这一点。这两种方式似乎都没有区别。如果没有区别,那么听起来好像您的服务模块没有被构建/编译。因此,不管您对新方法做了什么,它都不会出现。@ZackMatthews-取决于原因是什么以及您如何部署组件。我猜不到。每当我修改它时,我只是上传新的.svc+.dll文件。我有没有其他的发布方式?你发布的版本甚至都不会编译,所以在你的发布过程中出现了一个问题,这意味着你甚至没有注意到这一点。在发布重新编译的DLL之前,可能没有将其部署到生成文件夹中。
[OperationContract]
string GetDouble(int value);
string GetData(int value)
{
    return string.Format("You entered: {0}", value);
}
string GetDouble(int value) 
{
    return (value * 2).ToString();
}