Export (0) Print
Expand All

WebOperationContext Class

A helper class that provides easy access to contextual properties of Web requests and responses.

System.Object
  System.ServiceModel.Web.WebOperationContext

Namespace:  System.ServiceModel.Web
Assembly:  System.ServiceModel.Web (in System.ServiceModel.Web.dll)

public class WebOperationContext : IExtension<OperationContext>

The WebOperationContext type exposes the following members.

  NameDescription
Public methodWebOperationContextInitializes a new instance of the WebOperationContext class with the specified OperationContext instance.
Top

  NameDescription
Public propertyStatic memberCurrentGets the current Web operation context.
Public propertyIncomingRequestGets the Web request context for the request being received.
Public propertyIncomingResponseGets the Web response context for the request being received.
Public propertyOutgoingRequestGets the Web request context for the request being sent.
Public propertyOutgoingResponseGets the Web response context for the response being sent.
Top

  NameDescription
Public methodAttachAttaches the current WebOperationContext instance to the specified OperationContext instance.
Public methodCreateAtom10Response(ServiceDocument)Creates a message formatted according to the Atom 1.0 specification with the specified content.
Public methodCreateAtom10Response(SyndicationFeed)Creates a message formatted according to the Atom 1.0 specification with the specified content.
Public methodCreateAtom10Response(SyndicationItem)Creates a message formatted according to the Atom 1.0 specification with the specified content.
Public methodCreateJsonResponse<T>(T)Creates a JSON formatted message.
Public methodCreateJsonResponse<T>(T, DataContractJsonSerializer)Creates a JSON formatted message.
Public methodCreateStreamResponse(Action<Stream>, String)Creates a stream formatted message.
Public methodCreateStreamResponse(Stream, String)Creates a stream formatted message.
Public methodCreateStreamResponse(StreamBodyWriter, String)Creates a stream formatted message.
Public methodCreateTextResponse(String)Creates a text formatted response message.
Public methodCreateTextResponse(Action<TextWriter>, String)Creates a text formatted message
Public methodCreateTextResponse(String, String)Creates a text formatted message.
Public methodCreateTextResponse(Action<TextWriter>, String, Encoding)Creates a text formatted message
Public methodCreateTextResponse(String, String, Encoding)Creates a text formatted message.
Public methodCreateXmlResponse(XDocument)Creates an XML formatted message.
Public methodCreateXmlResponse(XElement)Creates an XML formatted message.
Public methodCreateXmlResponse<T>(T)Creates an XML formatted message.
Public methodCreateXmlResponse<T>(T, XmlObjectSerializer)Creates an XML formatted message.
Public methodCreateXmlResponse<T>(T, XmlSerializer)Creates an XML formatted message.
Public methodDetachDetaches the current WebOperationContext instance from the specified OperationContext instance.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetUriTemplateGets the URI template associated with the specified operation.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The following code shows how to retrieve the UriTemplateMatch instance associated with the Web operation context of the current call. The code also shows how to set the HTTP status for the outgoing response.

counter++;

UriTemplateMatch match = WebOperationContext.Current.IncomingRequest.UriTemplateMatch;

UriTemplate template = new UriTemplate("{id}");
customer.Uri = template.BindByPosition(match.BaseUri, counter.ToString());

customers[counter.ToString()] = customer;

WebOperationContext.Current.OutgoingResponse.SetStatusAsCreated(customer.Uri);

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft