Docs: WCF FaultException<T> - .NET Core 2.2

Created on 11 Apr 2019  Â·  4Comments  Â·  Source: dotnet/docs

Is faultcontracts with FaultException< T > not supported in .NET Core 2.2?

I have a WCF service reference like so - this exact code is not tested, but simular works well in .NET Standard 4.6.2.

Server side:

[OperationContract]
[FaultContract(typeof(MyErrorType))]
[WebInvoke(
      Method = "GET",
      UriTemplate = "/GetData?foo={foo}",
      BodyStyle = WebMessageBodyStyle.Bare,
      RequestFormat = WebMessageFormat.Json,
      ResponseFormat = WebMessageFormat.Json)]
ExpectedResultType 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" });
}

Client side

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;
}

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Area - .NET Core Guide product-question

Most helpful comment

@Henkolicious Sorry that didn't work. I would edit the issue you opened and put all this detail into it. That will help them help you better.

All 4 comments

I believe so. You have to use the https://www.nuget.org/packages/System.ServiceModel.Primitives/ NuGet package to enable it though. They don't ship as part of Core directly.

Let me know if that works for you.

@Thraka Nope, the NuGet did not do the trick.

@Henkolicious Sorry that didn't work. I would edit the issue you opened and put all this detail into it. That will help them help you better.

The same issue, it is impossible reference System.ServiceModel.Web (WebInvoke) on .Net Standard 2.0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JagathPrasad picture JagathPrasad  Â·  3Comments

stanuku picture stanuku  Â·  3Comments

ike86 picture ike86  Â·  3Comments

ygoe picture ygoe  Â·  3Comments

sime3000 picture sime3000  Â·  3Comments