本文整理匯總了C#中System.ServiceModel.Channels.HttpRequestMessageProperty.Method屬性的典型用法代碼示例。如果您正苦於以下問題:C# HttpRequestMessageProperty.Method屬性的具體用法?C# HttpRequestMessageProperty.Method怎麽用?C# HttpRequestMessageProperty.Method使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.ServiceModel.Channels.HttpRequestMessageProperty
的用法示例。
在下文中一共展示了HttpRequestMessageProperty.Method屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ProcessMessage
public Message ProcessMessage(Message request)
{
Message response = null;
//The HTTP Method (e.g. GET) from the incoming HTTP request
//can be found on the HttpRequestMessageProperty. The MessageProperty
//is added by the HTTP Transport when the message is received.
HttpRequestMessageProperty requestProperties =
(HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
//Here we dispatch to different internal implementation methods
//based on the incoming HTTP verb.
if (requestProperties != null)
{
if (String.Equals("GET", requestProperties.Method,
StringComparison.OrdinalIgnoreCase))
{
response = GetCustomer(request);
}
else if (String.Equals("POST", requestProperties.Method,
StringComparison.OrdinalIgnoreCase))
{
response = UpdateCustomer(request);
}
else if (String.Equals("PUT", requestProperties.Method,
StringComparison.OrdinalIgnoreCase))
{
response = AddCustomer(request);
}
else if (String.Equals("DELETE", requestProperties.Method,
StringComparison.OrdinalIgnoreCase))
{
response = DeleteCustomer(request);
}
else
{
//This service doesn't implement handlers for other HTTP verbs (such as HEAD), so we
//construct a response message and use the HttpResponseMessageProperty to
//set the HTTP status code to 405 (Method Not Allowed) which indicates the client
//used an HTTP verb not supported by the server.
response = Message.CreateMessage(MessageVersion.None, String.Empty, String.Empty);
HttpResponseMessageProperty responseProperty = new HttpResponseMessageProperty();
responseProperty.StatusCode = HttpStatusCode.MethodNotAllowed;
response.Properties.Add( HttpResponseMessageProperty.Name, responseProperty );
}
}
else
{
throw new InvalidOperationException( "This service requires the HTTP transport" );
}
return response;
}