开发者

How to implement custom fault contract in WCF?

Here are my interface and it's implementation class file. While implenting service function there is a chance to get 3 exceptions.

I need to handle these using a custom fault contract. Can you plase tell me how to implement 3 exceptions under one fault contract.

Interface:

Function GetEntities() As String

Class file that use the service Interface:

Public Function GetEntities() As String

     Dim result As String = Nothing
    Dim ds As New DataSet

    'Result string from Mapping file.
    Dim resultFrmMap As String = ReadXML(entity)  //Here need to handle exception.

    Using con As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("MainDBConnectionString").ToString())
        con.Open()
        Dim cmd As New SqlCommand(resultFrmMap, con)

        Using Da As New SqlDataAdapter(cmd)
        开发者_如何学Go    ds.Clear()

            Da.TableMappings.Add("Table", "Data")
            Da.Fill(ds)
            cmd.Dispose()
        End Using

    End Using  //Here need to handle exception.

    result = GetXML(ds)  //Here need to handle exception.



    Return result

End Function

Regards, jn


Create a DataContract class that models the fault detail (lets call it FaultDetails for now) and use this with the FaultContract attribute to annotate the GetEntities method in the service contract

Now in your GetEntities method catch the three exceptions and throw a FaultException(Of FaultDetails)

Either that or handle the translation centrally using IErrorHandler

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜