Wcf异常处理抛出错误
您好,我在 wcf 中处理异常时遇到问题。 我有一个这样的服务:
[ServiceContract]
public interface IAddressService
{
[OperationContract]
[FaultContract(typeof(ExecuteCommandException))]
int SavePerson(string idApp, int idUser, Person person);
}
我正在 WCFTestClient 实用程序中的服务上调用 SavePerson()。 SavePerson() 实现是:
public int SavePerson(string idApp, int idUser, Person person)
{
try
{
this._savePersonCommand.Person = person;
this.ExecuteCommand(idUser, idApp, this._savePersonCommand);
return this._savePersonCommand.Person.Id;
}
catch (ExecuteCommandException ex)
{
throw new FaultException<ExecuteCommandException>(ex, new FaultReason("Error in 'SavePerson'"));
}
}
但我收到此错误:
调用服务失败。可能的 原因:服务离线或 无法进入;客户端 配置不匹配 代理人;现有代理无效。 有关更多信息,请参阅堆栈跟踪 细节。您可以尝试通过以下方式恢复 启动一个新的代理,恢复到 默认配置,或者刷新 服务。
如果我更改 SavePerson 方法而不是:
catch (ExecuteCommandException ex)
{
throw new FaultException<ExecuteCommandException>(ex, new FaultReason("Error in 'SavePerson'"));
}
我这样做
catch(Exception)
{
throw;
}
,我不会收到上述错误,但我只收到异常消息,没有内部异常。 我做错了什么?
Hi I have a problem handling exceptions in wcf.
I have a service like this one:
[ServiceContract]
public interface IAddressService
{
[OperationContract]
[FaultContract(typeof(ExecuteCommandException))]
int SavePerson(string idApp, int idUser, Person person);
}
I am calling the SavePerson() on the service in the WCFTestClient utility.
The SavePerson() implementation is:
public int SavePerson(string idApp, int idUser, Person person)
{
try
{
this._savePersonCommand.Person = person;
this.ExecuteCommand(idUser, idApp, this._savePersonCommand);
return this._savePersonCommand.Person.Id;
}
catch (ExecuteCommandException ex)
{
throw new FaultException<ExecuteCommandException>(ex, new FaultReason("Error in 'SavePerson'"));
}
}
But I get this error:
Failed to invoke the service. Possible
causes: The service is offline or
inaccessible; the client-side
configuration does not match the
proxy; the existing proxy is invalid.
Refer to the stack trace for more
detail. You can try to recover by
starting a new proxy, restoring to
default configuration, or refreshing
the service.
if I change the SavePerson method and instead of:
catch (ExecuteCommandException ex)
{
throw new FaultException<ExecuteCommandException>(ex, new FaultReason("Error in 'SavePerson'"));
}
I do
catch(Exception)
{
throw;
}
I don't get the above error, but I only get the exception message and no inner exception.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您定义故障契约时:
您不能指定异常类型。相反,您可以指定您选择的数据协定来传回您认为必要的任何值。
例如:
When you define the fault contract:
you must not specify an exception type. Instead, you specify a data contract of your choice to pass back any values that you deem necessary.
For example: