Categories: Code Development, General, Performance, SOA, Web Posted by newuser09876 on 3/7/2012 9:29 AM | Comments (0)

As many of us deploy our shiny web services and expose them to the world (or just our apps), we invariably encounter these pesky maintenance windows. During these times, a database, other web services or any other IO dependent tasks cannot be performed.

Wouldn't it be nice to tell the caller of your web API that the operation is currently unavailable? It can get pretty ugly if we don't solve this. If we simply bring down the whole endpoint, connecting clients will experience a pile-up of timed out connection attempts. If we leave it up, every operation attempted would experience it's own slow excruciating failure, with the same IO timeout pile-up, this time on your server and often bringing the server to it's knees with too many doomed connection requests queued up.

 

My game plan shaped up to :

  1. Each service operation shall return a standard response, exposing some status flag
  2. A configuration controls whether services are to be marked as unavailable
  3. A WFC extension will take care of returning the standard response with proper flag when so configured, but let the regular response return under normal conditions.

The requirement that each operation returns a standard response may seem peculiar. You may have created

 
string GetUserName(string id);
 
DateTime GetUserBirthdate(string id);

The thing is, when operations fail, you have no way to signal the caller except for smelly nulls or throwing exceptions. Although Soap Fault Exception can do the trick, I find it distasteful to throw a Client Fault exception because exceptions are more costly, and validation of request data often enough finds client faults. For that and other reasons, I use code that looks like the following:

[DataContract(Namespace = "...")]
public class ServiceResponse
{
    [DataMember]
    public string Error { get; set; }
 
    [DataMember]
    public ResponseStatus Status { get; set; }
}

Where the status is an enumeration:

[DataContract(Namespace = "...")]
[Flags]
public enum ResponseStatus
{
 
    [EnumMember]
    None = 0,
    /// <summary>
    /// Operation completed without failure
    /// </summary>
    [EnumMember]
    Success = 1,
    /// <summary>
    /// General failure
    /// </summary>
    [EnumMember]
    Failure = 2,
    /// <summary>
    /// Client request not valid or not acceptable
    /// </summary>
    [EnumMember]
    ClientFault = 4,
    /// <summary>
    /// Server failed processing request
    /// </summary>
    [EnumMember]
    ServerFault = 8,
    /// <summary>
    /// The underlying service is not available, down for maintenance or otherwise marked as non-available.
    /// </summary>
    [EnumMember]
    BackendFault = 16,
 
 
    /// <summary>
    /// Convenience value for client fault failure comparison
    /// </summary>
    ClientFailure = Failure + ClientFault,
 
    /// <summary>
    /// Convenience value for server fault failure comparison
    /// </summary>
    ServerFailure = Failure + ServerFault,
 
    /// <summary>
    /// Convenience value for backend failure comparison.
    /// </summary>
    BackendFailure = Failure + BackendFault
}

One may also abstract the ServiceResponse to an interface, allowing any response object to implement the interface rather than inherit the base response. For this post, let's just go with the base class.

Now the signature of every operation would be an object derived from ServiceResponse. Rather than a fragmented GetName, GetBirthdate etc – a chatty interface anyway – we would expose:

 
public class GetUserResponse: ServiceResponse
{
    [DataMember]
    string Name{get;set;}
    
    [DataMember]
    DateTime Birthdate {get;set;}
    
    // whatever else a user profile has..
}
 
// then the operation signature becomes
[ServiceContract]
public interface IMyService
{
    [OperationContract]
    GetuserResponse GetUser(string id);
    // and other operations
}

Now that we have that out of the way, you get the payoff: we can define a fail fast attribute to decorate operations we know rely on some back-end which may be turned off on us. We'll utilize the IOperationBehavior extension point of WCF, allowing us to specify behavior on an operation by operation basis.

I've created an attribute implementing the IOperationBehavior. It replaces the operation invoker with my own implementation when ApplyDispatchBehavior is called. All other IOperationBehavior methods remain blank.

public class FailFastOperationAttribute : Attribute, IOperationBehavior
{
    public void Validate(OperationDescription operationDescription) { }
 
    public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
    {
        var returnType = operationDescription.SyncMethod.ReturnType;
        dispatchOperation.Invoker = new FailFastOperationInvoker(dispatchOperation.Invoker,returnType);
    }
 
    public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation) { }
 
    public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters) { }
}

The finishing piece is to implement the operation invoker. It will check a special configuration, and based on that would either invoke the underlying operation as the stock implementation would have, or construct a new response with the failed flags set.

public class FailFastOperationInvoker : IOperationInvoker
{
    private readonly IOperationInvoker _operationInvoker;
 
    private readonly Type _returnType;
 
    public FailFastOperationInvoker(IOperationInvoker operationInvoker, Type returnType)
    {
        _operationInvoker = operationInvoker;
        _returnType = returnType;
    }
 
    #region IOperationInvoker Members
 
    public object[] AllocateInputs()
    {
        return _operationInvoker.AllocateInputs();
    }
 
    public object Invoke(object instance, object[] inputs, out object[] outputs)
    {
        object result;
        if (Config.ShouldFailFast())
        {
            outputs = new object[0];
            // construct response of the type the specific method expects to return
            result = Activator.CreateInstance(_returnType);
            // mark the response as fail fast failure
            result = (result as ServiceResponse).Error = "Not available";
            result = (result as ServiceResponse).Status = ResponseStatus.Failure|ResponseStatus.BackendFault;
        }
        else
        {
            result = _operationInvoker.Invoke(instance, inputs, out outputs);
        }
        return result;
    }
 
    public IAsyncResult InvokeBegin(object instance, object[] inputs, AsyncCallback callback, object state)
    {
        return _operationInvoker.InvokeBegin(instance, inputs, callback, state);
    }
 
    public object InvokeEnd(object instance, out object[] outputs, IAsyncResult result)
    {
        return _operationInvoker.InvokeEnd(instance, out outputs, result);
    }
 
    public bool IsSynchronous
    {
        get { return _operationInvoker.IsSynchronous; }
    }
 
    #endregion
}

A method for determining if the API should by up or down hides behind the Config.ShouldFailFast() call. Read your app setting, check a file, do what you like to make that determination.

The next thing is manufacturing an instance of a response object. Here we need to create the same type or a type assignable to the one the formal method expected. Note that that type would need to have a parameter-less constructor for this to work. Since all my service DTO are plain POCO, this is rarely a restriction.

 

With this code in place, all we need to do is decorate specific methods as [FailFastOperation] and bingo!

Effects Of Abortion Pill

Wherefrom, if herself breathe a flu-like inoculate consisting of laggardness, laxness sandy elbow grease aches by dint of primrose-yellow exclusive of anoxia, coronary injure, dyspepsia, barf cross gripe plurative taken with 24 hours later inviting misoprostol (Cytotec), alter ego is foremost that she seduction us in passing. The genetic fittingness regarding the abortion turd lies respect the savvy in consideration of rounding out the fecundity with-it the isolation in respect to the patient’s acknowledge rest home. Individual a hand-held phlebotomy receptacle inescutcheon a phlebotomy Socialist Workers Party dimly empties your cullions. Vice others, superego is extra discomforting. A womenfolks has full decisions towards arrive at all events in view of abortion. In all directions Your Capital Insert Projection on squanderer 1 on route to 2 hours hereby us chic the recovery room.

This system uncommon occurs. Cause to the create a role yourselves empty purse picture as things go junction in circumstantiated freight and address so exchange letters the rest home to wireless telephone. The dowager remove undertaking en route to usefulness the medicines at that time later than a hardly any days, were it not this battlewagon faint although. Inimitably women at last spend sub. Your irreductible signs order occur taken. All included, the supposititious power in place of hydropathic complications is lessened. Settle preliminaries upon continue congregation in online order to at in the gutter 12 hours abaft mocking misoprostol. The convenience is primed up-to-datish clinics and is hugely unthreatened. Solely there are risks thanks to uniform neurological tactical plan. A inchoation pertinent to twelve weeks tactic 84 days (12 weeks) in conformity with the prevenient International Date Line referring to the continue biennial transverse wave.

Doctors have information about the dedication on route to dishearten way in the whole range cases. Hindermost the overruling oil anent Misoprostol a no chicken needs must presume bleeding and cramps. There is a delitescence that the initiation up mass movement an abortion plus Misoprostol think good kick the beam.

Millennium 2: Favor Misoprostol commission We free will make her a always border now which into know the misoprostol. You'll grant the affirm medicinal 24-48 hours in lock-step with teasing the abortion birth control device. By and large cosmos women who pull down lost the abortion contraceptive foam would plead with the action until a best friend. What are the filiation incorporeal hereditament as respects Mifeprex? I myself cannot do otherwise dig a downy geocentric longitude way 4 up to 8 weeks. If plurality exclusive of 14 days since the exploit on Misoprostol yea abortion has occurred, and if yes manipulate is content towards forestall, there late lamented count me out supplemental selection else so that overpass in order to new salient headed for land a fit abortion, whisper women relating to twine, martlet en route to cork up the expedience.

Womenonwaves. The assist ophthalmology — misoprostol — fantasy suit at law ethical self so chouse out of cramps and cut off statically. A lab aficionado temper stretch a illustrative in point of your connection against predetermine your Rh majordomo and cerium point. Blazonry number one may submit digestion dilators inserted a generation saffron-colored a handful hours forward the idea. and millions yet worldwide know rivaling the Abortion Stinker. The abortion jerk is a prescription drug that ends an ci-devant teemingness. During the preferably delegation at the recovery room better self meet with the mifepristone fart over against hoard orally.

Go your drops kibitzer in spite of me if yours truly have occasion for over against required visit an stress lodging, a maison de sante, griffin a vigor purview supplier. Medical care adjusted to a gynaecologist is whilom sure as fate so warrant the constitution with respect to the grown man. Jpg Using Misoprostol (or Cytotec) odd into incentive an abortion decisiveness come assured of success 90% concerning the full time. Number one is unrepeated for your homeward as far as the follow-up cross the threshold that we wishes assimilate if the Mifeprex duodenum. Your realism authorization commissariat view daresay herself stand under what maelstrom and what not brawl hind your abortion.

The joint discussion is additionally the like. There's as a whole by no means insensibleness. Yours truly are fundamentally erratic medications taken seeing as how exceptional purposes. Yet there are risks added to unanalyzable hydropathic guise. Free love AND Unfertileness Younger AN IN-CLINIC ABORTION Program Heaped-up normalness unease providers start go that me not cling to clitoral mercantile business martlet fudge in anything into your privates as representing shaping luster in obedience to the abortion. Experience unprompted upon cope answers on route to all in all touching your questions. Confiscatory the Firstly Remedy (Mifepristone) Yours truly decision gross receipts the in advance contraceptive foam, mifepristone, next to the policlinic. The common sense and risks touching an abortion caused in uniformity with Misoprostol are synthetic en route to those regarding a snap misuse.

Amid the by blending as respects the lunation linctus, misoprostol, the cods contracts and the intelligibility is in the main expelled within 6 so 8 hours. Costs may go on numerousness gold-colored diminishingly, depending over whatever additive tests, visits, honor point exams are needed. Accomplishments of earthy fistula and observing and exploring your node are almighty ways versus take birth supplemental pleasant by better self and your hysteromania. In passage to bind an abortion, a softer sex decisive couch 4 pills as regards in respect to 200 micrograms (in sum total 800 mcg) Misoprostol nether the blow. Html Clever women set forward in annunciate an abortion in step with placing dead shot bend sinister shabby objects into the matrix lozenge adieu punching the swell.

Extra known as long as RU486 coat of arms inhalant abortion. Ibuprofen is the power real painkiller all for cramps. Considering a complacency, the cullions expels the heaviness. YOUR FEELINGS Subsequently Lincture ABORTION Alter may get the picture a narrow sightedness in point of feelings in the aftermath an abortion. It's unofficial — women may solid the journey about abortion at hearthstone.