Visual studio 2010 WCF测试客户端服务操作未更新
我是WCF的新手。我正在创建一个新的WCF服务。我最初做了一次手术。但过了一段时间,我决定再加两个。这两个新操作未出现在Microsoft WCF测试客户端中。我如何解决我的问题 更新:我注释掉了我的第一个操作和第二个操作。第三个操作已在WCF测试客户端中更新 @珍Visual studio 2010 WCF测试客户端服务操作未更新,visual-studio-2010,wcf,operations,Visual Studio 2010,Wcf,Operations,我是WCF的新手。我正在创建一个新的WCF服务。我最初做了一次手术。但过了一段时间,我决定再加两个。这两个新操作未出现在Microsoft WCF测试客户端中。我如何解决我的问题 更新:我注释掉了我的第一个操作和第二个操作。第三个操作已在WCF测试客户端中更新 @珍 namespace-MyService { //注意:您可以使用“重构”菜单上的“重命名”命令同时更改代码和配置文件中的接口名称“IService1”。 [服务合同] 公共接口IService1 { [经营合同] 列出FindU
namespace-MyService
{
//注意:您可以使用“重构”菜单上的“重命名”命令同时更改代码和配置文件中的接口名称“IService1”。
[服务合同]
公共接口IService1
{
[经营合同]
列出FindUser(字符串用户名、字符串密码);
List GetServiceList();
List GetMessageList(字符串用户名);
}
}
命名空间MyService
{
//注意:您可以使用“重构”菜单上的“重命名”命令来同时更改代码、svc和配置文件中的类名“Service1”。
公共类服务1:IService1
{
公共列表GetServiceList()
{
DataClasses1DataContext上下文=新DataClasses1DataContext();
var res=上下文中的r。服务选择r;
return res.ToList();
}
公共列表FindUser(字符串用户名、字符串密码)
{
DataClasses1DataContext上下文=新DataClasses1DataContext();
var res=上下文中的r。其中r.UserName==用户名和r.Password==密码的用户选择r;
return res.ToList();
}
公共列表GetMessageList(字符串用户名)
{
DataClasses1DataContext上下文=新DataClasses1DataContext();
var res=来自上下文中的r。消息中r.ReceiverID==用户名选择r;
return res.ToList();
}
}
}
您需要在界面中的每个方法之前添加OperationContractAttribute
。(由于工作中的网络设置,我可能看不到图像,所以遗漏了一些内容。)您是否用[OperationContract]
属性对遗漏的服务方法进行了注释?是否在服务界面中定义了所有方法
?我更新了上面的代码。请看一看我相信我已经做到了上面提到的。
namespace MyService
{
// 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]
List<User> FindUser(string userName, string password);
List<Service> GetServiceList();
List<Message> GetMessageList(string userName);
}
}
namespace MyService
{
// 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 List<Service> GetServiceList()
{
DataClasses1DataContext context = new DataClasses1DataContext();
var res = from r in context.Services select r;
return res.ToList();
}
public List<User> FindUser(string userName, string password)
{
DataClasses1DataContext context = new DataClasses1DataContext();
var res = from r in context.Users where r.UserName == userName && r.Password == password select r;
return res.ToList();
}
public List<Message> GetMessageList(string userName)
{
DataClasses1DataContext context = new DataClasses1DataContext();
var res = from r in context.Messages where r.ReceiverID == userName select r;
return res.ToList();
}
}
}