这是我第一次使用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 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启动测试服务器时,只显示2种方法。 GetProduct没有显示。什么是错的?
答案 0 :(得分:-1)
请尝试此代码。
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);
}
}