I have to implement the following scenario:
In a SOAP service I'd just return something like the following:
class ProcessingResult {
public:
bool IsFailed;
string ErrorMessage;
byte[] ResultData;
};
and the middleware would properly serialize this over the wire, then the client proxy (produced by parsing WSDL) would deserialize it and the client would be happy.
How do I desing something similar in a WCF REST service?
You can do the same in REST service. Here is the service contract:
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(Method = "POST")]
ProcessingResult ProcessData(byte[] data);
}
public class ProcessingResult
{
public bool IsFailed { get; set; }
public string ErrorMessage { get; set; }
public byte[] ResultData { get; set; }
}
All byte arrays will be send as base64 encoded string. Example of request message:
<base64Binary xmlns="http://schemas.microsoft.com/2003/10/Serialization/">QmFzZSA2NCBTdHJlYW0=</base64Binary>
Example of response message:
<ProcessingResult xmlns="http://schemas.datacontract.org/2004/07/RestService">
<ErrorMessage>String content</ErrorMessage>
<IsFailed>true</IsFailed>
<ResultData>QmFzZSA2NCBTdHJlYW0=</ResultData>
</ProcessingResult>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.