Ciao, sto sviluppando un piccolo servizio wcf da interrogare con un client iPhone iOS.
questa è il metodo che aggiunge un nuovo utente alla app:
Public Sub putUserAccount(username As String, newUser As UserAccount) Implements ILostAndFoundService.putUserAccount
userAccountService = New UserAccountService
Try
userAccountService.CreateUserAccount(newUser)
Catch ex As Exception
Select ex.GetType
Case GetType(UserAccountAlredyExistException)
Throw New WebFaultException(Of String)("User already exists", Net.HttpStatusCode.InternalServerError)
End Select
End Try
End Sub e questa è la sua dichiarazione:
<OperationContract()>
<WebInvoke(Method:="POST", UriTemplate:="users/{username}", ResponseFormat:=WebMessageFormat.Json)>
Sub putUserAccount(ByVal username As String, ByVal newUser As UserAccount) Il servizio accetta correttamente le richieste in formato json, ma se si verifica l'eccezione, questa viene inoltrata in XML (testato con Fiddler)
l'endpointBehaviors nel mio webconfig è il seguente:
<endpointBehaviors>
<behavior name="RestConfiguration">
<webHttp helpEnabled="True" defaultOutgoingResponseFormat="Json" defaultBodyStyle="Bare" faultExceptionEnabled="True" />
</behavior>
</endpointBehaviors> come faccio a restituire il dettaglio dell'eccezione in json e non in xml??