2

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?

1 Answer 1

4
+100

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.