Reputation: 415
I have a soap interface with a boolean function, this function is supposed to return true if everything is succesfully, and false if something goes wrong.
How is it possible to return false + errormessage on a boolean function ?
Upvotes: 0
Views: 63
Reputation: 49230
As a direct answer to your question: yes it is possible, albeit not only using the bool
return type of course. Just pass/provide the message as an out
parameter.
For example:
[OperationContract]
bool MyOperation(/* ... other arguments ..., */ out string message);
You should either consider using exceptions, i.e. faults, as said by @Alexander Stepaniuk, or consider providing a data contract as return type.
For example:
[DataContract]
public class MyResult
{
[DataMember]
public bool Success { get; set; }
[DataMember]
public string ErrorMessage { get; set; }
}
[ServiceContract]
public interface IMyContract
{
[OperationContract]
MyResult MyFunction( /* ... other arguments ... */);
}
For a related discussion see Why would a WCF Contract include a ref/out parameter?.
Upvotes: 0
Reputation: 6408
As your interface assumes to return only bool result you can't return additional string.
If it is suitable in your case then you can generate Exception with specified message on server side rather than just return false
.
In that case SOAP fault is returned by the server as response. SOAP fault contains Exception message. So client knows that request is processed with error and client is able to read error message.
That is standard behavior.
You can find more details here.
Upvotes: 1