Hello All,
Greetings of the day.
Ambrish Jha
9811545125
Greetings of the day.
Ambrish Jha
9811545125
FAQ from webservices.XML.com by Ethan Cerami Web services represent an important evolutionary step in building distributed applications. But, what exactly is a Web service? What is the Web service protocol stack? And, does the World Wide Web Consortium support any Web service standards?Below are answers to the top ten most frequently asked questions (FAQs) about Web services. Together, they provide an overview of the Web services landscape as well as links to additional resources for more in-depth material. 1. What is a Web service?Many people and companies have debated the exact definition of Web services. At a minimum, however, a Web service is any piece of software that makes itself available over the Internet and uses a standardized XML messaging system.XML is used to encode all communications to a Web service. For example, a client invokes a Web service by sending an XML message, then waits for a corresponding XML response. Because all communication is in XML, Web services are not tied to any one operating system or programming language--Java can talk with Perl; Windows applications can talk with Unix applications. Beyond this basic definition, a Web service may also have two additional (and desirable) properties:
2. What is new about Web services?People have been using Remote Procedure Calls (RPC) for some time now, and they long ago discovered how to send such calls over HTTP.So, what is really new about Web services? The answer is XML. XML lies at the core of Web services, and provides a common language for describing Remote Procedure Calls, Web services, and Web service directories. Prior to XML, one could share data among different applications, but XML makes this so much easier to do. In the same vein, one can share services and code without Web services, but XML makes it easier to do these as well. By standardizing on XML, different applications can more easily talk to one another, and this makes software a whole lot more interesting. 3. I keep reading about Web services, but I have never actually seen one. Can you show me a real Web service in action?If you want a more intuitive feel for Web services, try out the IBM Web Services Browser, available on the IBM Alphaworks site. The browser provides a series of Web services demonstrations. Behind the scenes, it ties together SOAP, WSDL, and UDDI to provide a simple plug-and-play interface for finding and invoking Web services. For example, you can find a stock-quote service, a traffic-report service, and a weather service. Each service is independent, and you can stack services like building blocks. You can, therefore, create a single page that displays multiple services--where the end result looks like a stripped-down version of my.yahoo or my.excite.4. What is the Web service protocol stack?The Web service protocol stack is an evolving set of protocols used to define, discover, and implement Web services. The core protocol stack consists of four layers:
Fortunately, you do not need to understand the full protocol stack to get started with Web services. Assuming you already know the basics of HTTP, it is best to start at the XML Messaging layer and work your way up. 5. What is XML-RPC?XML-RPC is a protocol that uses XML messages to perform Remote Procedure Calls. Requests are encoded in XML and sent via HTTP POST; XML responses are embedded in the body of the HTTP response.More succinctly, XML-RPC = HTTP + XML + Remote Procedure Calls. Because XML-RPC is platform independent, diverse applications can communicate with one another. For example, a Java client can speak XML-RPC to a Perl server. To get a quick sense of XML-RPC, here is a sample XML-RPC request to a weather service (with the HTTP Headers omitted): The request consists of a simple element, which specifies the method name (getWeather) and any method parameters (zip code).Here is a sample XML-RPC response from the weather service: The response consists of a single element, which specifies the return value (the current temperature). In this case, the return value is specified as an integer.In many ways, XML-RPC is much simpler than SOAP, and therefore represents the easiest way to get started with Web services. The official XML-RPC specification is available at XML-RPC.com. Dozens of XML-RPC implementations are available in Perl, Python, Java, and Ruby. See the XML-RPC home page for a complete list of implementations. 6. What is SOAP?SOAP is an XML-based protocol for exchanging information between computers. Although SOAP can be used in a variety of messaging systems and can be delivered via a variety of transport protocols, the main focus of SOAP is Remote Procedure Calls (RPC) transported via HTTP. Like XML-RPC, SOAP is platform independent, and therefore enables diverse applications to communicate with one another.To get a quick sense of SOAP, here is a sample SOAP request to a weather service (with the HTTP Headers omitted): As you can see, the request is slightly more complicated than XML-RPC and makes use of both XML namespaces and XML Schemas. Much like XML-RPC, however, the body of the request specifies both a method name (getWeather), and a list of parameters (zipcode).Here is a sample SOAP response from the weather service: The response indicates a single integer return value (the current temperature).The World Wide Web Consortium (W3C) is in the process of creating a SOAP standard. The latest working draft is designated as SOAP 1.2, and the specification is now broken into two parts. Part 1 describes the SOAP messaging framework and envelope specification. Part 2 describes the SOAP encoding rules, the SOAP-RPC convention, and HTTP binding details. 7. What is WSDL?The Web Services Description Language (WSDL) currently represents the service description layer within the Web service protocol stack.In a nutshell, WSDL is an XML grammar for specifying a public interface for a Web service. This public interface can include the following:
Below is a sample WSDL file. This file describes the public interface for the weather service used in the SOAP example above. Obviously, there are many details to understanding the example. For now, just consider two points.
elements specify the individual XML messages that are transferred between computers. In this case, we have agetWeatherRequest and a getWeatherResponse. Second, the element specifies that the service is available via SOAP and is available at a specific URL.Using WSDL, a client can locate a Web service, and invoke any of the publicly available functions. With WSDL-aware tools, this process can be entirely automated, enabling applications to easily integrate new services with little or no manual code. For example, check out the GLUE platform from the Mind Electric.WSDL has been submitted to the W3C, but it currently has no official status within the W3C. See this W3C page for the latest draft. 8. What is UDDI?UDDI (Universal Description, Discovery, and Integration) currently represents the discovery layer within the Web services protocol stack.UDDI was originally created by Microsoft, IBM, and Ariba, and represents a technical specification for publishing and finding businesses and Web services. At its core, UDDI consists of two parts.
Beta versions of UDDI Version 2 are available at: 9. How do I get started with Web Services?The easiest way to get started with Web services is to learn XML-RPC. Check out the XML-RPC specification10. Does the W3C support any Web service standards?The World Wide Web Consortium (W3C) is actively pursuing standardization of Web service protocols. In September 2000, the W3C established anXML Protocol Activity. The goal of the group is to establish a formal standard for SOAP. A draft version of SOAP 1.2 is currently under review, and progressing through the official W3C recommendation process.On January 25, 2002, the W3C also announced the formation of a Web Service Activity. This new activity will include the current SOAP work as well as two new groups. The first new group is the Web Services Description Working Group, which will take up work on WSDL. The second new group is the Web Services Architecture Working Group, which will attempt to create a cohesive framework for Web service protocols. |
using System;
using System.Linq;
using System.Collections.Generic;
class app {
static void Main() {
string[] names = { "Burke", "Connor", "Frank",
"Everett", "Albert", "George",
"Harris", "David" };
IEnumerable query = from s in names
where s.Length == 5
orderby s
select s.ToUpper();
foreach (string item in query)
Console.WriteLine(item);
}
} BURKE DAVID FRANK To understand how language-integrated query works, we need to dissect the first statement of our program. IEnumerablequery = from s in names where s.Length == 5 orderby s select s.ToUpper();
Dim query As IEnumerable(Of String) = From s in names _
Where s.Length = 5 _
Order By s _
Select s.ToUpper()IEnumerablequery = names .Where(s => s.Length == 5) .OrderBy(s => s) .Select(s => s.ToUpper());
Funcfilter = s => s.Length == 5; Func extract = s => s; Func project = s => s.ToUpper(); IEnumerable query = names.Where(filter) .OrderBy(extract) .Select(project);
Funcfilter = delegate (string s) { return s.Length == 5; }; Func extract = delegate (string s) { return s; }; Func project = delegate (string s) { return s.ToUpper(); }; IEnumerable query = names.Where(filter) .OrderBy(extract) .Select(project);
Funcf = n => n < 5; Expression > e = n => n < 5;
bool isSmall = f(2); // isSmall is now true
bool isSmall = e(2); // compile error, expressions == data
Expression> filter = n => n < 5; BinaryExpression body = (BinaryExpression)filter.Body; ParameterExpression left = (ParameterExpression)body.Left; ConstantExpression right = (ConstantExpression)body.Right; Console.WriteLine("{0} {1} {2}", left.Name, body.NodeType, right.Value);
n LessThan 5
namespace System.Linq {
using System;
using System.Collections.Generic;
public static class Enumerable {
public static IEnumerable Where(
this IEnumerable source,
Func predicate) {
foreach (T item in source)
if (predicate(item))
yield return item;
}
}
} IEnumerablequery = Enumerable.Where(names, s => s.Length < 6);
IEnumerablequery = names.Where(s => s.Length < 6);
using System.Linq; // makes query operators visible
public class MySequence : IEnumerable{ public IEnumerator GetEnumerator() { for (int i = 1; i <= 10; i++) yield return i; } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public IEnumerable Where(Func filter) { for (int i = 1; i <= 10; i++) if (filter(i)) yield return i; } }
MySequence s = new MySequence();
foreach (int item in s.Where(n => n > 3))
Console.WriteLine(item);public static IEnumerableOfType (this IEnumerable source) { foreach (object item in source) if (item is T) yield return (T)item; }
// "classic" cannot be used directly with query operators IEnumerable classic = new OlderCollectionType(); // "modern" can be used directly with query operators IEnumerable
modern yields the same sequence of values as does classic. However, its type is compatible with modern IEnumerableobject[] vals = { 1, "Hello", true, "World", 9.1 };
IEnumerable justStrings = vals.OfType(); // declare a variable containing some strings
string[] names = { "Allen", "Arthur", "Bennett" };
// declare a variable that represents a query
IEnumerable ayes = names.Where(s => s[0] == 'A');
// evaluate the query
foreach (string item in ayes)
Console.WriteLine(item);
// modify the original information source
names[0] = "Bob";
// evaluate the query again, this time no "Allen"
foreach (string item in ayes)
Console.WriteLine(item); // declare a variable containing some strings
string[] names = { "Allen", "Arthur", "Bennett" };
// declare a variable that represents the result
// of an immediate query evaluation
string[] ayes = names.Where(s => s[0] == 'A').ToArray();
// iterate over the cached query results
foreach (string item in ayes)
Console.WriteLine(item);
// modifying the original source has no effect on ayes
names[0] = "Bob";
// iterate over result again, which still contains "Allen"
foreach (string item in ayes)
Console.WriteLine(item);interface is obvious. To the clients who write the queries, on the other hand, it is a great advantage to have a common type for remote information sources. Not only does it allow them to write polymorphic queries that can be used against different sources of data, but it also opens up the possibility for writing queries that go across domains.public class Person {
string name;
int age;
bool canCode;
public string Name {
get { return name; } set { name = value; }
}
public int Age {
get { return age; } set { age = value; }
}
public bool CanCode {
get { return canCode; } set { canCode = value; }
}
}Person value = new Person {
Name = "Chris Smith", Age = 31, CanCode = false
};Person value = new Person(); value.Name = "Chris Smith"; value.Age = 31; value.CanCode = false;
IEnumerablequery = names.Select(s => new Person { Name = s, Age = 21, CanCode = s.Length == 5 });
static Person[] people = {
new Person { Name="Allen Frances", Age=11, CanCode=false },
new Person { Name="Burke Madison", Age=50, CanCode=true },
new Person { Name="Connor Morgan", Age=59, CanCode=false },
new Person { Name="David Charles", Age=33, CanCode=true },
new Person { Name="Everett Frank", Age=16, CanCode=true },
};object v1 = new Person {
Name = "Brian Smith", Age = 31, CanCode = false
};
object v2 = new { // note the omission of type name
Name = "Brian Smith", Age = 31, CanCode = false
};var s = "Bob"; var n = 32; var b = true;
string s = "Bob"; int n = 32; bool b = true;
var value = new {
Name = " Brian Smith", Age = 31, CanCode = false
};internal class ??? {
string _Name;
int _Age;
bool _CanCode;
public string Name {
get { return _Name; } set { _Name = value; }
}
public int Age{
get { return _Age; } set { _Age = value; }
}
public bool CanCode {
get { return _CanCode; } set { _CanCode = value; }
}
public bool Equals(object obj) { ... }
public bool GetHashCode() { ... }
}var bob = new Person { Name = "Bob", Age = 51, CanCode = true };
var jane = new { Age = 29, FirstName = "Jane" };
var couple = new {
Husband = new { bob.Name, bob.Age },
Wife = new { Name = jane.FirstName, jane.Age }
};
int ha = couple.Husband.Age; // ha == 51
string wn = couple.Wife.Name; // wn == "Jane"var couple = new {
Husband = new { Name = bob.Name, Age = bob.Age },
Wife = new { Name = jane.FirstName, Age = jane.Age }
};var query = people.Select(p => new {
p.Name, BadCoder = p.Age == 11
});
foreach (var item in query)
Console.WriteLine("{0} is a {1} coder",
item.Name,
item.BadCoder ? "bad" : "good");string[] names = { "Burke", "Connor", "Frank", "Everett",
"Albert", "George", "Harris", "David" };
// unity sort
var s1 = names.OrderBy(s => s);
var s2 = names.OrderByDescending(s => s);
// sort by length
var s3 = names.OrderBy(s => s.Length);
var s4 = names.OrderByDescending(s => s.Length);string[] names = { "Burke", "Connor", "Frank", "Everett",
"Albert", "George", "Harris", "David" };
var s1 = names.OrderBy(s => s.Length).ThenBy(s => s);"Burke", "David", "Frank", "Albert", "Connor", "George", "Harris", "Everett"
public interface IGrouping: IEnumerable { public K Key { get; } }
string[] names = { "Albert", "Burke", "Connor", "David",
"Everett", "Frank", "George", "Harris"};
// group by length
var groups = names.GroupBy(s => s.Length);
foreach (IGrouping group in groups) {
Console.WriteLine("Strings of length {0}", group.Key);
foreach (string value in group)
Console.WriteLine(" {0}", value);
} Strings of length 6 Albert Connor George Harris Strings of length 5 Burke David Frank Strings of length 7 Everett
string[] names = { "Albert", "Burke", "Connor", "David",
"Everett", "Frank", "George", "Harris"};
// group by length
var groups = names.GroupBy(s => s.Length, s => s[0]);
foreach (IGrouping group in groups) {
Console.WriteLine("Strings of length {0}", group.Key);
foreach (char value in group)
Console.WriteLine(" {0}", value);
} Strings of length 6 A C G H Strings of length 5 B D F Strings of length 7 E
Note From this example that the projected type does not need to be the same as the source. In this case, we created a grouping of integers to characters from a sequence of strings.
public static U Aggregate(this IEnumerable source, U seed, Func func) { U result = seed; foreach (T element in source) result = func(result, element); return result; }
string[] names = { "Albert", "Burke", "Connor", "David",
"Everett", "Frank", "George", "Harris"};
int count = names.Aggregate(0, (c, s) => c + s.Length);
// count == 46int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
string[] names = { "Albert", "Burke", "Connor", "David",
"Everett", "Frank", "George", "Harris"};
int total1 = numbers.Sum(); // total1 == 55
int total2 = names.Sum(s => s.Length); // total2 == 46Note The second Sum statement is equivalent to the previous example using Aggregate.
string[] text = { "Albert was here",
"Burke slept late",
"Connor is happy" };
var tokens = text.Select(s => s.Split(' '));
foreach (string[] line in tokens)
foreach (string token in line)
Console.Write("{0}.", token);Albert.was.here.Burke.slept.late.Connor.is.happy.
string[] text = { "Albert was here",
"Burke slept late",
"Connor is happy" };
var tokens = text.SelectMany(s => s.Split(' '));
foreach (string token in tokens)
Console.Write("{0}.", token);string[] names = { "Burke", "Connor", "Frank", "Everett",
"Albert", "George", "Harris", "David" };
var query = names.SelectMany(n =>
people.Where(p => n.Equals(p.Name))
); the nparameter passed in from the outer source. Thus people.Where is called once for each n, with the resulting sequences flattened by SelectMany for the final output. The result is a sequence of all the people whose name appears in thenames array.string[] names = { "Burke", "Connor", "Frank", "Everett",
"Albert", "George", "Harris", "David" };
var query = names.Join(people, n => n, p => p.Name, (n,p) => p);string[] names = { "Burke", "Connor", "Frank", "Everett",
"Albert", "George", "Harris", "David" };
var query = names.GroupJoin(people, n => n, p => p.Name,
(n, matching) =>
new { Name = n, Count = matching.Count() }
);IEnumerablequery = names .Where(s => s.Length == 5) .OrderBy(s => s) .Select(s => s.ToUpper());
IEnumerablequery = from s in names where s.Length == 5 orderby s select s.ToUpper();
query-expression ::= from-clause query-body
query-body ::=
query-body-clause* final-query-clause query-continuation?
query-body-clause ::=
(from-clause
| join-clause
| let-clause
| where-clause
| orderby-clause)
from-clause ::= from itemName in srcExpr
join-clause ::= join itemName in srcExpr on keyExpr equals keyExpr
(into itemName)?
let-clause ::= let itemName = selExpr
where-clause ::= where predExpr
orderby-clause ::= orderby (keyExpr (ascending | descending)?)*
final-query-clause ::=
(select-clause | groupby-clause)
select-clause ::= select selExpr
groupby-clause ::= group selExpr by keyExpr
query-continuation ::= into itemName query-bodyvar query1 = from p in people
where p.Age > 20
orderby p.Age descending, p.Name
select new {
p.Name, Senior = p.Age > 30, p.CanCode
};
var query2 = from p in people
where p.Age > 20
orderby p.Age descending, p.Name
group new {
p.Name, Senior = p.Age > 30, p.CanCode
} by p.CanCode;var query1 = people.Where(p => p.Age > 20)
.OrderByDescending(p => p.Age)
.ThenBy(p => p.Name)
.Select(p => new {
p.Name,
Senior = p.Age > 30,
p.CanCode
});
var query2 = people.Where(p => p.Age > 20)
.OrderByDescending(p => p.Age)
.ThenBy(p => p.Name)
.GroupBy(p => p.CanCode,
p => new {
p.Name,
Senior = p.Age > 30,
p.CanCode
});var query = from s1 in names
where s1.Length == 5
from s2 in names
where s1 == s2
select s1 + " " + s2;string[] names = { "Burke", "Connor", "Frank", "Everett",
"Albert", "George", "Harris", "David" };Burke Burke Frank Frank David David
var query = names.Where(s1 => s1.Length == 5)
.SelectMany(s1 => names, (s1,s2) => new {s1,s2})
.Where($1 => $1.s1 == $1.s2)
.Select($1 => $1.s1 + " " + $1.s2);Note This version of SelectMany takes an extra lambda expression which is used to produce the result based on elements from the outer and inner sequences. In this lambda expression, the two range variables are collected in an anonymous type. The compiler invents a variable name $1 to denote that anonymous type in subsequent lambda expressions.
var query = from n in names
join p in people on n equals p.Name into matching
select new { Name = n, Count = matching.Count() };var query = names.GroupJoin(people, n => n, p => p.Name,
(n, matching) =>
new { Name = n, Count = matching.Count() }
); by clause. For example, consider this program:var query = from item in names
orderby item
group item by item.Length into lengthGroups
orderby lengthGroups.Key descending
select lengthGroups;
foreach (var group in query) {
Console.WriteLine("Strings of length {0}", group.Key);
foreach (var val in group)
Console.WriteLine(" {0}", val);
}Strings of length 7 Everett Strings of length 6 Albert Connor George Harris Strings of length 5 Burke David Frank
create table People (
Name nvarchar(32) primary key not null,
Age int not null,
CanCode bit not null
)
create table Orders (
OrderID nvarchar(32) primary key not null,
Customer nvarchar(32) not null,
Amount int
)[Table(Name="People")]
public class Person {
[Column(DbType="nvarchar(32) not null", Id=true)]
public string Name;
[Column]
public int Age;
[Column]
public bool CanCode;
}
[Table(Name="Orders")]
public class Order {
[Column(DbType="nvarchar(32) not null", Id=true)]
public string OrderID;
[Column(DbType="nvarchar(32) not null")]
public string Customer;
[Column]
public int? Amount;
}Note This example that nullable columns map to nullable types in the CLR (nullable types first appeared in version 2.0 of the .NET Framework), and that for SQL types that don't have a 1:1 correspondence with a CLR type (for example, nvarchar, char, text), the original SQL type is retained in the CLR metadata.
// establish a query context over ADO.NET sql connection
DataContext context = new DataContext(
"Initial Catalog=petdb;Integrated Security=sspi");
// grab variables that represent the remote tables that
// correspond to the Person and Order CLR types
Table custs = context.GetTable();
Table orders = context.GetTable();
// build the query
var query = from c in custs
from o in orders
where o.Customer == c.Name
select new {
c.Name,
o.OrderID,
o.Amount,
c.Age
};
// execute the query
foreach (var item in query)
Console.WriteLine("{0} {1} {2} {3}",
item.Name, item.OrderID,
item.Amount, item.Age); SELECT [t0].[Age], [t1].[Amount],
[t0].[Name], [t1].[OrderID]
FROM [Customers] AS [t0], [Orders] AS [t1]
WHERE [t1].[Customer] = [t0].[Name]var e = new XElement("Person",
new XAttribute("CanCode", true),
new XElement("Name", "Loren David"),
new XElement("Age", 31));
var s = e.ToString();Loren David 31
var e2 = XElement.Load(xmlReader); var e1 = XElement.Parse( @""); Loren David 31
var query = from p in people
where p.CanCode
select new XElement("Person",
new XAttribute("Age", p.Age),
p.Name);var x = new XElement("People",
from p in people
where p.CanCode
select
new XElement("Person",
new XAttribute("Age", p.Age),
p.Name));Allen Frances Connor Morgan
Dim x = _
>p.Name _
%>
IEnumerablejustNames = from e in x.Descendants("Person") select e.Value; //justNames = ["Allen Frances", "Connor Morgan"]
IEnumerablepersons = from e in x.Descendants("Person") select new Person { Name = e.Value, Age = (int)e.Attribute("Age") };
IEnumerablepersons = from e in x.Descendants("Person") select new Person { Name = e.Value, Age = (int?)e.Attribute("Age") ?? 21 };
Dim persons = _
From e In x... _
Select new Person { _
.Name = e.Value, _
.Age = IIF(e.@Age, 21) _
} . The Value property gets the first attribute in the collection and calls the Value property on that attribute.| Operator | Description |
|---|---|
| Where | Restriction operator based on predicate function |
| Select/SelectMany | Projection operators based on selector function |
| Take/Skip/ TakeWhile/SkipWhile | Partitioning operators based on position or predicate function |
| Join/GroupJoin | Join operators based on key selector functions |
| Concat | Concatenation operator |
| OrderBy/ThenBy/OrderByDescending/ThenByDescending | Sorting operators sorting in ascending or descending order based on optional key selector and comparer functions |
| Reverse | Sorting operator reversing the order of a sequence |
| GroupBy | Grouping operator based on optional key selector and comparer functions |
| Distinct | Set operator removing duplicates |
| Union/Intersect | Set operators returning set union or intersection |
| Except | Set operator returning set difference |
| AsEnumerable | Conversion operator to IEnumerable |
| ToArray/ToList | Conversion operator to array or List |
| ToDictionary/ToLookup | Conversion operators to Dictionary |
| OfType/Cast | Conversion operators to IEnumerable |
| SequenceEqual | Equality operator checking pairwise element equality |
| First/FirstOrDefault/Last/LastOrDefault/Single/SingleOrDefault | Element operators returning initial/final/only element based on optional predicate function |
| ElementAt/ElementAtOrDefault | Element operators returning element based on position |
| DefaultIfEmpty | Element operator replacing empty sequence with default-valued singleton sequence |
| Range | Generation operator returning numbers in a range |
| Repeat | Generation operator returning multiple occurrences of a given value |
| Empty | Generation operator returning an empty sequence |
| Any/All | Quantifier checking for existential or universal satisfaction of predicate function |
| Contains | Quantifier checking for presence of a given element |
| Count/LongCount | Aggregate operators counting elements based on optional predicate function |
| Sum/Min/Max/Average | Aggregate operators based on optional selector functions |
| Aggregate | Aggregate operator accumulating multiple values based on accumulation function and optional seed |