views:

446

answers:

1

I'm using the ChannelFactory in WCF to call into a REST service and I want to determine whether the server returned HTTP 200 or 201 in response to a PUT call. Currently, the call succeeds, but I can't determine if my object was created or updated. How can I do this?

+2  A: 

WCF is designed for all sorts of channels so this is not a high level object

You can access it though with something like this

factory.Endpoint.Behaviors.Add(new WebHttpBehavior());
IMyContract proxy = factory.CreateChannel();
using (OperationContextScope scope = new OperationContextScope((IContextChannel)proxy)) {
    proxy.MyMethod("Some data"));
    var responseCode = WebOperationContext.Current.IncomingResponse.StatusCode;
}
((IClientChannel)proxy).Close();
factory.Close();
TFD