C# 为什么没有显示此服务方法?
这是我第一次在Visual Studio和C中编程。我正在尝试创建一个web服务,但我的GetProduct没有显示出来C# 为什么没有显示此服务方法?,c#,asp.net,visual-studio-2010,wcf,web-services,C#,Asp.net,Visual Studio 2010,Wcf,Web Services,这是我第一次在Visual Studio和C中编程。我正在尝试创建一个web服务,但我的GetProduct没有显示出来 namespace GettingStartedHost { // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together. public class Se
namespace GettingStartedHost
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public int GetProduct(int a, int b)
{
return a * b;
}
[ServiceContract]
public interface IService
{
[OperationContract]
int GetProduct(int a, int b);
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
}
当我按CTRL-F5启动测试服务器时,只显示两个方法。GetProduct未显示。怎么了?请尝试此代码
namespace GettingStartedHost
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public int GetProduct(int a, int b)
{
return a * b;
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite == null)
{
throw new ArgumentNullException("composite");
}
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}
[ServiceContract]
public interface IService1
{
[OperationContract]
int GetProduct(int a, int b);
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
}
}
示例缺少IService1的定义…您是否更新了客户端项目中的服务引用?能否详细说明?我似乎无法理解,你必须写上我的名字才能在我的收件箱中看到你的回复;我的意思是:你在客户端项目中右键单击了你的服务引用并点击了更新服务引用了吗?@Alan:在你的代码中,你有服务1:IService1,但你的接口代码中有IService,你缺少了1。你好,Jams,谢谢你的帮助。我发现名称空间已经包含IService1的定义,但它仍然不起作用: