[英]Throw exception with inner exception in WCF
我正在嘗試通過WCF導線發送異常,但無法弄清楚我做錯了什么。 我遵循Oleg Sych和MSDN的指導,但無濟於事。
我得到的是The requested service, 'net.tcp://mymachine/myservicepath/MyService.svc' could not be activated. See the server's diagnostic trace logs for more information.
The requested service, 'net.tcp://mymachine/myservicepath/MyService.svc' could not be activated. See the server's diagnostic trace logs for more information.
。
[ServiceContract]
public interface ISystemInfoService
{
[OperationContract]
[FaultContract(typeof(MyException))]
void DoThrowException(string message);
}
//[ServiceContract] // <- the culprit
public class SystemInfoService : ISystemInfoService
{
public void DoThrowException(string message)
{
try
{
throw new MyException( "MyMessage" );
}
catch (MyExceptionexc)
{
throw new FaultException<MyException>(exc);
}
}
}
// The custom Exception resides in an common assembly reachable from both server and client.
[Serializable]
public class MyException: Exception
{
...
}
TIA
您可以嘗試使用datacontract類而不是可序列化的異常來處理異常嗎?
[DataContract]
public class MyExceptionClass
{
[DataMember]
public Exception Exc { get; set; }
}
[ServiceContract]
public interface ISystemInfoService
{
[OperationContract]
[FaultContract(typeof(MyExceptionClass))]
void DoThrowException(string message);
}
public class SystemInfoService : ISystemInfoService
{
public void DoThrowException(string message)
{
try
{
throw new Exception("MyMessage");
}
catch (Exception exc)
{
var data = new MyExceptionClass { Exc = exc };
throw new FaultException<MyExceptionClass>(data);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.