这可能很简单,但我有一个 .asmx Web 服务,它返回一个序列化为 json 的对象。如果有错误,我想抛出一个字符串。我最终为错误消息添加了一个公共字符串。我可以转换我的对象以返回一个字符串吗?
public TmsObject GetTombstoneDataJson(string ObjectNumber)
{
if ((Regex.IsMatch(ObjectNumber, @"^([\w\._-]|\s)*$")))
{
try
{
TmsObject tmsd = new TmsObject();
tmsd.Dated = "foo";
tmsd.Medium = "foo";
tmsd.Dimensions = "foo";
tmsd.ObjectNumber = "foo";
tmsd.CreditLine = "foo";
return tmsd;
}
catch
{
TmsObject notmsd = new TmsObject();
notmsd.ErrorMsg = "There was an error in processing this request. Please review the web service description and try again.";
return notmsd;
}
}
else
{
TmsObject notmsd = new TmsObject();
notmsd.ErrorMsg = "One of the required parameters is empty or incorrect.";
return notmsd;
}
}