Monday, April 1, 2013

WCF Durable Services


http://componotech.com/2008/01/wcf-durable-services/
Overview
Durable Services are a new type of service for .NET 3.5 that allow developers to easily manage long running conversations between a service and its clients. The framework provides persistent (durable) state information between calls by serializing state information after each call for each client. That state information can be stored in a database, file system, or any other non-transient store. When each subsequent call is made by the client, the service automatically retrieves the associated state using a token passed in the SOAP header or HTTP cookie. The token is available to the service through the DurableOperationContext.InstanceId.
Durable Services…
· Automatically manage long running conversations. Even if a session is destroyed, the state information is persisted and can be restored at a later time.
· Provide automatic and durable (across machine reboots, session destruction, etc.) state information via pluggable provider. You can configure SqlPersistenceProviderFactory or create a custom child of PersistenceProviderFactory.
· Durable Services use conversation tokens to keep track of client’s state. These tokens are automatically propagated in the SOAP header or http cookie.
· There are new context bindings that support managing the context token between client and service:
o WSHttpContextBinding
o NetTcpContextBinding
o BasicContextBinding
Alternatively you can create a custom binding to which you add a context binding element.
· Durable Services will almost always be used in conjunction with Workflow Services.
Even though all of the durable service classes live in the System.ServiceModel.* namespaces, they exist in the System.WorkflowServices assembly. Now why would Microsoft place the durable service classes in the System.WorkflowServices? I think it’s because durable Services are really the glue that makes WCF and WF such complimentary technologies. WCF abstracts out the protocol and other plumbing specifics that application developers shouldn’t have to deal with. WF provides a new way of mapping business processes and other workflows to often long running activities. When used together, application developers theoretically can focus on writing business specific code in a highly maintainable, easily configurable environment.
Implementation
The implementation of durable services is very similar to implementing reliable sessions. W00t! for a unified programming model! If you have experience with reliable sessions, this should be somewhat reminiscent. We will use the SqlPersistenceProviderFactory that comes with the framework. First, we have to setup the store by running these scripts:
“%windir%\Microsoft.Net\Framework\v3.5\SQL\EN\SqlPersistenceService_Schema.sql”
“%windir%\Microsoft.Net\Framework\v3.5\SQL\EN\SqlPersistenceService_Logic.sql”
Here is what my configuration file looks like. Notice the new wsHttpContextBinding as well as the persistenceProvider section under the behavior configuration. There are several configuration settings that you can change that I won’t go into here. Check it out on MSDN or play around with the Service Configuration Editor tool.
Finally, here and here are the ultra simple service interface and service type implementation. Notice that the InstanceId Guid is available through the DurableOperationContext.InstanceId property. When a client passes the context token to the service, the framework automatically uses the token to rehydrate that client’s state.
As always, if you have any questions please feel free to email me.
More about Durable Services:



Tutorial: Create a Durable Service
.NET Framework 3.5
3 out of 3 rated this helpful - Rate this topic
Durable services are Windows Communication Foundation (WCF) services that use context bindings, attributes, and new configuration elements to persist service state information to a store, such as a SQL database, which means that durable services have the capability to restore their own state when they are recycled. Durable services are useful when implementing long-running stateful conversations.
In this tutorial, you will create a durable service that persists its state information to a SQL database.
In This Section
Reference


Task 1: Define and Implement the Durable Service Contract
.NET Framework 3.5
0 out of 2 rated this helpful - Rate this topic
In this task, you will define and implement the service contract for your durable service.
Defining the contract
1.      Open Visual Studio 2008, click File, and select New and then Project.
2.      In the New Project dialog box, under WCF, select the WCF Service Library template.
3.      Name your project SimpleDurableService and click OK.
Visual Studio 2008 generates the following files for your WCF service: an App.config file to store configuration settings, a source file that contains a contract definition, and a source file that contains the service class that implements the contract definition.
The template creates a service with two operations and a data contract for a custom type. In this tutorial, you will define new operations for your durable service.
4.      Open IService1.cs (or IService1.vb if you created a Visual Basic solution) and replace the existing interface definition with the following code and remove the existing DataContractAttribute definition.
C#
[ServiceContract]
public interface IService1
{
    [OperationContract]
    int Add(int n1);

    [OperationContract]
    int Subtract(int n1);

    [OperationContract]
    int Multiply(int n1);

    [OperationContract]
    void EndPersistence();
}

1.      Open Service1.cs (or Service1.vb if you created a Visual Basic solution).
2.      Implement the updated IService1 interface in your Service1 class definition.

Visual Studio automatically creates default implementations for your interface methods, which you will modify in the next step.
3.      Modify the existing class definition to perform the appropriate logic as shown in the following code:
C#
public class Service1 : IService1
{
    int currentValue = default(int);

    #region IService1 Members

    public int Add(int n1)
    {
        return (currentValue += n1);
    }

    public int Subtract(int n1)
    {
        return (currentValue -= n1);
    }

    public int Multiply(int n1)
    {
        return (currentValue *= n1);
    }

    public void EndPersistence()
    {
    }
    #endregion
}

At this point, the WCF service you created is exactly the same as any WCF service you created in .NET Framework 3.0. The next task will show you how to take this service and persist its current state to a persistence store so that in the event your service is disconnected from the client, you can communicate with the client again at a later time from the last successful operation that was invoked.


Task 2: Enable Persistence for the Durable Service
.NET Framework 3.5
This topic has not yet been rated - Rate this topic
In this task, you will decorate the service you created in Task 1 with attributes that enable you to persist the state of your service after every successful operation invocation.
To decorate the service with durable service attributes
1.      Open Service1.cs (or Service1.vb if you created a Visual Basic solution).
2.      In the Solution Explorer pane, under the SimpleDurableService project node, right-click the References subfolder and select Add Reference.
3.      In the Add Reference dialog box, under the .NET tab, select System.WorkflowServices and click OK.
4.      Add the following using statement in your C# source file:
C#
using System.ServiceModel.Description;

If you created a Visual Basic solution, right-click the SimpleDurableService project node and select Properties. Select the References tab, and under Imported Namespaces, check System.ServiceModel.Description.
1.      To persist your service, you must decorate the Service1 class with the DurableServiceAttribute and SerializableAttribute attributes as shown in the following example.

C#
[Serializable]
[DurableService]
public class Service1 : IService1
{
    // The class definition was omitted for clarity.
}

1.      The DurableServiceAttribute attribute specifies that state information for your WCF service can be persisted to a persistence store, such as a database or file. Also, the service type must be serializable so that it can be transmitted to the persistence store.
2.      Decorate the service operations with the DurableOperationAttribute attribute as shown in the following example. This attribute specifies that the service instance state will be saved after the operation has completed.

C#
[DurableOperation(CanCreateInstance = true)]
public int Add(int n1)
{
    return (currentValue += n1);
}

[DurableOperation]
public int Subtract(int n1)
{
    return (currentValue -= n1);
}

[DurableOperation]
public int Multiply(int n1)
{
    return (currentValue *= n1);
}

[DurableOperation(CompletesInstance = true)]
public void EndPersistence()
{
}

The CanCreateInstance and CompletesInstance properties specify that the durable service instance will either be created or completed after the decorated operation has successfully completed. In this tutorial, several operations have the first and last operations controlling the behavior of the service instance.
Operations that are decorated with the DurableOperationAttribute attribute set to default values can only persist state information to an existing service instance entry in the persistence store. However, if you create a service contract where System.ServiceModel.SessionMode.NotAllowed is set to true, every DurableOperationAttribute attribute must have the CanCreateInstance property set to true.
Now that your service is decorated with the proper attributes, you must set up your configuration file and reference the persistence store you want to use.
To configure your durable service
1.      Open App.config.
2.      Modify the endpoint configuration settings to reference a context binding, such as WSHttpContextBinding.
<endpoint address ="" binding="wsHttpContextBinding" contract="SimpleDurableService.IService1" />
Context bindings must be used because a DurableOperationContext is used by the client to identify a specific service instance. After invoking a request/response operation and receiving a response from the service, the client will use the InstanceId value on each subsequent operation invocation so that the client associates itself with the correct service instance. If this tracking mechanism was not used, then when a service instance is either shut down or disconnected from the client, the client would not be able to reestablish a connection to a specific service instance.
3.      Add the following child node to your behavior node.
<behaviors>
      <serviceBehaviors>
        <behavior name="SimpleDurableService.Service1Behavior">
          <!-- To avoid disclosing metadata information,
          set the following value to false and remove the preceding metadata endpoint before deployment. -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes,
          set the following value to true. Set the value to false before deployment
          to avoid disclosing exception information. -->
          <serviceDebug includeExceptionDetailInFaults="False" />
          <persistenceProvider type="System.ServiceModel.Persistence.SqlPersistenceProviderFactory, System.WorkflowServices, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                               connectionStringName="DurableServiceStore"
                               persistenceOperationTimeout = "00:00:10"
                               lockTimeout="00:01:00"
                               serializeAsText="true"/>

        </behavior>
      </serviceBehaviors>
    </behaviors>
The PersistenceProviderElement defines the type of PersistenceProvider that your service will use. In this tutorial, the SqlPersistenceProviderFactory is used to create a new instance of the PersistenceProvider type that connects to a SQL database. Whenever the Add operation is invoked and successfully completes, a new service instance will be created and its state information will be stored in the SQL database.
4.      Add the connection string for the SQL database that your service instance will use for persistence.
  </system.serviceModel>
  <connectionStrings>
    <add name="DurableServiceStore" connectionString="Data Source=localhost\SQLEXPRESS;Initial Catalog=NetFx35Samples_DurableServiceStore;Integrated Security=SSPI"/>
  </connectionStrings>
</configuration>
Bb675272.note(en-us,VS.90).gifNote:
This tutorial uses the same database that is used for the Durable Workflow Services Sample; therefore, the connection string is the same. To allow access to the durable store, run the Createstores.cmd script from One-Time Setup Procedure for the Windows Communication Foundation Samples.



Task 3: Create a Durable Service Client
.NET Framework 3.5
1 out of 1 rated this helpful - Rate this topic
In this task, you will create a simple client to invoke operations on your durable service. The testing tool WcfTestClient.exe is used by the WCF Service Library template.
Creating the client
1.      In the SimpleDurableService solution, right-click the solution node in the Solution Explorer pane.
2.      Navigate to Add and select New Project.
3.      In the New Project dialog box, under Windows, select Console Application.
4.      Name your project DurableServiceTestClient and click OK.
5.      Right-click the DurableServiceTestClient project node and select Add Reference.
6.      In the Add Reference dialog box, in the .NET tab, select the System.ServiceModel assembly and click OK.
7.      Add the following using statement to your C# source file:
VB
Imports System.ServiceModel

If you created a Visual Basic solution, right-click the DurableServiceTestClient project node and select Properties. Select the References tab, and under Imported Namespaces, check System.ServiceModel.
1.      Use SvcUtil.exe to generate the proxy code and configuration file for your durable service.

Using SvcUtil.exe

To use SvcUtil.exe, see ServiceModel Metadata Utility Tool.

After you have generated your proxy code and configuration files, add those files to your DurableServiceTestClient project by doing the following:
1.      Navigate to the Solution Explorer pane.
2.      Right-click the DurableServiceTestClient project node.
3.      Highlight Add and select Existing Item.
4.      Navigate to the folder where SvcUtil.exe generated the configuration and proxy code files.
5.      Select the files and click OK.
6.      Rename your configuration file to App.config if it is not named that already.
2.      Add the following code to your Main method implementation:

C#
static void Main(string[] args)
{
    Service1Client client = new Service1Client("WSHttpContextBinding_IService1");
    client.Open();
    int currentValue = default(int);
    currentValue = client.Add(3);
    Console.WriteLine("The current value is {0}", currentValue);
    currentValue = client.Subtract(4);
    Console.WriteLine("The current value is {0}", currentValue);
    currentValue = client.Multiply(5);
    Console.WriteLine("The current value is {0}", currentValue);
    client.EndPersistence();
    Console.WriteLine("Press <ENTER> to shut down the client.");
    Console.ReadLine();
    client.Close();
}

Durable service clients are created in the same way as regular WCF service clients. A new instance of the client is created based off of the proxy code of the service. Next, a call to Open is made followed by the invocation of the service operations. Finally, a call to Close is made to shut down the client.
1.      To use the client with your durable service in the SimpleDurableService solution, you must delete a command-line argument from the SimpleDurableService project properties. To do so, perform the following steps:
1.      Right-click the SimpleDurableService project node and select Properties.
2.      Select the Debug tab, and in the detail pane under Start Options, remove /client:"WfcTestClient.exe" from the text box.
2.      Right-click the SimpleDurableService solution node and select Properties.
3.      In the Property Pages dialog box, select Multiple startup projects.
4.      If SimpleDurableService is not listed as the top item in the list, use the arrows on the side of the list box to make it the top item. This is needed so that your service starts running before your client application tries to invoke any operations on the service.
5.      For each project in the list, change the action from None to Start.
6.      Click Apply and then OK.
7.      Build both the service and client projects. You can host your durable service in IIS, a Windows application, or any other host process, but for the purposes of this tutorial, you will host it in WfcSvcHost.exe. WcfSvcHost.exe is a developer tool that hosts services for testing purposes.

You should observe the following output from the client's command-line interface:
The current value is 3
The current value is -1
The current value is -5
Press <ENTER> to shut down the client.
One way to observe that persistence is occurring after every operation (with the exception of EndPersistence), is to install Microsoft SQL Server Management Studio Express from http://www.microsoft.com/downloads and set debug points throughout your client app. After you hit those points, observe the InstanceData table in the NetFx35Samples_DurableServiceStore database. You should see a new entry being added to the table, then updated after every operation until the EndPersistence call completes, at which time the table entry will be removed.

Another way to see the value of the durable service is to make the first operation invocations to the service from your client and in Visual Studio put a breakpoint on the operation invocation. Before executing the third operation invocation, shut the service down and restart the service. Now make the operation invocation. The state of the service is now restored from the persistence database and you will be able to see that the service gives you back the reply desired for the current value.


WCF : What are durable services ?


Durable services are Windows Communication Foundation (WCF) services that use context bindings, attributes, and new configuration elements to persist service state information to a store, such as a SQL database, which means that durable services have the capability to restore their own state when they are recycled. Durable services are useful when implementing long-running stateful conversations.
In this tutorial, you will create a durable service that persists its state information to a SQL database.

From 4guysfromrolla


 http://aspnet.4guysfromrolla.com/default.aspx



Recommended ASP.NET Articles...

Ajax
An Introduction to AJAX and Atlas with ASP.NET 2.0
Building Interactive User Interfaces with Microsoft ASP.NET AJAX: Part 1 [Part 2] [Part 3] [Part 4] [Part 5] [Part 6] [Part 7] [Part 8] [Part 9] [Part 10] [Part 11] 
Creating an AJAX-Enabled Calendar Control
Disabling a User Interface Element During a Partial Page Postback
Periodically Updating the Screen and Web Page Title with ASP.NET AJAX
Creating a Filtering User Interface With jQuery In a Web Forms Application: Part 1 [Part 2]
Accessing Server-Side Data from Client Script (Part 1) [Part 2] [Part 3]
 
MVC
Implementing the Store Locator Application Using ASP.NET MVC (Part 1) [Part 2]
Using the Chart Controls with ASP.NET MVC
Displaying a Grid of Data in ASP.NET MVC [Sorting] [Paging] [Filtering] [Sorting and Paging] [Sorting, Paging, and Filtering] [Using MvcContrib Grid]
 
Website Layout and Design
A Sneak Peak at MasterPages in ASP.NET 2.0
Passing Information Between Content and Master Pages
ASP.NET Master Page Advice, Tips, and Tricks
Examining ASP.NET 2.0's Site Navigation - Part 1 [Part 2] [Part 3] [Part 4] [Part 5] 
Dynamically Setting the Page's Title in ASP.NET 2.0
Programmatically Creating Context-Sensitive Help on a Web Page
Creating CSS Friendly Websites with ASP.NET 2.0
Displaying Random Images in an ASP.NET Web Page
Implementing Incremental Navigation with ASP.NET
Improving CSS With .LESS
Displaying Multimedia Content In A Floating Window Using FancyBox
 
Using Visual Studio
A Look Forward at Microsoft's Visual Web Developer 2005
Creating and Using Code Snippets in Visual Studio 2005
Improved Debugging with Visual Studio 2005's Debugger Visualizers
An Overview of ASP.NET 3.5 and Visual Studio 2008
My Favorite New Features in Visual Studio 2010
Visual Basic 2010 Language Enhancements
C# Adds Optional and Named Arguments
 
Working With and Displaying Data
A Sneak Peak at Working with Data in ASP.NET 2.0
Accessing and Updating Data in ASP.NET: Data Source Control Basics [Part 2] [Part 3] [Part 4] [Part 5] [Part 6] [Part 7] [Part 8] [Part 9] [Part 10] [Part 11] [Part 12] [Part 13] [Part 14] [Part 15] 
Working with Databases in ASP.NET 2.0 and Visual Studio 2005
GridView Examples for ASP.NET 2.0
Using Strongly-Typed Data Access in Visual Studio 2005 and ASP.NET 2.0
Returning Ranked Results with Microsoft SQL Server 2005
Custom Paging in ASP.NET 2.0 with SQL Server 2005 [Sorting Custom Paged Results] [Filtering Custom Paged Results]
Checking All CheckBoxes in a GridView [Adding a "Check/Uncheck All" Header CheckBox] [Using jQuery]
A Multitude of Tutorials that Examine Working with Data in ASP.NET 2.0
Creating a Tag Cloud in ASP.NET
Storing Binary Files Directly in the Database Using ASP.NET 2.0
Deploying a Local Database to a Remote Web Host
Debugging SQL Server 2005 Stored Procedures in Visual Studio
Displaying Extended Details in a GridView Using an Ajax Pop-Up (Part 1) [Part 2]
Using ASP.NET 3.5's ListView and DataPager Controls: Displaying Data with the ListView [Grouping Data] [Sorting Data] [Paging Through Data] [Grouping By a Data Field] [Deleting Data] [Editing Data] [Inserting Data] [Creating an SEO-Friendly Paging Interface] [The Ultimate DataPager Interface]
Extending the GridView to Include Sort Arrows [Improving the Sort Arrows GridView Control]
Importing an Excel Spreadsheet Using Typed DataSets and TableAdapters: Building the Database [Building the Importer Web Page and Uploading the Excel Spreadsheet] [Displaying the Uploaded Excel Spreadsheet] [Creating a Data Access Layer (DAL)] [Importing the Excel Spreadsheet]
Working with XML Data Using LINQ, a TreeView, and a ListView :: Displaying Data [Editing Data]
Displaying Detail Records for User-Selected Master Records :: Using a Dynamic IN Clause [Saving the User's Search Preferences]
Creating a Databound Label Control
Creating a Dynamic Data-Driven User Interface (Part 1) [Part 2] [Part 3] [Part 4]
Programmatically Retrieving a Stored Procedure's Parameters
Retrieving the Just-Inserted ID of an IDENTITY Column Using a SqlDataSource Control
New Date Data Types in Microsoft SQL Server 2008
An Extensive Examination of LINQ: An Introduction to LINQ [Part 2] [Part 3] [Part 4] [Part 5] [Part 6] [Part 7] [Part 8] [Part 9] [Part 10] 
Using SqlBulkCopy To Perform Efficient Bulk SQL Operations [Using Transactions with SqlBulkCopy]
A Look at the GridView's New Sorting Styles in ASP.NET 4
Filtering Data Using ASP.NET 4's QueryExtender Control
Displaying Files and Folders in a GridView
 
System Architecture
A Look at ASP.NET 2.0's Provider Model
Examining ASP.NET 2.0's Membership, Roles, and Profile - Part 1 [Part 2] [Part 3] [Part 4] [Part 5] [Part 6] [Part 7] [Part 8] [Part 9] [Part 10] [Part 11] [Part 12] [Part 13] [Part 14] [Part 15] [Part 16] [Part 17] [Part 18] 
Creating a Login Overlay
Using ASP.NET, Membership, and jQuery to Determine Username Availability
Apply ASP.NET Authentication and Authorization Rules to Static Content with IIS 7.0's Integrated Pipeline Feature
Gracefully Responding to Unhandled Exceptions - Displaying User-Friendly Error Pages [Processing Unhandled Exceptions]
Creating Custom Configuration Sections in
Web.config
[Using .NET 2.0's Configuration API]
Health Monitoring in ASP.NET 2.0: The Basics [Part 2] [Part 3] 
Rolling Your Own Website Administration Tool - Part 1 [Part 2]
Using Coordinated Universal Time (UTC) to Store Date/Time Values [Advice for Storing and Displaying Dates and Times Across Different Time Zones]
Taking an ASP.NET 2.0 Application Offline
Using ASP.NET Routing Without ASP.NET MVC [URL Routing in ASP.NET 4] [Dissecting ASP.NET Routing]
Exception Handling Advice for ASP.NET Web Applications
Querying a Multi-Tenant Data Architecture
Techniques for Preventing Duplicate URLs in Your Website
 
Working with Web Controls
Dissecting the Validation Controls in ASP.NET 2.0
Creating a Step-by-Step User Interface with the ASP.NET 2.0 Wizard Control: The Basics [Improving and Customizing the User Experience]
Customizing the CreateUserWizard Control [Customizing the CreateUserWizard Control To Display a Fixed Set Of Security Questions]
Using the TreeView Control and a DataList to Create an Online Image Gallery
Creating Validator Controls for the CheckBox and CheckBoxList |
Disabling the Submit Button Until a CheckBox is Checked
Creating a TextBox Word / Character Counter Control [Updates to the TextBox Word / Character Counter Control]
Working Around ASP.NET's HyperLink ImageUrl Bug
Picking Dates with a Free RJS PopCalendar, a Free ASP.NET Popup Calendar Control
Displaying a Message in Response to Some Action and Then Hiding It on Subsequent Postbacks
RedirectButton - Redirect Users With the Click of a Button
Creating a "What I'm Reading" Widget
Take Control Of Web Control ClientID Values in ASP.NET 4
Data Web Controls Enhancements in ASP.NET 4
Managing View State in ASP.NET 4 Using the New ViewStateMode Property
Focusing and Selecting the Text in ASP.NET TextBox Controls
 
Security
Encrypting Configuration Information in ASP.NET 2.0 Applications
An Overview of Cryptographic Systems and Encrypting Database Data [Using Symmetric Encryption in a SQL Server 2005 Database] [Using Asymmetric Encryption and Digital Signatures in a SQL Server 2005 Database]
 
Network Functions
Sending Email in ASP.NET 2.0 [HTML-Formatted Emails, Attachments, and Gracefully Handling SMTP Exceptions] [Reply-To, Priority, and Read Receipts]
Emailing the Rendered Output of an ASP.NET Web Control in ASP.NET 2.0
Returning an IPv4 Address in an IPv6-Enabled Environment
Parsing HTML Documents with the Html Agility Pack
 
Caching
Output Caching in ASP.NET 2.0
Extending ASP.NET Output Caching
 
Miscellaneous Topics
Accessing Embedded Resources through a URL using
WebResource.axd
Client-Side Enhancements in ASP.NET 2.0
Creating a Quick and Dirty Online Blackjack Game
A Look at ASP.NET 2.0's URL Mapping
Persisting Page State in ASP.NET 2.0
Personalizing RSS Feeds with ASP.NET 2.0
Building a User Control that Displays RSS Feeds Using a DataList and an XmlDataSource Control
Creating an ASP.NET 2.0 Polling User Control: Design Decisions and the Data Model [Building the Polling User Control] [Creating Administration Web Pages]
Hosting ASP.NET Applications in Medium Trust
Resetting Scroll Position When Using
MaintainScrollPositionOnPostback
Extending Base Type Functionality with Extension Methods
Dissecting ASP.NET Version 3.5's Web.config File
Creating an Online Boggle Solver :: Building the User Interface [Solving the Puzzle] [Using jQuery Templates and WCF]
Warning the User when Caps Lock is On
Techniques for Randomly Reordering an Array
Helping Visitors Search Your Site By Creating an OpenSearch Provider
Modifying the HTTP Response Using Filters
Key Configuration Settings When Deploying a Web Application
Locking the Screen During a Postback
Using Expression Builders in ASP.NET [skmExpressionBuilders - A Suite of Custom Expression Builder Classes]
Syndicating and Consuming RSS 1.0 (RDF) Feeds in ASP.NET 3.5
An Overview of Partial Classes and Partial Methods
Four Little Known, Helpful Methods, Properties, and Features for ASP.NET Developers
Accessing Images On Flickr From An ASP.NET Website Using The Flickr.Net Library
Removing Unnecessary HTTP Headers in IIS and ASP.NET
Adding a Color Picker Control To Your ASP.NET Application
Integrating Twitter Into An ASP.NET Website [Integrating Twitter Into An ASP.NET Website Using OAuth]
Comparing the Performance of Visual Studio's Web Reference to a Custom Class
Building a Store Locator ASP.NET Application Using Google Maps API (Part 1) [Part 2] [Part 3]
Preventing Users From Copying Text From and Pasting It Into TextBoxes
Search Engine Optimization Enhancements in ASP.NET 4
Maximize Your Website's Search Engine Placement Using Microsoft's Free SEO Toolkit
Defining Descriptive Text for Enumeration Members
Determine Your ASP.NET Page's View State Size
Create ZIP Files From An ASP.NET Application
Optimize Images Using the ASP.NET Sprite and Image Optimization Framework
Formatting Dates, Times and Numbers in ASP.NET
Use jQuery and ASP.NET to Build a News Ticker [Pausing and Resuming the Ticker]
Iron Speed Designer Review
Filling in PDF Forms with ASP.NET and iTextSharp [Creating PDF Documents with ASP.NET and iTextSharp]
 
Graphics and Charting
Creating Charts with the Google Chart API [A Google Chart API Custom Server Control]
Dynamically Generating and Caching Images in ASP.NET with the GeneratedImage Control [Image Transforms with the ASP.NET Generated Image Control]
Using Microsoft's Chart Controls In An ASP.NET Application: Getting Started [Plotting Chart Data] [Rendering the Chart] [Sorting and Filtering Chart Data] [Programmatically Generating Chart Images] [Creating Drill Down Reports] [Adding Statistical Formulas] [Enhancing Charts With Ajax] [Serializing Chart Data] [Using the Chart Controls with ASP.NET MVC] [Exporting Charts] 
 
Recommended ASP.NET 1.0 / 1.1 Articles...
These articles include information on ASP.NET version 1.x or on topics that are not version 2.0-specific...
[ASP.NET Basics] | [Working with Web Controls] | [Displaying Data] | [Advanced Data-Driven Tasks] | [Network Functions] | [Caching] | [Web Services] | [Software Design Principles and Best Practices] | [Application Architecture] | [XML] | [Examining ASP.NET Applications] | [Security] | [Graphics and Charting] | [Working with the File System] | [Utilizing Components] | [Advanced Techniques] | [Miscellaneous Topics]
ASP.NET Basics
Commonly Asked ASP.NET Questions... Answered!
ASP.NET Code Behind Pages
Mark Anders Answers your ASP.NET/.NET Questions!
Recommended Blogs for .NET and ASP.NET Developers
How ASP.NET Web Pages are Processed on the Web Server
Adding Client-Side Message Boxes in your ASP.NET Web Pages
Getting the Most Out of Visual Studio .NET | Improving Developer Productivity with Visual Studio .NET Macros
Passing Parameters from One Page to Another
 
Working with Web Controls
Form Validation with ASP.NET - It Doesn't Get Any Easier!
Using the CustomValidator Control
Displaying XML Data in the Internet Explorer TreeView Control | Using the TreeView IE Web Control
Populating Form Inputs Using the Calendar Control
Creating a RollOver Button Server Control
Easily Adding Functionality to ASP.NET Server Controls
A Custom ASP.NET Server Control for Displaying RSS Feeds | Displaying RSS Feeds - A Look at RssFeed Version 1.9 | Syndicating Your Web Site's Content with RSS and ASP.NET
Using Menus in an ASP.NET Web Application
Creating a Content Rater
Creating a Row-Selectable DataGrid Control
Introducing the RoundedCorners Web Control | Improving the RoundedCorners Web Control
Extending the Calendar Control's Date Navigation
Providing a Richer Means for Entering Text Data
Displaying Text in the Browser's Status Bar When Mousing Over a LinkButton | Stopping JavaScript Errors When Opening a LinkButton in a New Window
Creating a TextBoxLengthValidator Validator Control
An Easier Way to Highlight the Rows of a DataGrid on MouseOver
Display Local Weather Forecasts with the NOAA's Web Service [Updating the MultiDayForecast Web Control]
Enter and the Button Click Event [Two Common Pitfalls When Submitting a Web Form Using the Enter Key]
List Control Items and Attributes | ListControl Items, Attributes, and ViewState
 
Displaying Data
Using the ASP.NET DataGrid Control
Understanding the Differences Among the DataGrid, DataList, and Repeater
Efficiently Iterating Through Results from a Database Query using ADO.NET
An Extensive Examination of the DataGrid Web Control: Part 1 [Part 2] [Part 3] [Part 4] [Part 5] [Part 6] [Part 7] [Part 8] [Part 9] [Part 10] [Part 11] [Part 12] [Part 13] [Part 14] [Part 15] [Part 16] [Part 17] [Part 18]
Displaying Records in a DataGrid in Random Order
Creating Databound DropDown Lists in ASP.NET | Creating a Default Option in a Databound DropDown List
Creating a DataBound List of Radio Buttons in ASP.NET
XML, the DataSet, and a DataGrid | DataGrids, DataSets, and XML Strings
Using the .NET Framework Data Provider for Oracle
Binding a Scalar Array to a Data Web Control
Creating Collapsible Detail Regions in a Repeater | Creating a Tabbed Interface for Displaying Parent/Child Data
A Code Template for a Pageable, Bi-Directional Sortable DataGrid
Retrieving Scalar Data from a Stored Procedure
 
Advanced Data-Driven Tasks
Paging Database Results in ASP.NET | Paging in ASP.NET
Custom ASP.NET Datagrid Paging With Exact Count
Adding a
DropDownList
to an Editable DataGrid
Customizing DataBinded Output in Templates
Including Subheadings in a Datagrid
Summarizing Data with
ROLLUP
Computing Values from a DataTable
Adding a New Record to the DataGrid | Enhancing Inserting Data through the DataGrid Footer
Imposing Constraints on DataSet
DataTable
s
Transferring the Datagrid data Between Web Forms
Creating a Custom DataGridColumn Class
Displaying Custom Classes in a DataGrid
Hosting a Windows Control in a Web Form
Adding Paging Support to the Repeater or DataList with the
PagedDataSource
Class
Creating a Repeater that Supports Pagination and Sorting
Maintaining Database Consistency with Transactions
 
Network Functions
Screen Scraping with ASP.NET
Sending Email from an ASP.NET Web Page
Emailing the Rendered Output of an ASP.NET Web Control | Enhancing the 'Email the Rendered Output of an ASP.NET Web Control' Code | Emailing the Rendered Output of an ASP.NET Web Control in ASP.NET 2.0
Consuming an RSS Feed with ASP.NET | Creating an Online RSS News Aggregator with ASP.NET
Uploading in ASP.NET
Performing Browser Detection Using ASP.NET
A Deeper Look at Performing HTTP Requests in an ASP.NET Page | Making Authenticated HTTP Requests from an ASP.NET Page
 
Caching
.NET Data Caching
Caching in ASP.NET
Displaying Cached XML Data in a DataGrid, and Intelligently Refreshing the Data
 
Web Services
Creating and Consuming a Web Service
Creating a .NET Web Service
Building Client Interfaces for .NET Web Services
An Extensive Examination of Web Services: Part 1 [Part 2] [Part 3] [Part 4] [Part 5] [Part 6] [Part 7] [Part 8] [Part 9] [Part 10] [Part 11]
Searching Google Using the Google Web Service
Building an NBA Team Standings Web Service
 
Software Design Principles and Best Practices
FxCop, Your .NET Cop
NProf and ACT, Your Performance Assistants
A Brief Introduction to NAnt
Test Driven Development Using NUnit in C#
Advanced Techniques with NUnitAsp
Unit Testing the Data Access Layer
An Introduction and Overview of the Microsoft Application Blocks | Examining the Data Access Application Block | Examining the Exception Management Application Block (EMAB) | An Introduction to the Microsoft Enterprise Library | Working with the Enterprise Library's Data Access Application Block
Why I Don't Use DataSets in My ASP.NET Applications | More On Why I Don't Use DataSets in My ASP.NET Applications
Database Projects in Visual Studio .NET
Gracefully Responding to Unhandled Exceptions - Displaying User-Friendly Error Pages
 
Application Architecture
Using XML to Share Constants Across Projects | Improving Using XML to Share Constants Across Projects
Accessing Common Code, Constants, and Functions in an ASP.NET Project
An Introduction and Overview of the Microsoft Application Blocks | Examining the Data Access Application Block | Examining the Exception Management Application Block (EMAB) | An Introduction to the Microsoft Enterprise Library
Streamlining Your Data Access Layer with Helper Methods
Specifying Configuration Settings in
Web.config
[Creating Custom Configuration Sections in
Web.config
]
Globalizing ASP.NET Applications With Non-Standard Languages
Creating Template-Driven Web Sites with MasterPages
Using HTTP Modules and Handlers to Create Pluggable ASP.NET Components
Using a Custom Base Class for your ASP.NET Pages' Code-Behind Classes
 
XML
Creating XML Documents with the
XmlTextWriter
Class
Quickly Editing an XML File
Querying XML Data with XQuery
Using XML to Store States and Provinces
 
Examining ASP.NET Applications
An ASP.NET Rating System
Hangman in ASP.NET
A Robust Image Gallery for ASP.NET
Displaying a List of Scaled Images | True Image Resizing
Building an Event Calendar Web Application
Creating a Banner Ad System in ASP.NET
Creating a Content Rater | Improving the Content Rater
Web-Based Surveys Made Easy | Working with the WebSurvey Control's Results
Creating a Simple Image Slide Show
 
Security
Building Secure ASP.NET Applications: Authentication, Authorization, and Secure Communication
Using MD5 to Encrypt Passwords in a Database | Could you Pass the Salt? Improving the Security in Encrypting Passwords using MD5
Converting Mike Shaffer's VBScript RC4 Encryption Code to C#
Role-Based Authorization With Forms Authentication | Dissecting Forms Authentication
Protecting Files with ASP.NET
An Overview of Authentication and Authorization Options in ASP.NET
Encrypting Sensitive Data in a Database
Passing Tamper-Proof QueryString Parameters | Creating Expiring Web Pages
Generating Random Passwords with ASP.NET
An Overview of Cryptographic Systems and Encrypting Database Data [Using Symmetric Encryption in a SQL Server 2005 Database] [Using Asymmetric Encryption and Digital Signatures in a SQL Server 2005 Database]
 
Graphics and Charting
Drawing Serpinski's Triangle with ASP.NET
ASP.NET Charting Using Office Web Components (OWC)
Create Snazzy Web Charts and Graphics On the Fly with ASP.NET
An Introduction to Microsoft SQL Server 2000 Reporting Services
ASP.NET Charting with NPlot
 
Working with the File System
Reading Text Files in an ASP.NET Web Page
| Highlighting Search Keywords in a DataGrid Web Control
Displaying the Files in a Directory using a DataGrid
Reading and Writing Text Files with the .NET Framework
 
Utilizing Components
Using Components in ASP.NET
Accessing .NET components from COM components
Using Win32 DLL functions and COM components from .NET applications
COM Interoperability in the .NET Framework
Building ASP.NET User Controls | An Extensive Examination of User Controls
Trigger Page Methods from a User Control
 
Advanced Techniques
Displaying Information about the ASP.NET Process
Displaying Performance Monitor Information through an ASP.NET Web Page
HTTP Handlers and HTTP Modules in ASP.NET
Dynamic Controls in ASP.NET | Working with Dynamically Created Controls | Dynamic Web Controls, Postbacks, and View State
Sorting An Array Using
Array.Sort()
Regular Expressions in .NET
Efficiently Searching a Sorted Array
Tracing in ASP.NET
HttpContext.Items
- a Per-Request Cache Store
Using ASP.NET to Prompt a User to Save When Leaving a Page | An Update on Prompting a User to Save When Leaving an ASP.NET Page
Understanding Interfaces and Their Usefulness
A Look at WebCharts, a Free .NET Charting Control
Bubbling Events Up the Control Hierarchy
Specialized Collections
 
Miscellaneous Topics
Understanding Enumerations
A Look at ASP.NET's Adaptive Rendering | Client-Side Validation in Downlevel Browsers
Decompiling .NET Assemblies
Understanding Pagination in ASP.NET 1.x Mobile Applications
Maintaining Scroll Position on Postback
Searching Your Website with Microsoft Index Services
Little Known, Invaluable Methods and Properties in the .NET Framework Base Class Library : Working with File Paths | Working with Colors
Subtleties in Providing a Read-Only User Interface
 

Sunday, March 31, 2013

jQuery Modal popup : Misc Basics : dialog("open") and button click open


1. Opening a modal pop-up on button click

 a.    $(function() {
        $("#mybtn").click(function() {
            $("#mydlg").dialog();
        });
    });

OR
 b.        $(document).ready(function() {
            $("#mybtn").click(function() {
                $("#mydlg").dialog();
            });
        });

Both of these will work.

Full code :
<head runat="server">
    <title></title>
    <script src="jquery-1.9.1.js" type="text/javascript"></script>
    <link href="jquery-1.10.2-ui.css" rel="stylesheet" type="text/css" />
    <script src="jquery-1.10.2-ui.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#mybtn").click(function() {
                $("#mydlg").dialog();
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="mydlg">
   
    </div>
    <button type="button" id="mybtn"></button>
    </form>
</body>





=================================================
2. Using dialog("open")

To enable dialog("open"), you should disable the dialog's autoOpen behavior:

<script type="text/javascript">
    $(document).ready(function() {
        $("#mydlg").dialog({ autoOpen: false });
        $("#mybtn").click(function() {
            $("#mydlg").dialog("open");
        });
    });
</script>


Full Code :
<head runat="server">
    <title></title>
    <script src="jquery-1.9.1.js" type="text/javascript"></script>
    <link href="jquery-1.10.2-ui.css" rel="stylesheet" type="text/css" />
    <script src="jquery-1.10.2-ui.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("#mydlg").dialog({ autoOpen: false });
        $("#mybtn").click(function() {
            $("#mydlg").dialog("open");
        });
    });
</script>
 
</head>
<body>
    <form id="form1" runat="server">
    <div id="mydlg">
    </div>
    <input type="button" id="mybtn" />
    </form>
</body>
=============================================================


Comparing features of LangGraph vs CrewAI

LangGraph Orchestration vs CrewAI Orchestration The following table compares LangGraph and CrewAI orchestration across their menta...