C# 休息服务返回不工作
我有一个rest服务合同,它以前工作得很好,返回一个IdocEntity类的对象 这是此的工作代码:C# 休息服务返回不工作,c#,rest,constructor,datacontract,C#,Rest,Constructor,Datacontract,我有一个rest服务合同,它以前工作得很好,返回一个IdocEntity类的对象 这是此的工作代码: [OperationContract] [WebInvoke( Method = "*", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrappe
[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);
}
}
下面是返回配置文件的那一个的rest代码
[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);
}
}
[运营合同]
[WebInvoke(
Method=“*”,
ResponseFormat=WebMessageFormat.Json,
RequestFormat=WebMessageFormat.Json,
BodyStyle=WebMessageBodyStyle.Wrapped,
UriTemplate=“updateProfile”
)]
配置文件更新配置文件(字符串entityId、字符串邮件、字符串telf、字符串传真、字符串目录);
公共配置文件更新配置文件(字符串entityId、字符串mail、字符串telf、字符串传真、字符串direc)
{
尝试
{
如果(!string.IsNullOrEmpty(entityId))
{
Profile perfil=Profile.GetProfileByEntityId(新Guid(entityId));
perfil.Mail=Mail;
性能电话=telf;
perfil.Fax=传真;
perfil.Direccion=direc;
Profile.UpdateProfileDataByEntityId(perfil);
返回性能;
}
其他的
{
ArgumentException exx=新的ArgumentException(“Error.No-se-Encuntera el-usuario.”);
抛出新的WebFaultException(新的ErrorMessage(exx)、HttpStatusCode.Unauthorized);
}
}
捕获(WebFaultException)
{
投掷;
}
捕获(例外情况除外)
{
抛出新的WebFaultException(新的ErrorMessage(ex)、HttpStatusCode.InternalServerError);
}
}
现在,我更改了第一个,以返回一个Profile对象,以获取更多信息,它停止工作。然后我检查了第二个,它也失败了
它做的一切都很好,但我的rest服务返回0无响应
IdocEntity和Profile都有它们的[DataContract]和[DataMember]内容,IdocEntity过去工作得很好
也许值得一提的是,Profile有一个Hashtable属性
编辑:问题不在于hashtable属性,没有它也不起作用
有人帮忙会很好,谢谢:)我终于找到了问题所在。我的Profile类上的一个属性是我初始化为的DateTime
DateTime bornDate=new DateTime()
在我的更新中,我没有给它任何价值
我把它改成了
DateTime bornDate=DateTime.now代码>
现在可以完美地工作了需要更多的代码才能提供帮助我会发布更多的代码,我做了一些更改,我认为配置文件1可以工作,但没有,所以这不是问题,我会更新更多的信息。我环顾四周,找不到关于rest服务返回对象而不是从另一个对象扩展的任何特殊信息,所以我不知道他们之间有什么不同
[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);
}
}