【发布时间】:2015-03-09 09:07:14
【问题描述】:
我有一个休息服务合同,它过去可以很好地返回 IdocEntity 类的对象。
这是它的工作代码:
[OperationContract]
[WebInvoke(
Method = "*",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "login/{userName}/{password}/{ip}"
)]
IdocEntity Login(string userName, string password, string ip);
public IdocEntity Login(string userName, string password, string ip)
{
[some checks]
try
{
userEntity = checkUSR(userName, password, ip, string.Empty);
if (userEntity == null)
{
ArgumentException exx = new ArgumentException("User not found");
throw new WebFaultException<ErrorMessage>(new ErrorMessage(exx), HttpStatusCode.Unauthorized);
}
return userEntity;
}
catch (WebFaultException<ErrorMessage>)
{
throw;
}
catch (Exception ex)
{
throw new WebFaultException<ErrorMessage>(new ErrorMessage(ex), HttpStatusCode.InternalServerError);
}
}
我还有另一个合同返回 Profile 类的对象。
配置文件从 IdocEntity 扩展而来,但它不起作用。这是我的对象配置文件:
[Serializable]
[DataContract]
public class Profile : IdocEntity
{
[a bunch of properties with [DataMember] on top of them]
public Profile(Guid entityId) :
base(entityId)
{ }
[a bunch of methods to get or update a profile]
}
这是返回个人资料的其余代码
[OperationContract]
[WebInvoke(
Method = "*",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "updateProfile"
)]
Profile UpdateProfile(string entityId, string mail, string telf, string fax, string direc);
public Profile UpdateProfile(string entityId, string mail, string telf, string fax, string direc)
{
try
{
if (!string.IsNullOrEmpty(entityId))
{
Profile perfil = Profile.GetProfileByEntityId(new Guid(entityId));
perfil.Mail = mail;
perfil.Telephone = telf;
perfil.Fax = fax;
perfil.Direccion = direc;
Profile.UpdateProfileDataByEntityId(perfil);
return perfil;
}
else
{
ArgumentException exx = new ArgumentException("Error. No se encuentra el usuario.");
throw new WebFaultException<ErrorMessage>(new ErrorMessage(exx), HttpStatusCode.Unauthorized);
}
}
catch (WebFaultException<ErrorMessage>)
{
throw;
}
catch (Exception ex)
{
throw new WebFaultException<ErrorMessage>(new ErrorMessage(ex), HttpStatusCode.InternalServerError);
}
}
现在,我将第一个更改为返回 Profile 对象,以获取更多信息,但它停止工作。然后我检查了第二个,它也失败了。
一切正常,但我的休息服务正在返回0 No Response
IdocEntity 和 Profile 都有自己的 [DataContract] 和 [DataMember] 内容,而 IdocEntity 过去工作得很好。
也许值得一提的是 Profile 有一个 Hashtable 属性 编辑:问题不在于哈希表属性,没有它也不起作用。
一些帮助会很好,谢谢:)
【问题讨论】:
-
需要更多代码才能提供帮助
-
我会发布更多代码,我已经更改了一些内容,我认为配置文件可以工作但不是,所以这不是问题,我会更新更多信息。跨度>
-
我环顾四周,找不到任何关于休息服务返回的对象比另一个对象扩展的特别之处,所以我不知道它们之间有什么不同
标签: c# rest constructor datacontract