0

这是我第一次在 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 不显示。怎么了?

4

1 回答 1

-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);
    }

}
于 2012-10-16T23:22:37.513 回答