Wednesday, 31 July 2013

SET ANSI_PADDING (Transact-SQL)

SET ANSI_PADDING (Transact-SQL)

SQL Server 2005
1 out of 2 rated this helpful - Rate this topic
Controls the way the column stores values shorter than the defined size of the column, and the way the column stores values that have trailing blanks in char, varchar, binary, and varbinary data.
ms187403.note(en-US,SQL.90).gifImportant:
In a future version of SQL Server ANSI_PADDING will always be ON and any applications that explicitly set the option to OFF will produce an error. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.
Topic link icon Transact-SQL Syntax Conventions
SET ANSI_PADDING { ON | OFF }
Columns defined with char, varchar, binary, and varbinary data types have a defined size.
This setting affects only the definition of new columns. After the column is created, SQL Server 2005 stores the values based on the setting when the column was created. Existing columns are not affected by a later change to this setting.
ms187403.note(en-US,SQL.90).gifNote:
We recommend that ANSI_PADDING always be set to ON.
The following table shows the effects of the SET ANSI_PADDING setting when values are inserted into columns with char, varchar, binary, and varbinary data types.
Setting char(n) NOT NULL or binary(n) NOT NULL char(n) NULL or binary(n) NULL varchar(n) or varbinary(n)
ON
Pad original value (with trailing blanks for char columns and with trailing zeros for binary columns) to the length of the column.
Follows same rules as for char(n) or binary(n) NOT NULL when SET ANSI_PADDING is ON.
Trailing blanks in character values inserted into varchar columns are not trimmed. Trailing zeros in binary values inserted into varbinary columns are not trimmed. Values are not padded to the length of the column.
OFF
Pad original value (with trailing blanks for char columns and with trailing zeros for binary columns) to the length of the column.
Follows same rules as for varchar or varbinary when SET ANSI_PADDING is OFF.
Trailing blanks in character values inserted into a varchar column are trimmed. Trailing zeros in binary values inserted into a varbinary column are trimmed.
ms187403.note(en-US,SQL.90).gifNote:
When padded, char columns are padded with blanks, and binary columns are padded with zeros. When trimmed, char columns have the trailing blanks trimmed, and binary columns have the trailing zeros trimmed.
SET ANSI_PADDING must be ON when you are creating or changing indexes on computed columns or indexed views. For more information about required SET option settings with indexed views and indexes on computed columns, see "Considerations When You Use the SET Statements" in SET (Transact-SQL).
The default for SET ANSI_PADDING is ON. The SQL Native Client ODBC driver and SQL Native Client OLE DB Provider for SQL Server automatically set ANSI_PADDING to ON when connecting. This can be configured in ODBC data sources, in ODBC connection attributes, or OLE DB connection properties set in the application before connecting. The default for SET ANSI_PADDING is OFF for connections from DB-Library applications.
The SET ANSI_PADDING setting does not affect the nchar, nvarchar, ntext, text, image, and large value. They always display the SET ANSI_PADDING ON behavior. This means trailing spaces and zeros are not trimmed.
When SET ANSI_DEFAULTS is ON, SET ANSI_PADDING is enabled.
The setting of SET ANSI_PADDING is set at execute or run time and not at parse time.
Requires membership in the public role.
The following example shows how the setting affects each of these data types.
PRINT 'Testing with ANSI_PADDING ON'
SET ANSI_PADDING ON;
GO

CREATE TABLE t1 (
   charcol CHAR(16) NULL, 
   varcharcol VARCHAR(16) NULL, 
   varbinarycol VARBINARY(8)
);
GO
INSERT INTO t1 VALUES ('No blanks', 'No blanks', 0x00ee);
INSERT INTO t1 VALUES ('Trailing blank ', 'Trailing blank ', 0x00ee00);

SELECT 'CHAR' = '>' + charcol + '<', 'VARCHAR'='>' + varcharcol + '<',
   varbinarycol
FROM t1;
GO

PRINT 'Testing with ANSI_PADDING OFF';
SET ANSI_PADDING OFF;
GO

CREATE TABLE t2 (
   charcol CHAR(16) NULL, 
   varcharcol VARCHAR(16) NULL, 
   varbinarycol VARBINARY(8)
);
GO
INSERT INTO t2 VALUES ('No blanks', 'No blanks', 0x00ee);
INSERT INTO t2 VALUES ('Trailing blank ', 'Trailing blank ', 0x00ee00);

SELECT 'CHAR' = '>' + charcol + '<', 'VARCHAR'='>' + varcharcol + '<',
   varbinarycol
FROM t2;
GO

DROP TABLE t1
DROP TABLE t2

Monday, 29 July 2013

Charts for Asp.Net Application



Introduction:

In this article we will learn how to create a chart for our ASP.NET application.

Background:

Here we will see how to draw a chart for our data in ASP.Net. We are using a third party control to draw our chart. This is a .dll file I found somewhere using Google search. It's not my .dll. This .dll file provides various types of charts such as LineChart, PieChart, CircleChart etc...

To prepare for a chart using this .dll file follow the steps given below.

Step 1:

Start a new web-site; give the name as ChartInAsp.Net. It will give you one Default.aspx and .cs file.

Step 2:

Download source code and copy the Webchart.dll file from the bin directory to some location. Now add a reference to this WebChart.dll file.

Step 3:

Now Register this dll in your Page directory such as shown bellow. And get the Chart control from this dll.
<%@ Register TagPrefix="Web" Namespace="WebChart" Assembly="WebChart" %><Web:ChartControl ID="ChartControl1" runat="Server" Height="366px"                         Width="500px" />

Step 4:

Now move to Design view and see that the Chart control is created as shown below. Whenever we are creating this control the default chart is LineChart; you can change it to another type by setting it's type property in property window or in the .cs file. We will see how to change it again in the .cs file.

charts.gif

Step 5:

Now move to .cs file and Import the WebChart as shown below.

using WebChart;

Step 6:

Now get your Data from database or prepare only Dataset or DataTable.
// Preparing Data Source For Chart Control        DataTable dt = new DataTable("Chart");
        DataColumn dc = new DataColumn("Year", typeof(int));
        DataColumn dc1 = new DataColumn("Aveg", typeof(double));
        dt.Columns.Add(dc);
        dt.Columns.Add(dc1);
        DataRow dr = dt.NewRow();
        dr[0] = 1995;
        dr[1] = 10.5;
        dt.Rows.Add(dr);
        DataRow dr1 = dt.NewRow();
        dr1[0] = 2000;
        dr1[1] = 11.5;
        dt.Rows.Add(dr1);

Step 7:

Now bind this data to the chart control. Here you can choose either LineChart, CircleChart or PieChart etc… Here we will bind the data to our LineChart and color this chart as follows.
//Chart type you can change chart type here ex. pie chart,circle chart

        LineChart chart = new LineChart();//Class instance for LineChart        chart.Fill.Color = Color.FromArgb(50, Color.SteelBlue);
        chart.Line.Color = Color.SteelBlue;
        chart.Line.Width = 2;
        chart.Legend = "X Axis: Year.\nY Axis: Average";
        //looping through datatable and adding to chart control        foreach (DataRow dr2 in dt.Rows)
        {
            chart.Data.Add(new ChartPoint(dr2["Year"].ToString(), (float)System.Convert.ToSingle(dr2["Aveg"])));
        }
        ConfigureColors();
        ChartControl1.Charts.Add(chart);        ChartControl1.RedrawChart();
Step 8:

The ConfigureColors Method to color our chart.
private void ConfigureColors()
{
    ChartControl1.Background.Color = Color.FromArgb(75, Color.SteelBlue);
    ChartControl1.Background.Type = InteriorType.LinearGradient;
    ChartControl1.Background.ForeColor = Color.SteelBlue;
    ChartControl1.Background.EndPoint = new Point(500, 350);
    ChartControl1.Legend.Position = LegendPosition.Bottom;
    ChartControl1.Legend.Width = 40;
    ChartControl1.YAxisFont.ForeColor = Color.SteelBlue;
    ChartControl1.XAxisFont.ForeColor = Color.SteelBlue;
    ChartControl1.ChartTitle.Text = "GRAPH EXAMPLE IN ASP.NET";
    ChartControl1.ChartTitle.ForeColor = Color.White;
    ChartControl1.Border.Color = Color.SteelBlue;
    ChartControl1.BorderStyle = BorderStyle.Ridge;}

Step 9:

Now run your application; it will show a nice chart Control to you. This dll will create a WebCharts folder in your application Directory for storing chart Images.

Conclusion:

In this way you can prepare various types of charts for you ASP.Net application.


The Dll you can download it from the following link.
http://www.c-sharpcorner.com/uploadfile/krishnasarala/charts-for-asp-net-application/

http://demos.devexpress.com/asp/Default.aspx 

JavaScript Animation

<!DOCTYPE html>
<html>
<head>
<script>
function mouseOver()
{
document.getElementById("b1").src ="b_blue.gif";
}
function mouseOut()
{
document.getElementById("b1").src ="b_pink.gif";
}
</script>
</head>

<body>
<a href="http://www.w3schools.com" target="_blank">
<img border="0" alt="Visit W3Schools!" src="b_pink.gif" id="b1" width="26" height="26" onmouseover="mouseOver()" onmouseout="mouseOut()" /></a>
</body>
</html>

Response.End() - Thread was being aborted

ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer

PRB: ThreadAbortException Occurs If You Use Response.End, Response.Redirect, or Server.Transfer

Article ID: 312629 - View products that this article applies to.
This article was previously published under Q312629

Symptoms

If you use the Response.End, Response.Redirect, or Server.Transfer method, a ThreadAbortException exception occurs. You can use a try-catch statement to catch this exception.

Cause

The Response.End method ends the page execution and shifts the execution to the Application_EndRequest event in the application's event pipeline. The line of code that follows Response.End is not executed.

This problem occurs in the Response.Redirect and Server.Transfer methods because both methods call Response.End internally.

Resolution

To work around this problem, use one of the following methods:
  • For Response.End, call the HttpContext.Current.ApplicationInstance.CompleteRequest method instead of Response.End to bypass the code execution to the Application_EndRequest event.
  • For Response.Redirect, use an overload, Response.Redirect(String url, bool endResponse) that passes false for the endResponse parameter to suppress the internal call to Response.End. For example:

      Response.Redirect ("nextpage.aspx", false);
          
    If you use this workaround, the code that follows Response.Redirect is executed.
  • For Server.Transfer, use the Server.Execute method instead. 
http://support.microsoft.com/kb/312629

Thursday, 25 July 2013

Schedule a Job in Sql Server 2008

Schedule a Job

SQL Server 2012
This topic describes how to schedule a SQL Server Agent job.

Security

For detailed information, see Implement SQL Server Agent Security.
Arrow icon used with Back to Top link [Top]

To create and attach a schedule to a job

  1. In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance.
  2. Expand SQL Server Agent, expand Jobs, right-click the job you want to schedule, and click Properties.
  3. Select the Schedules page, and then click New.
  4. In the Name box, type a name for the new schedule.
  5. Clear the Enabled check box if you do not want the schedule to take effect immediately following its creation.
  6. For Schedule Type, select one of the following:
    • Click Start automatically when SQL Server Agent starts to start the job when the SQL Server Agent service is started.
    • Click Start whenever the CPUs become idle to start the job when the CPUs reach an idle condition.
    • Click Recurring if you want a schedule to run repeatedly. To set the recurring schedule, complete the Frequency, Daily Frequency, and Duration groups on the dialog.
    • Click One time if you want the schedule to run only once. To set the One time schedule, complete the One-time occurrence group on the dialog.
Arrow icon used with Back to Top link [Top]

To attach a schedule to a job

  1. In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance.
  2. Expand SQL Server Agent, expand Jobs, right-click the job that you want to schedule, and click Properties.
  3. Select the Schedules page, and then click Pick.
  4. Select the schedule that you want to attach, and then click OK.
  5. In the Job Properties dialog box, double-click the attached schedule.
  6. Verify that Start date is set correctly. If it is not, set the date when you want for the schedule to start, and then click OK.
  7. In the Job Properties dialog box, click OK.
Arrow icon used with Back to Top link [Top]

To schedule a job

  1. In Object Explorer, connect to an instance of Database Engine.
  2. On the Standard bar, click New Query.
  3. Copy and paste the following example into the query window and click Execute.
    USE msdb ;
    GO
    -- creates a schedule named NightlyJobs. 
    -- Jobs that use this schedule execute every day when the time on the server is 01:00. 
    EXEC sp_add_schedule
        @schedule_name = N'NightlyJobs' ,
        @freq_type = 4,
        @freq_interval = 1,
        @active_start_time = 010000 ;
    GO
    -- attaches the schedule to the job BackupDatabase
    EXEC sp_attach_schedule
       @job_name = N'BackupDatabase',
       @schedule_name = N'NightlyJobs' ;
    GO
    
For more information, see sp_add_schedule (Transact-SQL) and sp_attach_schedule (Transact-SQL).
SQL SERVER – Difference Between Union vs. Union All – Optimal Performance Comparison

More than a year ago I had written article SQL SERVER – Union vs. Union All – Which is better for performance? I have got many request to update this article. It is not fair to update already written article so I am rewriting it again with additional information.

UNION
The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type. With UNION, only distinct values are selected.

UNION ALL
The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values.

The difference between Union and Union all is that Union all will not eliminate duplicate rows, instead it just pulls all rows from all tables fitting your query specifics and combines them into a table.

A UNION statement effectively does a SELECT DISTINCT on the results set. If you know that all the records returned are unique from your union, use UNION ALL instead, it gives faster results.

Run following script in SQL Server Management Studio to see the result between UNION ALL and UNION. Download complete script from here.

/* Declare First Table */
DECLARE @Table1 TABLE (ColDetail VARCHAR(10))
INSERT INTO @Table1
SELECT 'First'
UNION ALL
SELECT 'Second'
UNION ALL
SELECT 'Third'
UNION ALL
SELECT 'Fourth'
UNION ALL
SELECT 'Fifth'
/* Declare Second Table */
DECLARE @Table2 TABLE (ColDetail VARCHAR(10))
INSERT INTO @Table2
SELECT 'First'
UNION ALL
SELECT 'Third'
UNION ALL
SELECT 'Fifth'
/* Check the data using SELECT */
SELECT *
FROM @Table1
SELECT *
FROM @Table2
/* UNION ALL */
SELECT *
FROM @Table1
UNION ALL
SELECT *
FROM @Table2
/* UNION */
SELECT *
FROM @Table1
UNION
SELECT
*
FROM @Table2
GO

In our example we have two tables: @Table1 and @Table2.


Now let us run UNION ALL and UNION together and see the resultset as well as Execution Plan compared to complete set of query. You can always turn on actual execution plan using CTRL+M.

We can see from the resultset of UNION ALL that it returns everything from both the table but from UNION it is very clear that only DISTINCT rows from both the table is only retrieved.


Additionally, when comparing the execution plan of UNION ALL and UNION it is also quite clear that UNION ALL is way less expensive than UNION as it does not have DISTINCT SORT operation.






WSDL (Web Services Description Language)

Introduction to WSDL
WSDL is an XML-based language for describing Web services and how to access them.

What You Should Already Know
Before you continue you should have a basic understanding of the following:
  • XML
  • XML Namespaces
  • XML Schema

What is WSDL?
  • WSDL stands for Web Services Description Language
  • WSDL is written in XML
  • WSDL is an XML document
  • WSDL is used to describe Web services
  • WSDL is also used to locate Web services
  • WSDL is a W3C recommendation

WSDL Describes Web Services
WSDL stands for Web Services Description Language.
WSDL is a document written in XML. The document describes a Web service. It specifies the location of the service and the operations (or methods) the service exposes.

WSDL is a W3C Recommendation
WSDL became a W3C Recommendation 26. June 2007.



A WSDL document is just a simple XML document.
It contains set of definitions to describe a web service.

The WSDL Document Structure
A WSDL document describes a web service using these major elements:
ElementDescription
<types>
A container for data type definitions used by the web service
<message>
A typed definition of the data being communicated
<portType>
A set of operations supported by one or more endpoints
<binding>
A protocol and data format specification for a particular port type
The main structure of a WSDL document looks like this:
<definitions>

<types>

  data type definitions........
</types>

<message>

  definition of the data being communicated....
</message>

<portType>

  set of operations......
</portType>

<binding>

  protocol and data format specification....
</binding>

</definitions>
A WSDL document can also contain other elements, like extension elements, and a service element that makes it possible to group together the definitions of several web services in one single WSDL document.

WSDL Ports
The <portType> element is the most important WSDL element.
It describes a web service, the operations that can be performed, and the messages that are involved.
The <portType> element can be compared to a function library (or a module, or a class) in a traditional programming language.

WSDL Messages
The <message> element defines the data elements of an operation.
Each message can consist of one or more parts. The parts can be compared to the parameters of a function call in a traditional programming language.

WSDL Types
The <types> element defines the data types that are used by the web service.
For maximum platform neutrality, WSDL uses XML Schema syntax to define data types.

WSDL Bindings
The <binding> element defines the data format and protocol for each port type.

WSDL Example
This is a simplified fraction of a WSDL document:
<message name="getTermRequest">
  <part name="term" type="xs:string"/>
</message>

<message name="getTermResponse">

  <part name="value" type="xs:string"/>
</message>

<portType name="glossaryTerms">

  <operation name="getTerm">
    <input message="getTermRequest"/>
    <output message="getTermResponse"/>
  </operation>
</portType>
In this example the <portType> element defines "glossaryTerms" as the name of a port, and "getTerm" as the name of an operation.
The "getTerm" operation has an input message called "getTermRequest" and an output message called "getTermResponse".
The <message> elements define the parts of each message and the associated data types.
Compared to traditional programming, glossaryTerms is a function library, "getTerm" is a function with "getTermRequest" as the input parameter, and getTermResponse as the return parameter.



The <portType> element is the most important WSDL element.

WSDL - The <portType> Element
The <portType> element defines a web service, the operations that can be performed, and the messages that are involved.
<portType> defines the connection point to a web service. It can be compared to a function library (or a module, or a class) in a traditional programming language. Each operation can be compared to a function in a traditional programming language.

Operation Types
The request-response type is the most common operation type, but WSDL defines four types:
TypeDefinition
One-way
The operation can receive a message but will not return a response
Request-response
The operation can receive a request and will return a response
Solicit-response
The operation can send a request and will wait for a response
Notification
The operation can send a message but will not wait for a response

One-Way Operation
A one-way operation example:
<message name="newTermValues">
  <part name="term" type="xs:string"/>
  <part name="value" type="xs:string"/>
</message>

<portType name="glossaryTerms">

  <operation name="setTerm">
    <input name="newTerm" message="newTermValues"/>
  </operation>
</portType >
In the example above, the portType "glossaryTerms" defines a one-way operation called "setTerm".
The "setTerm" operation allows input of new glossary terms messages using a "newTermValues" message with the input parameters "term" and "value". However, no output is defined for the operation.

Request-Response Operation
A request-response operation example:
<message name="getTermRequest">
  <part name="term" type="xs:string"/>
</message>

<message name="getTermResponse">

  <part name="value" type="xs:string"/>
</message>

<portType name="glossaryTerms">

  <operation name="getTerm">
    <input message="getTermRequest"/>
    <output message="getTermResponse"/>
  </operation>
</portType>
In the example above, the portType "glossaryTerms" defines a request-response operation called "getTerm".
The "getTerm" operation requires an input message called "getTermRequest" with a parameter called "term", and will return an output message called "getTermResponse" with a parameter called "value".



WSDL bindings defines the message format and protocol details for a web service.

Binding to SOAP
A request-response operation example:
<message name="getTermRequest">
  <part name="term" type="xs:string"/>
</message>

<message name="getTermResponse">

  <part name="value" type="xs:string"/>
</message>

<portType name="glossaryTerms">

  <operation name="getTerm">
    <input message="getTermRequest"/>
    <output message="getTermResponse"/>
  </operation>
</portType>

<binding type="glossaryTerms" name="b1">

   <soap:binding style="document"
   transport="http://schemas.xmlsoap.org/soap/http" />
   <operation>
     <soap:operation soapAction="http://example.com/getTerm"/>
     <input><soap:body use="literal"/></input>
     <output><soap:body use="literal"/></output>
  </operation>
</binding>
The binding element has two attributes - name and type.
The name attribute (you can use any name you want) defines the name of the binding, and the type attribute points to the port for the binding, in this case the "glossaryTerms" port.
The soap:binding element has two attributes - style and transport.
The style attribute can be "rpc" or "document". In this case we use document. The transport attribute defines the SOAP protocol to use. In this case we use HTTP.
The operation element defines each operation that the portType exposes.
For each operation the corresponding SOAP action has to be defined. You must also specify how the input and output are encoded. In this case we use "literal".



Universal Description, Discovery and Integration (UDDI) is a directory service where businesses can register and search for Web services.

What is UDDI
UDDI is a platform-independent framework for describing services, discovering businesses, and integrating business services by using the Internet.
  • UDDI stands for Universal Description, Discovery and Integration
  • UDDI is a directory for storing information about web services
  • UDDI is a directory of web service interfaces described by WSDL
  • UDDI communicates via SOAP
  • UDDI is built into the Microsoft .NET platform

What is UDDI Based On?
UDDI uses World Wide Web Consortium (W3C) and Internet Engineering Task Force (IETF) Internet standards such as XML, HTTP, and DNS protocols.
UDDI uses WSDL to describe interfaces to web services
Additionally, cross platform programming features are addressed by adopting SOAP, known as XML Protocol messaging specifications found at the W3C Web site.

UDDI Benefits
Any industry or businesses of all sizes can benefit from UDDI.
Before UDDI, there was no Internet standard for businesses to reach their customers and partners with information about their products and services. Nor was there a method of how to integrate into each other's systems and processes.
Problems the UDDI specification can help to solve:
  • Making it possible to discover the right business from the millions currently online
  • Defining how to enable commerce once the preferred business is discovered
  • Reaching new customers and increasing access to current customers
  • Expanding offerings and extending market reach
  • Solving customer-driven need to remove barriers to allow for rapid participation in the global Internet economy
  • Describing services and business processes programmatically in a single, open, and secure environment

How can UDDI be Used
If the industry published an UDDI standard for flight rate checking and reservation, airlines could register their services into an UDDI directory. Travel agencies could then search the UDDI directory to find the airline's reservation interface. When the interface is found, the travel agency can communicate with the service immediately because it uses a well-defined reservation interface.

Who is Supporting UDDI?
UDDI is a cross-industry effort driven by all major platform and software providers like Dell, Fujitsu, HP, Hitachi, IBM, Intel, Microsoft, Oracle, SAP, and Sun, as well as a large community of marketplace operators, and e-business leaders.
Over 220 companies are members of the UDDI community.





SOAP Example

SOAP Building Blocks

A SOAP message is an ordinary XML document containing the following elements:
  • An Envelope element that identifies the XML document as a SOAP message
  • A Header element that contains header information
  • A Body element that contains call and response information
  • A Fault element containing errors and status information
All the elements above are declared in the default namespace for the SOAP envelope:
http://www.w3.org/2001/12/soap-envelope
and the default namespace for SOAP encoding and data types is:
http://www.w3.org/2001/12/soap-encoding

Syntax Rules

Here are some important syntax rules:
  • A SOAP message MUST be encoded using XML
  • A SOAP message MUST use the SOAP Envelope namespace
  • A SOAP message MUST use the SOAP Encoding namespace
  • A SOAP message must NOT contain a DTD reference
  • A SOAP message must NOT contain XML Processing Instructions

Skeleton SOAP Message

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Header>
...
</soap:Header>

<soap:Body>
...
  <soap:Fault>
  ...
  </soap:Fault>
</soap:Body>

</soap:Envelope> 


The SOAP Envelope element is the root element of a SOAP message.

The SOAP Envelope Element

The required SOAP Envelope element is the root element of a SOAP message. This element defines the XML document as a SOAP message.

Example

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
  ...
  Message information goes here
  ...
</soap:Envelope>



The xmlns:soap Namespace

Notice the xmlns:soap namespace in the example above. It should always have the value of: "http://www.w3.org/2001/12/soap-envelope".
The namespace defines the Envelope as a SOAP Envelope.
If a different namespace is used, the application generates an error and discards the message.

The encodingStyle Attribute

The encodingStyle attribute is used to define the data types used in the document. This attribute may appear on any SOAP element, and applies to the element's contents and all child elements.
A SOAP message has no default encoding.

Syntax

soap:encodingStyle="URI"

Example

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
  ...
  Message information goes here
  ...
</soap:Envelope>




The SOAP Body element contains the actual SOAP message.

The SOAP Body Element

The required SOAP Body element contains the actual SOAP message intended for the ultimate endpoint of the message.
Immediate child elements of the SOAP Body element may be namespace-qualified.

Example

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body>
  <m:GetPrice xmlns:m="http://www.w3schools.com/prices">
    <m:Item>Apples</m:Item>
  </m:GetPrice>
</soap:Body>

</soap:Envelope>
The example above requests the price of apples. Note that the m:GetPrice and the Item elements above are application-specific elements. They are not a part of the SOAP namespace.
A SOAP response could look something like this:
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body>
  <m:GetPriceResponse xmlns:m="http://www.w3schools.com/prices">
    <m:Price>1.90</m:Price>
  </m:GetPriceResponse>
</soap:Body>

</soap:Envelope>




The SOAP Fault element holds errors and status information for a SOAP message.

The SOAP Fault Element

The optional SOAP Fault element is used to indicate error messages.
If a Fault element is present, it must appear as a child element of the Body element. A Fault element can only appear once in a SOAP message.
The SOAP Fault element has the following sub elements:
Sub Element Description
<faultcode> A code for identifying the fault
<faultstring> A human readable explanation of the fault
<faultactor> Information about who caused the fault to happen
<detail>
Holds application specific error information related to the Body element

SOAP Fault Codes

The faultcode values defined below must be used in the faultcode element when describing faults:
Error Description
VersionMismatch Found an invalid namespace for the SOAP Envelope element
MustUnderstand An immediate child element of the Header element, with the mustUnderstand attribute set to "1", was not understood
Client The message was incorrectly formed or contained incorrect information
Server There was a problem with the server so the message could not proceed




The HTTP Protocol

HTTP communicates over TCP/IP. An HTTP client connects to an HTTP server using TCP. After establishing a connection, the client can send an HTTP request message to the server:
POST /item HTTP/1.1
Host: 189.123.255.239
Content-Type: text/plain
Content-Length: 200
The server then processes the request and sends an HTTP response back to the client. The response contains a status code that indicates the status of the request:
200 OK
Content-Type: text/plain
Content-Length: 200
In the example above, the server returned a status code of 200. This is the standard success code for HTTP.
If the server could not decode the request, it could have returned something like this:
400 Bad Request
Content-Length: 0



SOAP HTTP Binding

A SOAP method is an HTTP request/response that complies with the SOAP encoding rules.

HTTP + XML = SOAP

A SOAP request could be an HTTP POST or an HTTP GET request.
The HTTP POST request specifies at least two HTTP headers: Content-Type and Content-Length.

Content-Type

The Content-Type header for a SOAP request and response defines the MIME type for the message and the character encoding (optional) used for the XML body of the request or response.

Syntax

Content-Type: MIMEType; charset=character-encoding

Example

POST /item HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8



Content-Length

The Content-Length header for a SOAP request and response specifies the number of bytes in the body of the request or response.

Syntax

Content-Length: bytes

Example

POST /item HTTP/1.1
Content-Type: application/soap+xml; charset=utf-8
Content-Length: 250




A SOAP Example

In the example below, a GetStockPrice request is sent to a server. The request has a StockName parameter, and a Price parameter that will be returned in the response. The namespace for the function is defined in "http://www.example.org/stock".

A SOAP request:

POST /InStock HTTP/1.1
Host: www.example.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">
  <m:GetStockPrice>
    <m:StockName>IBM</m:StockName>
  </m:GetStockPrice>
</soap:Body>

</soap:Envelope>

The SOAP response:

HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: nnn

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body xmlns:m="http://www.example.org/stock">
  <m:GetStockPriceResponse>
    <m:Price>34.5</m:Price>
  </m:GetStockPriceResponse>
</soap:Body>

</soap:Envelope>




Introduction


Simple Object Oriented Protocol or SOAP is a simple, light weight, XML based protocol that can be used for exchange of data in a de-centralized, distributed environment.  It is making headlines these days within the enterprise development community and promises to revolutionize Web applications development by facilitating interoperability between heterogeneous applications.  Using the SOAP protocol, objects of any kind, developed on any platform, using any language can cross communicate with each other.  Hence, we can connect the services offered by different heterogeneous systems together as components and use these components to build a complex information system with ease.  This article provides a detailed overview of SOAP in a lucid language.
What is SOAP, Anyway?


Simple Object Oriented Protocol or SOAP is a stateless, platform independent, XML based generic lightweight protocol that used HTTP as its transport and can be used for developing distributed complex computing environments.  SOAP is about applications communicating directly with each other over the Internet in a very rich way.  It is a stateless, message exchange paradigm that allows for exchange of data between heterogeneous web applications.  SOAP is supported on any platform and be utilized on a wide variety of applications.  SOAP is similar to its contemporary technologies, like DCOM or CORBA, in the sense that both provide a RPC mechanism for invoking remote methods.  However, SOAP differs from these technologies in the XML Open Standard that it provides for the purpose of data exchange between homogenous or heterogeneous distributed applications.  SOAP is supported by both HTTP and SMTP, but HTTP gained more acceptances over the years.
SOAP is platform independent, language independent and messaging between applications makes this protocol a robust and standardized mechanism in order to handle message communication across homogenous or heterogeneous networks.  The most common messaging pattern used in SOAP is Remote Procedure Call or RPC.  This indicates that the client sends a request message to the server.  The server in turn sends the response message to the client.  The prerequisite for having a proper understanding of SOAP is XML.  This is because XML is the basis of all SOAP related activities.  All SOAP messages are transmitted in XML format.  XML, a platform independent Meta (Language composed of non-binary ASCII text), has revolutionized the way data is transferred between systems.  XML is fast becoming as ubiquitous as HTTP.  It has now already become an accepted standard for representation and interchange of data in structured form accross systems.  All SOAP messages are transmitted as XML.
Why is SOAP required?



Distributed Applications that can support heterogeneous platforms for the purpose of data and information requires a common data format for transmission of data.  We have had protocols earlier like DCOM, RPC, IIOP, etc, but these were restricted to a homogenous environment only. They have been around for quite some time now, but they have their own limitations.  Any two systems communicating with each other using any of these protocols should have support for the protocol that they are using.  As an example, if a system "A" communicates with a system "B" using IIOP, both these systems should have support for IIOP to ensure that the communication takes place successfully.  For a heterogeneous environment this is not feasible.  The situation is more complex.  Simple Object Oriented Protocol (SOAP) is an Open Standard protocol and the solution to this complexity.
Advantages of SOAP



The following are some of the many advantages that SOAP provides.
·         Simplicity -- The SOAP messages are in simple, human readable XML format.
·         Scalability -- This is because it uses HTTP protocol for transport.
·         Language neutrality -- Can be developed using any language.
·         Interoperability and Platform Independence-- SOAP can be implemented in any language and can be executed in any platform.
Disadvantages of SOAP



The following are the disadvantages of SOAP.
·         Slower than CORBA or RMI or IIOP due to the lengthy XML format that it has to follow and the parsing of the envelop that is required.
·         It depends on WSDL and does not have any standardized mechanism for dynamic discovery of the services.
Composition of SOAP



As per the SOAP specification, SOAP is typically composed of the following three parts:
·         A framework that describes how the message can be constructed and how it can be processed
·         A set of encoding rules for exchanging the data types
·         A convention and a procedure for representing the Remote Procedure Calls
Anatomy of a SOAP Message



A client sends a SOAP message to the server.  This requesting data is also called a SOAP Request. The server receives the request, processes the same and sends a response back to the client. This returning data is known as the SOAP Response.  This communication back and forth between the client and the server takes place through HTTP protocol.
The following constitute a SOAP message declaration:
·         An envelope element that recognizes then XML file format which will be sent across as a SOAP message
·         An optional element that can describes header information
·         The description of the body which contains the information of the request and the response elements
·         Provision for another optional element that provides information as and when an error occurs
The SOAP format is clearly illustrated in listing 1 that follows.
Listing 1: A SOAP message format
<SOAP: Envelope>
  <SOAP: Header>
  </SOAP: Header>
  <SOAP: Body>
  </SOAP: Body>
</SOAP: Envelope>
SOAP support in Microsoft .NET


This section discusses the support for SOAP that is provided by the Microsoft .NET Framework. Microsoft .NET provides an excellent inbuilt support for SOAP.  This section discusses the SOAP support that is available in Microsoft .NET for both Web Services and Remoting technologies.
SOAP and Web Services



Simple Object Access Protocol (SOAP), Web Services Description Language (WSDL), and Universal Description, Discovery and Integration (UDDI) are emerging as the de facto standards for Web services.  A Web Service can be consumed by any client irrespective of the platform that the client is using.  This is because Web Services are based on the HTTP protocol.  The .NET Framework encapsulates the support for SOAP internally.
SOAP and Microsoft .NET Remoting



Unlike Web Services, Remoting is a technology that can be used in homogenous environments only.  Remoting technology uses channels and formatters.  The channels provide the transport protocol and the formatters are responsible for serialization and de-serialization.  We can create SOAP channels rather than using the HTTP channels in .NET.  In such a case, we have to make use of the System.Runtime.Serialization.Formatters.Soap namespace in .NET.
References




Conclusion



It should be noted that SOAP does not address object activation, marshaling objects/references, garbage collection, etc.  Further, as SOAP is a wire protocol, it does not provide an activation mechanism.  However, we can still use these in our applications as a layer on top of SOAP if required.  This article has provided a detailed discussion on SOAP, why SOAP is required, the advantages and disadvantages of SOAP and the support for SOAP in Web Services and Microsoft .NET Remoting technologies.






C# LINQ Joins With SQL

There are  Different Types of SQL Joins  which are used to query data from more than one database tables. In this article, you will learn a...