WCF 服务中添加的新功能未显示在客户端上

ZCo*_*der 3 c# asp.net wcf wcf-data-services windows-phone-8.1

我在 Asp.net MVC 上有一个简单的 Web 应用程序。我创建了一个 WFC 服务,以便我可以将数据发送到我的 Windows 8.1 应用程序,但是我的新功能没有显示在我的客户端中。

这是我的 WFC 代码:

[DataContract]
    public class Service1 : IService1
    {
        ApplicationDbContext _db=new ApplicationDbContext();

        public string GetData(int value)
        {


            return string.Format("You entered: {0}", value);
        }

        public WtFImages.Models.Images GetDataL(int value)
        {
            var User = _db.Image.Local.FirstOrDefault(c => c.Id == value);

            return User;
        }
        public List<WtFImages.Models.Images> GetDataAll(int value)
        {
            var GetAllPublic = _db.Image.Local.ToList();

            return (GetAllPublic);
        }

        public IList<WtFImages.Models.Images> ZGetDataAll(int value)
        {
            var GetAllPublic = _db.Image.Local.ToList();

            return (GetAllPublic);
        }
        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的客户端只显示默认功能。

在此处输入图片说明

服务代码

namespace ImageFechingWfc
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {

        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        // TODO: Add your service operations here
    }


    // Use a data contract as illustrated in the sample below to add composite types to service operations.
    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Rez*_*aei 5

您想要作为服务方法公开的每个方法都应该存在于您的IService1接口中并且应该用 装饰[OperationContract],然后您应该在服务类中实现该方法。

  • 打开IService1.cs并放置您的方法的签名是IService1接口,然后用 装饰您的新方法[OperationContract],然后放入实现Service1并重建项目,然后添加您的服务引用并使用它。
  • 此外,您不需要[DataContract]在您的服务实现之上。

例如,如果你想int Add(int x, int y)在你的服务中有一个方法,把它放在你的IService1界面中:

[OperationContract]
int Add(int x, int y);
Run Code Online (Sandbox Code Playgroud)

然后把它放在你的Service1班级里:

public int Add(int x, int y)
{
    return x+y;
}
Run Code Online (Sandbox Code Playgroud)

要了解有关 WCF 服务的更多信息,您可以阅读此入门教程