C# WCF正在调用不存在的服务实现
一个月前,我在解决方案中创建了WCF服务 我有服务合同和实施的项目:ServiceContract.csprojC# WCF正在调用不存在的服务实现,c#,.net,wcf,visual-studio-2013,C#,.net,Wcf,Visual Studio 2013,一个月前,我在解决方案中创建了WCF服务 我有服务合同和实施的项目:ServiceContract.csproj namespace ERP.ServiceContract { [ServiceContract] public interface IUserManagementService { [OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllUser
namespace ERP.ServiceContract
{
[ServiceContract]
public interface IUserManagementService
{
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllUsers", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllUsersResponse")]
IEnumerable<UserDTO> GetAllUsers();
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllUserInfo", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllUserInfoResponse")]
IEnumerable<UserInfoDTO> GetAllUserInfo();
[OperationContract(Action = "http://tempuri.org/IUserManagementService/AddUser", ReplyAction = "http://tempuri.org/IUserManagementService/AddUserResponse")]
void AddUser(UserDTO user);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ModifyUser", ReplyAction = "http://tempuri.org/IUserManagementService/ModifyUserResponse")]
void ModifyUser(UserDTO user);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetUserInfoByUserName", ReplyAction = "http://tempuri.org/IUserManagementService/GetUserInfoByUserNameResponse")]
UserInfoDTO GetUserInfoByUserName(string userName);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/AddUserInfo", ReplyAction = "http://tempuri.org/IUserManagementService/AddUserInfoResponse")]
void AddUserInfo(UserInfoDTO user_info);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ModifyUserInfo", ReplyAction = "http://tempuri.org/IUserManagementService/ModifyUserInfoResponse")]
void ModifyUserInfo(UserInfoDTO user_info);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/VerifyLogin", ReplyAction = "http://tempuri.org/IUserManagementService/VerifyLoginResponse")]
UserDTO VerifyLogin(string userName, string password);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/AddPerson", ReplyAction = "http://tempuri.org/IUserManagementService/AddPersonResponse")]
void AddPerson(PersonDTO person);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/Filter", ReplyAction = "http://tempuri.org/IUserManagementService/FilterResponse")]
IEnumerable<UserDTO> Filter(Func<UserDTO, bool> predicate);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidateUser", ReplyAction = "http://tempuri.org/IUserManagementService/ValidateUserResponse")]
IEnumerable<ValidationErrorDTO> ValidateUser(UserDTO user);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetUsersTree", ReplyAction = "http://tempuri.org/IUserManagementService/GetUsersTreerResponse")]
IEnumerable<UserDTO> GetUsersTree(UserDTO currentUser);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidateUserInfo", ReplyAction = "http://tempuri.org/IUserManagementService/ValidateUserInfoResponse")]
IEnumerable<ValidationErrorDTO> ValidateUserInfo(UserInfoDTO userInfo);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetCityNameByCAP", ReplyAction = "http://tempuri.org/IUserManagementService/GetCityNameByCAPResponse")]
string GetCityNameByCAP(string CAP);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllCitiesNames", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllCitiesNamesResponse")]
IEnumerable<string> GetAllCitiesNames();
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllCitiesCAPs", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllCitiesCAPsResponse")]
IEnumerable<string> GetAllCitiesCAPs();
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ModifyPerson", ReplyAction = "http://tempuri.org/IUserManagementService/ModifyPersonResponse")]
void ModifyPerson(PersonDTO person);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidatePerson", ReplyAction = "http://tempuri.org/IUserManagementService/ValidatePersonResponse")]
IEnumerable<ValidationErrorDTO> ValidatePerson(PersonDTO person);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllPeople", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllPeopleResponse")]
IEnumerable<PersonDTO> GetAllPeople();
[OperationContract(Action = "http://tempuri.org/IUserManagementService/PersonWithEmailExists", ReplyAction = "http://tempuri.org/IUserManagementService/PersonWithEmailExistsResponse")]
bool PersonWithEmailExists(string email);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetPersonAssociatedToUserWithUserName", ReplyAction = "http://tempuri.org/IUserManagementService/GetPersonAssociatedToUserWithUserNameResponse")]
PersonDTO GetPersonAssociatedToUserWithUserName(string userName);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllCities", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllCitiesResponse")]
IEnumerable<CityDTO> GetAllCities();
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllCountriesKeys", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllCountriesKeysResponse")]
IEnumerable<string> GetAllCountriesKeys();
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ModifyUserWithUserName", ReplyAction = "http://tempuri.org/IUserManagementService/ModifyUserWithUserNameResponse")]
void ModifyUserWithUserName(string userName, string password = null, string name = null, string roleKey = null, DateTime? registrationDate = null, bool? active = null, bool? deleted = null, string fk_creator = null);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidateUserData", ReplyAction = "http://tempuri.org/IUserManagementService/ValidateUserDataResponse")]
IEnumerable<ValidationErrorDTO> ValidateUserData(string userName = null, string password = null, string name = null, string roleKey = null, string fk_creator = null);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetUserRoleOfUserWithUserName", ReplyAction = "http://tempuri.org/IUserManagementService/GetUserRoleOfUserWithUserNameResponse")]
string GetUserRoleOfUserWithUserName(string userName);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/AddRecord", ReplyAction = "http://tempuri.org/IUserManagementService/AddRecordResponse")]
void AddRecord(UserInfoDTO userInfo, PersonDTO referencePerson, ContractDTO contract, string cityKey, string countryKey);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidateRecord", ReplyAction = "http://tempuri.org/IUserManagementService/ValidateRecordResponse")]
IEnumerable<ValidationErrorDTO> ValidateRecord(UserInfoDTO userInfo, PersonDTO referencePerson, ContractDTO contract, string cityKey, string countryKey);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidateContract", ReplyAction = "http://tempuri.org/IUserManagementService/ValidateContractResponse")]
IEnumerable<ValidationErrorDTO> ValidateContract(ContractDTO contract);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetContract", ReplyAction = "http://tempuri.org/IUserManagementService/GetContractResponse")]
ContractDTO GetContract(string id);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetContractAssociatedWithUserInfoWithKey", ReplyAction = "http://tempuri.org/IUserManagementService/GetContractAssociatedWithUserInfoWithKeyResponse")]
ContractDTO GetContractAssociatedWithUserInfoWithKey(string key);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetContractKeyOfContractAssociatedWithUserInfoWithKey", ReplyAction = "http://tempuri.org/IUserManagementService/GetContractKeyOfContractAssociatedWithUserInfoWithKeyResponse")]
string GetContractKeyOfContractAssociatedWithUserInfoWithKey(string key);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetPersonFullName", ReplyAction = "http://tempuri.org/IUserManagementService/GetPersonFullNameResponse")]
string GetPersonFullName(string email);
}
}
namespace ERP.ServiceContract
{
public class UserManagementService : IUserManagementService
{
public void GetUsersTree()
{
throw new Exception();
}
public IEnumerable<DTO.UserDTO> GetAllUsers()
{
throw new NotImplementedException();
}
public IEnumerable<DTO.UserInfoDTO> GetAllUserInfo()
{
throw new NotImplementedException();
}
public void AddUser(DTO.UserDTO user)
{
throw new NotImplementedException();
}
public void ModifyUser(DTO.UserDTO user)
{
throw new NotImplementedException();
}
public void AddUserInfo(DTO.UserInfoDTO user_info)
{
throw new NotImplementedException();
}
public void ModifyUserInfo(DTO.UserInfoDTO user_info)
{
throw new NotImplementedException();
}
public void AddPerson(DTO.PersonDTO person)
{
throw new NotImplementedException();
}
public DTO.UserDTO VerifyLogin(string userName, string password)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.UserDTO> Filter(Func<DTO.UserDTO, bool> predicate)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.ValidationErrorDTO> ValidateUser(DTO.UserDTO user)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.UserDTO> GetUsersTree(DTO.UserDTO currentUser)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.ValidationErrorDTO> ValidateUserInfo(DTO.UserInfoDTO userInfo)
{
throw new NotImplementedException();
}
public string GetCityNameByCAP(string CAP)
{
throw new NotImplementedException();
}
public IEnumerable<string> GetAllCitiesNames()
{
throw new NotImplementedException();
}
public IEnumerable<string> GetAllCitiesCAPs()
{
throw new NotImplementedException();
}
public void ModifyPerson(DTO.PersonDTO person)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.ValidationErrorDTO> ValidatePerson(DTO.PersonDTO person)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.PersonDTO> GetAllPeople()
{
throw new NotImplementedException();
}
public bool PersonWithEmailExists(string email)
{
throw new NotImplementedException();
}
public DTO.PersonDTO GetPersonAssociatedToUserWithUserName(string userName)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.CityDTO> GetAllCities()
{
throw new NotImplementedException();
}
public IEnumerable<string> GetAllCountriesKeys()
{
throw new NotImplementedException();
}
public void ModifyUserWithUserName(string userName, string password = null, string name = null, string roleKey = null, DateTime? registrationDate = null, bool? active = null, bool? deleted = null, string fk_creator = null)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.ValidationErrorDTO> ValidateUserData(string userName = null, string password = null, string name = null, string roleKey = null, string fk_creator = null)
{
throw new NotImplementedException();
}
public string GetUserRoleOfUserWithUserName(string userName)
{
throw new NotImplementedException();
}
public void AddRecord(DTO.UserInfoDTO userInfo, DTO.PersonDTO referencePerson, DTO.ContractDTO contract, string cityKey, string countryKey)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.ValidationErrorDTO> ValidateRecord(DTO.UserInfoDTO userInfo, DTO.PersonDTO referencePerson, DTO.ContractDTO contract, string cityKey, string countryKey)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.ValidationErrorDTO> ValidateContract(DTO.ContractDTO contract)
{
throw new NotImplementedException();
}
public DTO.ContractDTO GetContract(string id)
{
throw new NotImplementedException();
}
public DTO.ContractDTO GetContractAssociatedWithUserInfoWithKey(string key)
{
throw new NotImplementedException();
}
public string GetContractKeyOfContractAssociatedWithUserInfoWithKey(string key)
{
throw new NotImplementedException();
}
public string GetPersonFullName(string email)
{
throw new NotImplementedException();
}
public DTO.UserInfoDTO GetUserInfoByUserName(string userName)
{
throw new NotImplementedException();
}
}
}
服务合同:IUserManagementService
namespace ERP.ServiceContract
{
public class UserManagementService : IUserManagementService
{
private IUserManagement _userManager = UserManagement.GetInstanceForDatabase();
public IEnumerable<UserInfoDTO> GetAllUserInfo()
{
return Converter.ConvertEachElementToDTO(_userManager.GetAllUserInfo());
}
public IEnumerable<UserDTO> GetAllUsers()
{
var users = _userManager.GetAllUsers();
//foreach(UserBDO user in users)
//{
// user.UserManager = _userManager;
// user.InitializeCreatedUsers();
//}
return Converter.ConvertEachElementToDTO(users);
}
public void AddUser(UserDTO user)
{
_userManager.AddUser(user.ToBDO());
}
public void AddUserInfo(UserInfoDTO user_info)
{
_userManager.AddUserInfo(user_info.ToBDO());
}
public IEnumerable<UserDTO> Filter(Func<UserDTO, bool> predicate)
{
return GetAllUsers().Where(predicate);
}
public UserInfoDTO GetUserInfoByUserName(string userName)
{
return _userManager.GetUserInfoByUserName(userName).ToDTO();
}
public void ModifyUser(UserDTO user)
{
_userManager.ModifyUser(user.ToBDO());
}
public void ModifyUserInfo(UserInfoDTO user_info)
{
_userManager.ModifyUserInfo(user_info.ToBDO());
}
public IEnumerable<ValidationErrorDTO> ValidateUser(UserDTO user)
{
return Converter.ConvertEachElementToDTO(_userManager.ValidateUser(user.ToBDO()));
}
public UserDTO VerifyLogin(string userName, string password)
{
UserBDO result = _userManager.VerifyLogin(userName, password);
if (result == null)
{
return null;
}
return result.ToDTO();
}
public IEnumerable<UserDTO> GetUsersTree(UserDTO currentUser)
{
throw new Exception();
return Converter.ConvertEachElementToDTO(_userManager.GetUsersTree(currentUser.ToBDO()));
return null;
}
public IEnumerable<ValidationErrorDTO> ValidateUserInfo(UserInfoDTO info)
{
return Converter.ConvertEachElementToDTO(_userManager.ValidateUserInfo(info.ToBDO()));
}
public string GetCityNameByCAP(string CAP)
{
return _userManager.GetCityNameByCAP(CAP);
}
public IEnumerable<string> GetAllCitiesNames()
{
return _userManager.GetAllCitiesNames();
}
public IEnumerable<string> GetAllCitiesCAPs()
{
return _userManager.GetAllCitiesCAPs();
}
public void AddPerson(PersonDTO person)
{
_userManager.AddPerson(person.ToBDO());
}
public void ModifyPerson(PersonDTO person)
{
_userManager.ModifyPerson(person.ToBDO());
}
public IEnumerable<ValidationErrorDTO> ValidatePerson(PersonDTO person)
{
return Converter.ConvertEachElementToDTO(_userManager.ValidatePerson(person.ToBDO()));
}
public IEnumerable<PersonDTO> GetAllPeople()
{
return Converter.ConvertEachElementToDTO(_userManager.GetAllPeople());
}
public bool PersonWithEmailExists(string email)
{
return _userManager.PersonWithEmailExists(email);
}
public PersonDTO GetPersonAssociatedToUserWithUserName(string userName)
{
PersonBDO result = _userManager.GetPersonAssociatedToUserWithUserName(userName);
if (_userManager.GetPersonAssociatedToUserWithUserName(userName) == null)
{
return null;
}
return result.ToDTO();
}
public IEnumerable<CityDTO> GetAllCities()
{
return Converter.ConvertEachElementToDTO(_userManager.GetAllCities());
}
public IEnumerable<string> GetAllCountriesKeys()
{
return _userManager.GetAllCountiresKeys();
}
public void ModifyUserWithUserName(string userName, string password = null, string name = null, string roleKey = null, DateTime? registrationDate = default(DateTime?), bool? active = default(bool?), bool? deleted = default(bool?), string fk_creator = null)
{
_userManager.ModifyUserWithUserName(userName, password, name, roleKey, registrationDate, active, deleted, fk_creator);
}
public IEnumerable<ValidationErrorDTO> ValidateUserData(string userName = null, string password = null, string name = null, string roleKey = null, string fk_creator = null)
{
return Converter.ConvertEachElementToDTO(_userManager.ValidateUserData(userName, password, name, roleKey, fk_creator));
}
public string GetUserRoleOfUserWithUserName(string userName)
{
return _userManager.GetUserRoleOfUserWithUserName(userName);
}
public void AddRecord(UserInfoDTO userInfo, PersonDTO referencePerson, ContractDTO contract, string cityKey, string countryKey)
{
_userManager.AddRecord(userInfo.ToBDO(), referencePerson.ToBDO(), contract.ToBDO(), cityKey, countryKey);
}
public IEnumerable<ValidationErrorDTO> ValidateRecord(UserInfoDTO userInfo, PersonDTO referencePerson, ContractDTO contract, string cityKey, string countryKey)
{
return Converter.ConvertEachElementToDTO(_userManager.ValidateRecord(userInfo.ToBDO(), referencePerson.ToBDO(), contract.ToBDO(), cityKey, countryKey));
}
public IEnumerable<ValidationErrorDTO> ValidateContract(ContractDTO contract)
{
return Converter.ConvertEachElementToDTO(_userManager.ValidateContract(contract.ToBDO()));
}
public ContractDTO GetContract(string id)
{
ContractBDO result = _userManager.GetContract(id);
if (result != null)
{
return result.ToDTO();
}
return null;
}
public ContractDTO GetContractAssociatedWithUserInfoWithKey(string key)
{
ContractBDO result = _userManager.GetContractAssociatedWithUserInfoWithKey(key);
if (result == null)
{
return null;
}
return result.ToDTO();
}
public string GetContractKeyOfContractAssociatedWithUserInfoWithKey(string key)
{
return _userManager.GetContractKeyOfContractAssociatedWithUserInfoWithKey(key);
}
public string GetPersonFullName(string email)
{
return _userManager.GetPersonFullName(email);
}
}
}
服务实现:UserManagementService
namespace ERP.ServiceContract
{
public class UserManagementService : IUserManagementService
{
private IUserManagement _userManager = UserManagement.GetInstanceForDatabase();
public IEnumerable<UserInfoDTO> GetAllUserInfo()
{
return Converter.ConvertEachElementToDTO(_userManager.GetAllUserInfo());
}
public IEnumerable<UserDTO> GetAllUsers()
{
var users = _userManager.GetAllUsers();
//foreach(UserBDO user in users)
//{
// user.UserManager = _userManager;
// user.InitializeCreatedUsers();
//}
return Converter.ConvertEachElementToDTO(users);
}
public void AddUser(UserDTO user)
{
_userManager.AddUser(user.ToBDO());
}
public void AddUserInfo(UserInfoDTO user_info)
{
_userManager.AddUserInfo(user_info.ToBDO());
}
public IEnumerable<UserDTO> Filter(Func<UserDTO, bool> predicate)
{
return GetAllUsers().Where(predicate);
}
public UserInfoDTO GetUserInfoByUserName(string userName)
{
return _userManager.GetUserInfoByUserName(userName).ToDTO();
}
public void ModifyUser(UserDTO user)
{
_userManager.ModifyUser(user.ToBDO());
}
public void ModifyUserInfo(UserInfoDTO user_info)
{
_userManager.ModifyUserInfo(user_info.ToBDO());
}
public IEnumerable<ValidationErrorDTO> ValidateUser(UserDTO user)
{
return Converter.ConvertEachElementToDTO(_userManager.ValidateUser(user.ToBDO()));
}
public UserDTO VerifyLogin(string userName, string password)
{
UserBDO result = _userManager.VerifyLogin(userName, password);
if (result == null)
{
return null;
}
return result.ToDTO();
}
public IEnumerable<UserDTO> GetUsersTree(UserDTO currentUser)
{
throw new Exception();
return Converter.ConvertEachElementToDTO(_userManager.GetUsersTree(currentUser.ToBDO()));
return null;
}
public IEnumerable<ValidationErrorDTO> ValidateUserInfo(UserInfoDTO info)
{
return Converter.ConvertEachElementToDTO(_userManager.ValidateUserInfo(info.ToBDO()));
}
public string GetCityNameByCAP(string CAP)
{
return _userManager.GetCityNameByCAP(CAP);
}
public IEnumerable<string> GetAllCitiesNames()
{
return _userManager.GetAllCitiesNames();
}
public IEnumerable<string> GetAllCitiesCAPs()
{
return _userManager.GetAllCitiesCAPs();
}
public void AddPerson(PersonDTO person)
{
_userManager.AddPerson(person.ToBDO());
}
public void ModifyPerson(PersonDTO person)
{
_userManager.ModifyPerson(person.ToBDO());
}
public IEnumerable<ValidationErrorDTO> ValidatePerson(PersonDTO person)
{
return Converter.ConvertEachElementToDTO(_userManager.ValidatePerson(person.ToBDO()));
}
public IEnumerable<PersonDTO> GetAllPeople()
{
return Converter.ConvertEachElementToDTO(_userManager.GetAllPeople());
}
public bool PersonWithEmailExists(string email)
{
return _userManager.PersonWithEmailExists(email);
}
public PersonDTO GetPersonAssociatedToUserWithUserName(string userName)
{
PersonBDO result = _userManager.GetPersonAssociatedToUserWithUserName(userName);
if (_userManager.GetPersonAssociatedToUserWithUserName(userName) == null)
{
return null;
}
return result.ToDTO();
}
public IEnumerable<CityDTO> GetAllCities()
{
return Converter.ConvertEachElementToDTO(_userManager.GetAllCities());
}
public IEnumerable<string> GetAllCountriesKeys()
{
return _userManager.GetAllCountiresKeys();
}
public void ModifyUserWithUserName(string userName, string password = null, string name = null, string roleKey = null, DateTime? registrationDate = default(DateTime?), bool? active = default(bool?), bool? deleted = default(bool?), string fk_creator = null)
{
_userManager.ModifyUserWithUserName(userName, password, name, roleKey, registrationDate, active, deleted, fk_creator);
}
public IEnumerable<ValidationErrorDTO> ValidateUserData(string userName = null, string password = null, string name = null, string roleKey = null, string fk_creator = null)
{
return Converter.ConvertEachElementToDTO(_userManager.ValidateUserData(userName, password, name, roleKey, fk_creator));
}
public string GetUserRoleOfUserWithUserName(string userName)
{
return _userManager.GetUserRoleOfUserWithUserName(userName);
}
public void AddRecord(UserInfoDTO userInfo, PersonDTO referencePerson, ContractDTO contract, string cityKey, string countryKey)
{
_userManager.AddRecord(userInfo.ToBDO(), referencePerson.ToBDO(), contract.ToBDO(), cityKey, countryKey);
}
public IEnumerable<ValidationErrorDTO> ValidateRecord(UserInfoDTO userInfo, PersonDTO referencePerson, ContractDTO contract, string cityKey, string countryKey)
{
return Converter.ConvertEachElementToDTO(_userManager.ValidateRecord(userInfo.ToBDO(), referencePerson.ToBDO(), contract.ToBDO(), cityKey, countryKey));
}
public IEnumerable<ValidationErrorDTO> ValidateContract(ContractDTO contract)
{
return Converter.ConvertEachElementToDTO(_userManager.ValidateContract(contract.ToBDO()));
}
public ContractDTO GetContract(string id)
{
ContractBDO result = _userManager.GetContract(id);
if (result != null)
{
return result.ToDTO();
}
return null;
}
public ContractDTO GetContractAssociatedWithUserInfoWithKey(string key)
{
ContractBDO result = _userManager.GetContractAssociatedWithUserInfoWithKey(key);
if (result == null)
{
return null;
}
return result.ToDTO();
}
public string GetContractKeyOfContractAssociatedWithUserInfoWithKey(string key)
{
return _userManager.GetContractKeyOfContractAssociatedWithUserInfoWithKey(key);
}
public string GetPersonFullName(string email)
{
return _userManager.GetPersonFullName(email);
}
}
}
服务客户端:UserManagementServiceClient
服务托管项目:ServiceLayer.csproj
<%@ ServiceHost Language="C#" Debug="true" Service="ERP.ServiceContract.UserManagementService" %>
我使用的是visual studio pro 2013,我的解决方案针对的是net framework 4.5.2。
该解决方案(以及与该服务相关的项目)是使用Visual Studio Express 2015创建的,两周前我就开始使用Visual Studio Professional 2013。解决方案的迁移已成功
直到一周前,一切都很顺利。在过去的一个月里,我已经编写了很多代码,并成功地进行了调试,服务运行得非常好
一周前,我在调用我的服务的特定方法(GetUserInfoByUserName)时开始出现问题:UserManagementService.cs not found+MissingMethodException
我试图单击“浏览并查找UserManagementService.cs”,出现了一个窗口:“源文件与模块构建时的WW不同。是否仍要调试器使用它(是/否)?”(选择“是”无法解决问题)
MissingMethodException是由UnserInfoDTO(一个留在其他项目中的类)的构造函数调用引起的
所以我开始排除故障,我发现了以下事实:
1) 如果我调用服务的其他方法,我不会得到任何错误。但是WCF正在调用旧版本的方法。我修改了所有方法,用“thrownewexception”替换了它们主体中的全部代码。不会抛出异常。程序遵循旧的指令。
当然,GetUserInfoByUserName(字符串用户名)方法也是如此:不会引发异常(exception)。MissingMethodException被抛出,因为该方法仍在执行旧代码,在那里我调用了UserInfoDTO的构造函数
2) 如果我直接调用UserManagementService,只需在客户机中创建一个实例,一切正常。换句话说,我只有在通过服务客户端(UserManagementServiceClient)调用服务时才会出现问题
3) 看来ServiceContract项目的代码(我有服务合同和它的实现,我有问题)是正确编译的。
这一事实非常明显(见第2点),但我想100%确定,所以我在调试时打开了模块窗口:Debug-->Windows-->Modules,在那里我可以读取加载的所有dll。
ServiceContract.dll的重量为16 Kb。
我做了这个实验:我在服务契约和服务实现(UserManagementService)中添加了新代码,并重新构建了解决方案。
我启动了另一个调试会话并查看了加载的dll:ServiceContract.dll的重量为18 Kb,因此编译后的代码已用新的C#代码更新。
这意味着调试时我没有加载较旧版本的dll
4) 问题不应该出现在服务客户端实现中。
客户端服务是使用svcutil生成的。
为了进行故障排除,我在同一个解决方案(一个简单的控制台应用程序)中创建了一个新的使用者,这次我使用“添加服务引用”生成了服务客户机。
我与该消费者有相同的问题
5) 我试图更改服务所在网站的端口:从57915更改为57916,以排除问题与其他网站具有相同端口(57915)的事实无关。
当然,我相应地更新了使用者的配置文件。
这一行动并没有解决问题
6) 我试图从项目中删除UserManagementService.cs并重新登录它。不成功
7) 我试图从解决方案中删除ServiceContract.proj,创建了一个新项目,并在新项目中复制了已删除项目的代码。不成功
下面是服务合同代码(IUserManagementService),project ServiceContract.csproj
namespace ERP.ServiceContract
{
[ServiceContract]
public interface IUserManagementService
{
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllUsers", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllUsersResponse")]
IEnumerable<UserDTO> GetAllUsers();
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllUserInfo", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllUserInfoResponse")]
IEnumerable<UserInfoDTO> GetAllUserInfo();
[OperationContract(Action = "http://tempuri.org/IUserManagementService/AddUser", ReplyAction = "http://tempuri.org/IUserManagementService/AddUserResponse")]
void AddUser(UserDTO user);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ModifyUser", ReplyAction = "http://tempuri.org/IUserManagementService/ModifyUserResponse")]
void ModifyUser(UserDTO user);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetUserInfoByUserName", ReplyAction = "http://tempuri.org/IUserManagementService/GetUserInfoByUserNameResponse")]
UserInfoDTO GetUserInfoByUserName(string userName);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/AddUserInfo", ReplyAction = "http://tempuri.org/IUserManagementService/AddUserInfoResponse")]
void AddUserInfo(UserInfoDTO user_info);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ModifyUserInfo", ReplyAction = "http://tempuri.org/IUserManagementService/ModifyUserInfoResponse")]
void ModifyUserInfo(UserInfoDTO user_info);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/VerifyLogin", ReplyAction = "http://tempuri.org/IUserManagementService/VerifyLoginResponse")]
UserDTO VerifyLogin(string userName, string password);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/AddPerson", ReplyAction = "http://tempuri.org/IUserManagementService/AddPersonResponse")]
void AddPerson(PersonDTO person);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/Filter", ReplyAction = "http://tempuri.org/IUserManagementService/FilterResponse")]
IEnumerable<UserDTO> Filter(Func<UserDTO, bool> predicate);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidateUser", ReplyAction = "http://tempuri.org/IUserManagementService/ValidateUserResponse")]
IEnumerable<ValidationErrorDTO> ValidateUser(UserDTO user);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetUsersTree", ReplyAction = "http://tempuri.org/IUserManagementService/GetUsersTreerResponse")]
IEnumerable<UserDTO> GetUsersTree(UserDTO currentUser);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidateUserInfo", ReplyAction = "http://tempuri.org/IUserManagementService/ValidateUserInfoResponse")]
IEnumerable<ValidationErrorDTO> ValidateUserInfo(UserInfoDTO userInfo);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetCityNameByCAP", ReplyAction = "http://tempuri.org/IUserManagementService/GetCityNameByCAPResponse")]
string GetCityNameByCAP(string CAP);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllCitiesNames", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllCitiesNamesResponse")]
IEnumerable<string> GetAllCitiesNames();
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllCitiesCAPs", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllCitiesCAPsResponse")]
IEnumerable<string> GetAllCitiesCAPs();
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ModifyPerson", ReplyAction = "http://tempuri.org/IUserManagementService/ModifyPersonResponse")]
void ModifyPerson(PersonDTO person);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidatePerson", ReplyAction = "http://tempuri.org/IUserManagementService/ValidatePersonResponse")]
IEnumerable<ValidationErrorDTO> ValidatePerson(PersonDTO person);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllPeople", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllPeopleResponse")]
IEnumerable<PersonDTO> GetAllPeople();
[OperationContract(Action = "http://tempuri.org/IUserManagementService/PersonWithEmailExists", ReplyAction = "http://tempuri.org/IUserManagementService/PersonWithEmailExistsResponse")]
bool PersonWithEmailExists(string email);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetPersonAssociatedToUserWithUserName", ReplyAction = "http://tempuri.org/IUserManagementService/GetPersonAssociatedToUserWithUserNameResponse")]
PersonDTO GetPersonAssociatedToUserWithUserName(string userName);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllCities", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllCitiesResponse")]
IEnumerable<CityDTO> GetAllCities();
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetAllCountriesKeys", ReplyAction = "http://tempuri.org/IUserManagementService/GetAllCountriesKeysResponse")]
IEnumerable<string> GetAllCountriesKeys();
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ModifyUserWithUserName", ReplyAction = "http://tempuri.org/IUserManagementService/ModifyUserWithUserNameResponse")]
void ModifyUserWithUserName(string userName, string password = null, string name = null, string roleKey = null, DateTime? registrationDate = null, bool? active = null, bool? deleted = null, string fk_creator = null);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidateUserData", ReplyAction = "http://tempuri.org/IUserManagementService/ValidateUserDataResponse")]
IEnumerable<ValidationErrorDTO> ValidateUserData(string userName = null, string password = null, string name = null, string roleKey = null, string fk_creator = null);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetUserRoleOfUserWithUserName", ReplyAction = "http://tempuri.org/IUserManagementService/GetUserRoleOfUserWithUserNameResponse")]
string GetUserRoleOfUserWithUserName(string userName);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/AddRecord", ReplyAction = "http://tempuri.org/IUserManagementService/AddRecordResponse")]
void AddRecord(UserInfoDTO userInfo, PersonDTO referencePerson, ContractDTO contract, string cityKey, string countryKey);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidateRecord", ReplyAction = "http://tempuri.org/IUserManagementService/ValidateRecordResponse")]
IEnumerable<ValidationErrorDTO> ValidateRecord(UserInfoDTO userInfo, PersonDTO referencePerson, ContractDTO contract, string cityKey, string countryKey);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/ValidateContract", ReplyAction = "http://tempuri.org/IUserManagementService/ValidateContractResponse")]
IEnumerable<ValidationErrorDTO> ValidateContract(ContractDTO contract);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetContract", ReplyAction = "http://tempuri.org/IUserManagementService/GetContractResponse")]
ContractDTO GetContract(string id);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetContractAssociatedWithUserInfoWithKey", ReplyAction = "http://tempuri.org/IUserManagementService/GetContractAssociatedWithUserInfoWithKeyResponse")]
ContractDTO GetContractAssociatedWithUserInfoWithKey(string key);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetContractKeyOfContractAssociatedWithUserInfoWithKey", ReplyAction = "http://tempuri.org/IUserManagementService/GetContractKeyOfContractAssociatedWithUserInfoWithKeyResponse")]
string GetContractKeyOfContractAssociatedWithUserInfoWithKey(string key);
[OperationContract(Action = "http://tempuri.org/IUserManagementService/GetPersonFullName", ReplyAction = "http://tempuri.org/IUserManagementService/GetPersonFullNameResponse")]
string GetPersonFullName(string email);
}
}
namespace ERP.ServiceContract
{
public class UserManagementService : IUserManagementService
{
public void GetUsersTree()
{
throw new Exception();
}
public IEnumerable<DTO.UserDTO> GetAllUsers()
{
throw new NotImplementedException();
}
public IEnumerable<DTO.UserInfoDTO> GetAllUserInfo()
{
throw new NotImplementedException();
}
public void AddUser(DTO.UserDTO user)
{
throw new NotImplementedException();
}
public void ModifyUser(DTO.UserDTO user)
{
throw new NotImplementedException();
}
public void AddUserInfo(DTO.UserInfoDTO user_info)
{
throw new NotImplementedException();
}
public void ModifyUserInfo(DTO.UserInfoDTO user_info)
{
throw new NotImplementedException();
}
public void AddPerson(DTO.PersonDTO person)
{
throw new NotImplementedException();
}
public DTO.UserDTO VerifyLogin(string userName, string password)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.UserDTO> Filter(Func<DTO.UserDTO, bool> predicate)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.ValidationErrorDTO> ValidateUser(DTO.UserDTO user)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.UserDTO> GetUsersTree(DTO.UserDTO currentUser)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.ValidationErrorDTO> ValidateUserInfo(DTO.UserInfoDTO userInfo)
{
throw new NotImplementedException();
}
public string GetCityNameByCAP(string CAP)
{
throw new NotImplementedException();
}
public IEnumerable<string> GetAllCitiesNames()
{
throw new NotImplementedException();
}
public IEnumerable<string> GetAllCitiesCAPs()
{
throw new NotImplementedException();
}
public void ModifyPerson(DTO.PersonDTO person)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.ValidationErrorDTO> ValidatePerson(DTO.PersonDTO person)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.PersonDTO> GetAllPeople()
{
throw new NotImplementedException();
}
public bool PersonWithEmailExists(string email)
{
throw new NotImplementedException();
}
public DTO.PersonDTO GetPersonAssociatedToUserWithUserName(string userName)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.CityDTO> GetAllCities()
{
throw new NotImplementedException();
}
public IEnumerable<string> GetAllCountriesKeys()
{
throw new NotImplementedException();
}
public void ModifyUserWithUserName(string userName, string password = null, string name = null, string roleKey = null, DateTime? registrationDate = null, bool? active = null, bool? deleted = null, string fk_creator = null)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.ValidationErrorDTO> ValidateUserData(string userName = null, string password = null, string name = null, string roleKey = null, string fk_creator = null)
{
throw new NotImplementedException();
}
public string GetUserRoleOfUserWithUserName(string userName)
{
throw new NotImplementedException();
}
public void AddRecord(DTO.UserInfoDTO userInfo, DTO.PersonDTO referencePerson, DTO.ContractDTO contract, string cityKey, string countryKey)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.ValidationErrorDTO> ValidateRecord(DTO.UserInfoDTO userInfo, DTO.PersonDTO referencePerson, DTO.ContractDTO contract, string cityKey, string countryKey)
{
throw new NotImplementedException();
}
public IEnumerable<DTO.ValidationErrorDTO> ValidateContract(DTO.ContractDTO contract)
{
throw new NotImplementedException();
}
public DTO.ContractDTO GetContract(string id)
{
throw new NotImplementedException();
}
public DTO.ContractDTO GetContractAssociatedWithUserInfoWithKey(string key)
{
throw new NotImplementedException();
}
public string GetContractKeyOfContractAssociatedWithUserInfoWithKey(string key)
{
throw new NotImplementedException();
}
public string GetPersonFullName(string email)
{
throw new NotImplementedException();
}
public DTO.UserInfoDTO GetUserInfoByUserName(string userName)
{
throw new NotImplementedException();
}
}
}
我解决了这个问题
我的解决方案中有一个旧的dll导致了问题
如果您阅读此问题是因为您有类似的问题,请检查解决方案的所有项目(bin和obj文件夹)中是否没有旧的dll(或一般的可执行代码)