【发布时间】:2019-04-11 11:47:39
【问题描述】:
.NET Core 2.2 不支持带有 FaultException
我有一个这样的 WCF 服务参考 - 这个确切的代码未经测试,但 simular 在 .NET Standard 4.6.2 中运行良好。
服务器端:
[OperationContract]
[FaultContract(typeof(MyErrorType))]
[WebInvoke(
Method = "GET",
UriTemplate = "/GetData?foo={foo}",
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
ExpectedReturnType GetData(int foo);
[DataContract]
[Serializable]
public class MyErrorType
{
[DataMember]
public int ErrorCode { get; set; }
[DataMember]
public string Description { get; set; }
}
try {
return GetData(123);
}
catch (Exception e)
{
throw new FaultException<MyErrorType>(new MyErrorType() { ErrorCode = 20, Description = "Server side error message returning to client" });
}
客户端
try
{
_client.GetData(123);
}
catch (FaultException <MyErrorType> e)
{
// NEVER ENDS UP HERE IN .NET Core 2.2
// works fine in .NET Standard 4.6.2
Console.WriteLine(e.Details.ErrorCode);
Console.WriteLine(e.Details.Description);
throw e;
}
catch (Exception e)
{
throw e;
}
【问题讨论】:
标签: wcf .net-core-2.2