Thursday, 31 July 2014

Increasing request limit quota in WCF/REST Service

Customizing webHttpBinding in web.config and referencing with bindingConfiguration in endpoint element
<system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="AmmuEndPointServiceBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="AmmuServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <!-- Customizations for REST service -->
      <webHttpBinding>
        <!-- Limits set to 10 MB (specified value in bytes) -->
        <binding name="AmmuBinding" maxReceivedMessageSize="10485760" maxBufferPoolSize="10485760" maxBufferSize="10485760" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00">
          <readerQuotas maxDepth="32" maxStringContentLength="10485760" maxArrayLength="10485760" maxBytesPerRead="10485760" />
          <security mode="None" />
        </binding>
      </webHttpBinding>
    </bindings>
  
    <services>
      <service name="Amalay.Web.Services.AmmuService" behaviorConfiguration="AmmuServiceBehavior">
        <endpoint address="" binding="webHttpBinding" contract="Amalay.Web.Services.IAmmuService" bindingConfiguration="AmmuBinding" behaviorConfiguration="AmmuEndPointServiceBehavior" />
      </service>
    </services>

    <serviceHostingEnvironment aspNetCompatibilityEnabled= "true" multipleSiteBindingsEnabled="true"  />

  </system.serviceModel>

HTTP status codes

1xx – Informational: These status codes indicate a provisional response. The client should be prepared to receive one or more 1xx responses before receiving a regular response.

100 - Continue.
101 - Switching protocols.

2xx – Success: This class of status codes indicates that the server successfully accepted the client request.

200 - OK. The client request has succeeded.
201 - Created.
202 - Accepted.
203 - Non-authoritative information.
204 - No content.
205 - Reset content.
206 - Partial content.
3xx – Redirection: The client browser must take more action to complete the request. For example, the browser may have to request a different page on the server or repeat the request by using a proxy server.

301 - Moved Permanently
302 - Object moved Temporarily
303 - See Other
304 - Not modified.
307 - Temporary redirect.
4xx - Client Error: An error occurs, and the client appears to be at fault. For example, the client may request a page that does not exist, or the client may not provide valid authentication information.

400 - Bad request.
401 - Access denied. IIS defines a number of different 401 errors that indicate a more specific cause of the error. These specific error codes are displayed in the browser but are not displayed in the IIS log:


403 - Forbidden. IIS defines a number of different 403 errors that indicate a more specific cause of the error:


404 - Not found. 404.0 - (None) – File or directory not found.


405 - HTTP verb used to access this page is not allowed (method not allowed.)
406 - Client browser does not accept the MIME type of the requested page.
407 - Proxy authentication required.
412 - Precondition failed.
413 – Request entity too large.
414 - Request-URI too long.
415 – Unsupported media type.
416 – Requested range not satisfiable.
417 – Execution failed.
423 – Locked error.

5xx - Server Error: The server cannot complete the request because it encounters an error.

500 - Internal server error.

501 - Header values specify a configuration that is not implemented.
502 - Web server received an invalid response while acting as a gateway or proxy.


503 - Service unavailable. This error code is specific to IIS 6.0.
504 - Gateway timeout.
505 - HTTP version not supported.

Removing HTML tags from Input String in Sql Server

CREATE FUNCTION [dbo].[FN_AMMU_REMOVE_HTML_TAGS]
(
@INPUT_STRING NVARCHAR(MAX)
)
   
RETURNS NVARCHAR(MAX)
AS
BEGIN
    DECLARE @Start INT, @End INT, @Length INT;
   
    WHILE CHARINDEX('<', @INPUT_STRING) > 0 AND CHARINDEX('>', @INPUT_STRING, CHARINDEX('<', @INPUT_STRING)) > 0
    BEGIN
        SET @Start  = CHARINDEX('<', @INPUT_STRING);
        SET @End    = CHARINDEX('>', @INPUT_STRING, CHARINDEX('<', @INPUT_STRING));
        SET @Length = (@End - @Start) + 1;
       
        IF @Length > 0
        BEGIN
            SET @INPUT_STRING = STUFF(@INPUT_STRING, @Start, @Length, '')
        END
     END
   
    RETURN RTRIM(@INPUT_STRING);
END