tag:blogger.com,1999:blog-70640227204175639922024-02-19T23:17:12.552-08:00Web ServiceJonhttp://www.blogger.com/profile/10247055052512255066noreply@blogger.comBlogger13125tag:blogger.com,1999:blog-7064022720417563992.post-53688768034177895392007-12-27T21:03:00.000-08:002007-12-27T21:05:51.823-08:00How do we use a Web Service?This is how the Web Service releases information. We need to write clients to extract the information from the XML document. Theses clients could be<br /><span style="color:#ffff00;">A Web page<br />A console / Windows application<br />A Wireless Markup Language (WML) / WMLScript to interact with mobile phones<br />A Palm / Win CE application to use on Personal Digital Assistants (PDAs). I will explain this process in the</span><br />You can also call the Web Service directly using the HTTP GET method. In this case we will not be going through the above Web page and clicking the Invoke button. The syntax for directly calling the Web Service using HTTP GET is<br />http://server/webServiceName.asmx/functionName?parameter=parameterValue<br />Therefore, the call for our Web Service will be<br />http://localhost/work/aspx/SampleService.asmx/GetSecurityInfo?Code=IBM<br />This will produce the same result as clicking the Invoke button.<br />Now we know how to create a Web Service and use it. But the work is half done. How will our clients find our Web Service? Is there any way to search for our Web Service on the Internet? Is there a Web crawler or a Yahoo search engine for Web Services? In order to answer these questions we need to create a "discovery" file for our Web Service.<br /><br /><strong>Creating a Discovery file</strong><br />Web Service discovery is the process of locating and interrogating Web Service descriptions, which is a preliminary step for accessing a Web Service. It is through the discovery process that Web Service clients learn that a Web Service exists, what its capabilities are, and how to properly interact with it. Discovery file is a XML document with a .DISCO extension. It is not compulsory to create a discovery file for each Web Service. Here is a sample discovery file for our securities Web Service.<br /><?xml version="1.0" ?><br /><disco:discovery disco="http://schemas.xmlsoap.org/disco/"><br /><scl:contractref ref="http://localhost/work/aspx/SampleService.asmx?SDL"><br /></disco:discovery><br />We can name this file "SampleService.disco" and save it to the same directory as the Web Service. If we are creating any other Web Services under the "/work/aspx" directory, it is wise to enable "dynamic discovery." Dynamic discovery will scan for all the *.DISCO files in all the subdirectories of "/work/aspx" automatically.<br /><?xml version="1.0" ?><br /><dynamicdiscovery xmlns="urn:schemas-dynamicdiscovery:disco.2000-03-17"><br /></dynamicdiscovery><br /><br /><strong>An example of an active discovery file can be found at</strong> <a href="http://services3.xmethods.net/dotnet/default.disco">http://services3.xmethods.net/dotnet/default.disco</a>. By analyzing the discovery file we can find where the Web Services reside in the system. Unfortunately both these methods require you to know the exact URL of the discovery file. If we cannot find the discovery file, we will not be able to locate the Web Services. Universal Description, Discovery, and Integration (UDDI) describes mechanisms to advertise existing Web Services. This technology is still at the infant stage. UDDI is an open, Internet-based specification designed to be the building block that will enable businesses to quickly, easily, and dynamically find and transact business with one another using their preferred applications. A reference site for UDDI is <a href="http://uddi.microsoft.com/">http://uddi.microsoft.com</a>.<br />There have been a lot of Web Services written by developers. www.xmethods.com is one of the sites that has an index of Web Services. Some developers are building WSDL search engines to find Web Services on the Web.<br /><br /><strong>Deploying a Web Service</strong><br />Deploying the Web Services from development to staging or production is very simple. Similar to ASP.NET applications, just copy the .ASMX file and the .DISCO files to the appropriate directories, and you are in business.<br /><br /><strong>The future of the Web Services<br /></strong>The future looks bright for the Web Service technology. Microsoft is not alone in the race for Web Service technology. Sun and IBM are very interested. There are SOAP toolkits available for Apache and Java Web servers. I believe Web Services needs a bit of work, especially the Web Service discovery process. It is still very primitive.<br />On a positive note, Web Services have the potential to introduce new concepts to the Web. One I refer to as "pay per view" architecture. Similar to pay-TV, we can build Web sites that can generate revenue for each request a user sends (as opposed to a flat, monthly subscription). In order to get some data, we can sometimes pay a small fee. Commercially this could be handy for a lot of people.<br /><br /><strong>Examples<br /></strong>Online newspaper sites can publish a 10-year-old article with a $2 "pay per view" structure.<br />Stock market portals can itemize every user portfolio for every single stock quote and build pricing and discount structures. And the list goes on ...<br />On a very optimistic note, Web Services can be described as the "plug and play" building blocks of enterprise Business to Business (B2B) Web solutions.<br /><strong>Appendix A<br /></strong><span style="color:#ffff00;"><?xml version="1.0" ?><br /><serviceDescription xmlns:s0="http://tempuri.org/" name="SecurityWebService" targetNamespace="http://tempuri.org/"<br />xmlns="urn:schemas-xmlsoap-org:sdl.2000-01-25"><br /><soap xmlns="urn:schemas-xmlsoap-org:soap-sdl-2000-01-25"><br /><service><br /><addresses><br /><address uri="http://localhost/work/aspx/SampleService.asmx"><br /></addresses><br /><requestresponse name="GetSecurityInfo" soapaction="http://tempuri.org/GetSecurityInfo"><br /><request ref="s0:GetSecurityInfo"><br /><response ref="s0:GetSecurityInfoResult"><br /><info>This method call will get the company name and the price for a given security code.</info><br /></requestresponse><br /></service><br /></soap><br /><httppost xmlns="urn:schemas-xmlsoap-org:post-sdl-2000-01-25"><br /><service><br /><requestresponse name="GetSecurityInfo" href="http://localhost/work/aspx/SampleService.asmx/GetSecurityInfo"><br /><request><br /><form><br /><input name="Code"><br /></form><br /></request><br /><response><br /><mimexml ref="s0:SecurityInfo"><br /></response><br /><info>This method call will get the company name and the price for a given security code.</info><br /></requestresponse><br /></service><br /></httppost><br /><httpget xmlns="urn:schemas-xmlsoap-org:get-sdl-2000-01-25"><br /><service><br /><requestresponse name="GetSecurityInfo" href="http://localhost/work/aspx/SampleService.asmx/GetSecurityInfo"><br /><request><br /><param name="Code"><br /></request><br /><response><br /><mimexml ref="s0:SecurityInfo"><br /></response><br /><info>This method call will get the company name and the price for a given security code.</info><br /></requestresponse><br /></service><br /></httpget><br /><schema targetNamespace="http://tempuri.org/" attributeFormDefault="qualified"<br />elementFormDefault="qualified" xmlns="http://www.w3.org/1999/XMLSchema"><br /><element name="GetSecurityInfo"><br /><complextype><br /><all><br /><element name="Code" q1="http://www.w3.org/1999/XMLSchema" type="q1:string" nullable="true"><br /></all><br /></complextype><br /></element><br /><element name="GetSecurityInfoResult"><br /><complextype><br /><all><br /><element name="result" type="s0:SecurityInfo"><br /></all><br /></complextype><br /></element><br /><complextype name="SecurityInfo"><br /><all><br /><element name="Code" q2="http://www.w3.org/1999/XMLSchema" type="q2:string" nullable="true"><br /><element name="CompanyName" q3="http://www.w3.org/1999/XMLSchema" type="q3:string" nullable="true"><br /><element name="Price" q4="http://www.w3.org/1999/XMLSchema" type="q4:double"><br /></all><br /></complextype><br /><element name="SecurityInfo" type="s0:SecurityInfo"><br /></schema><br /></servicedescription><br /><br /></span><span style="color:#ffff00;"></span>Jonhttp://www.blogger.com/profile/10247055052512255066noreply@blogger.com0tag:blogger.com,1999:blog-7064022720417563992.post-84247754234902541212007-12-27T21:00:00.000-08:002007-12-27T21:03:55.473-08:00Creating a .NET Web ServiceMicrosoft .NET marketing has created a huge hype about its Web Services. This is the first of two articles on Web Services. Here we will create a .NET Web Service using C#. We will look closely at the Discovery protocol, UDDI, and the future of the Web Services. In the next article, we will concentrate on consuming existing Web Services on multiple platforms (i.e., Web, WAP-enabled mobile phones, and windows applications).<br /><br /><strong>Why do we need Web Services?<br /></strong>After buying something over the Internet, you may have wondered about the delivery status. Calling the delivery company consumes your time, and it's also not a value-added activity for the delivery company. To eliminate this scenario the delivery company needs to expose the delivery information without compromising its security. Enterprise security architecture can be very sophisticated. What if we can just use port 80 (the Web server port) and expose the information through the Web server? Still, we have to build a whole new Web application to extract data from the core business applications. This will cost the delivery company money. All the company wants is to expose the delivery status and concentrate on its core business. This is where Web Services come in.<br /><br /><strong>What is a Web Service?</strong><br />Web Services are a very general model for building applications and can be implemented for any operation system that supports communication over the Internet. Web Services use the best of component-based development and the Web. Component-base object models like Distributed Component Object Model (DCOM), Remote Method Invocation (RMI), and Internet Inter-Orb Protocol (IIOP) have been around for some time. Unfortunately all these models depend on an object-model-specific protocol. Web Services extend these models a bit further to communicate with the Simple Object Access Protocol (SOAP) and Extensible Markup Language (XML) to eradicate the object-model-specific protocol barrier (see Figure 1).<br />Web Services basically uses Hypertext Transfer Protocol (HTTP) and SOAP to make business data available on the Web. It exposes the business objects (COM objects, Java Beans, etc.) to SOAP calls over HTTP and executes remote function calls. The Web Service consumers are able to invoke method calls on remote objects by using SOAP and HTTP over the Web.<br /><br /><br />How is the user at Location A aware of the semantics of the Web Service at Location B? This question is answered by conforming to a common standard. Service Description Language (SDL), SOAP Contract Language (SCL) and Network Accessible Specification Language (NASSL) are some XML-like languages built for this purpose. However, IBM and Microsoft recently agreed on the Web Service Description Language (WSDL) as the Web Service standard.<br />The structure of the Web Service components is exposed using this Web Service Description Language. WSDL 1.1 is a XML document describing the attributes and interfaces of the Web Service. The new specification is available at msdn.microsoft.com/xml/general/wsdl.asp.<br /><br /><strong>The task ahead</strong><br />The best way to learn about Web Services is to create one. We all are familiar with stock quote services. The NASDAQ, Dow Jones, and Australian Stock Exchange are famous examples. All of them provide an interface to enter a company code and receive the latest stock price. We will try to replicate the same functionality.<br />The input parameters for our securities Web service will be a company code. The Web service will extract the price feed by executing middle-tier business logic functions. The business logic functions are kept to a bare minimum to concentrate on the Web service features.<br /><br /><strong>Tools to create a Web Service</strong><br />The core software component to implement this application will be MS .NET Framework SDK, which is currently in beta. You can download a version from Microsoft. I used Windows 2000 Advance Server on a Pentium III with 300 MB of RAM.<br />The preferred Integration Development Environment (IDE) to create Web Services is Visual Studio .NET. However, you can easily use any text editor (WordPad, Notepad, Visual Studio 6.0) to create a Web Service file.<br /><br /><strong>I assume you are familiar with the following concepts:<br /></strong>Basic knowledge of .NET platform<br />Basic knowledge of C#<br />Basic knowledge of object-oriented concepts<br />Creating a Web Service<br />We are going to use C# to create a Web Service called "SecurityWebService." A Web Service file will have an .ASMX file extension. (as opposed to an .ASPX file extension of a ASP.NET file).<br /><br /><strong>The first line of the file will look like</strong><br /><%@ WebService Language="C#" class="SecurityWebService" %><br />This line will instruct the compiler to run on Web Service mode and the name of the C# class. We also need to access the Web Service namespace. It is also a good practice to add a reference to the System namespace.<br />using System;<br />using System.Web.Services;<br />The SecurityWebService class should inherit the functionality of the Web Services class. Therefore, we put the following line of code:<br />public class SecurityWebService : WebService<br />Now we can use our object-oriented programming skills to build a class. C# classes are very similar to C++ or Java classes. It will be a walk in the park to create a C# class for anyone with either language-coding skills.<br />Dot-net Web Services are intelligent enough to cast basic data types. Therefore, if we return "int," "float," or "string" data types, it can convert them to standard XML output. Unfortunately, in most cases we need get a collection of data regarding a single entity. Let's take an example.<br />Our SecurityWebService stock quotes service requires the user to enter a company code, and it will deliver the full company name and the current stock price. Therefore, we have three pieces of information for a single company:<br />Company code (data type - string)<br />Company name (data type - string)<br />Price (data type - Double) We need to extract all this data when we are referring to a single stock quote. There are several ways of doing this. The best way could be to bundle them in an enumerated data type. We can use "structs" in C# to do this, which is very similar to C++ structs.<br />public struct SecurityInfo<br />{<br />public string Code;<br />public string CompanyName;<br />public double Price;<br />}<br /><strong>Now we have all the building blocks to create our Web Service. Therefore, our code will look like.</strong><br /><%@ WebService Language="C#" class="SecurityWebService" %><br />using System;<br />using System.Web.Services;<br />public struct SecurityInfo<br />{<br />public string Code;<br />public string CompanyName;<br />public double Price;<br />}<br />public class SecurityWebService : WebService<br />{<br />private SecurityInfo Security;<br /><br />public SecurityWebService()<br />{<br />Security.Code = "";<br />Security.CompanyName = "";<br />Security.Price = 0;<br />}<br />private void AssignValues(string Code)<br />{<br />// This is where you use your business components.<br />// Method calls on Business components are used to populate the data.<br />// For demonstration purposes, I will add a string to the Code and<br />// use a random number generator to create the price feed.<br /><br />Security.Code = Code;<br />Security.CompanyName = Code + " Pty Ltd";<br />Random RandomNumber = new System.Random();<br />Security.Price = double.Parse(new System.Random(RandomNumber.Next(1,10)).NextDouble().ToString("##.##"));<br />}<br />[WebMethod(Description="This method call will get the company name and the price for a given security code.",EnableSession=false)]<br />public SecurityInfo GetSecurityInfo(string Code)<br />{<br />AssignValues(Code);<br />SecurityInfo SecurityDetails = new SecurityInfo();<br />SecurityDetails.Code = Security.Code;<br />SecurityDetails.CompanyName = Security.CompanyName;<br />SecurityDetails.Price = Security.Price;<br />return SecurityDetails;<br />}<br />}<br />Remember, this Web Service can be accessed through HTTP for any use. We may be referring to sensitive business data in the code and wouldn't want it to fall into the wrong hands. The solution is to protect the business logic function and only have access to the presentation functions. This is achieved by using the keyword "[Web Method]" in C#. Let's look at the function headers of our code.<br />[WebMethod(Description="This......",EnableSession=false)]<br />public SecurityInfo GetSecurityInfo(string Code)<br />This function is exposed to the public. The "description" tag can be used to describe the Web Service functionality. Since we will not be storing any session data, we will disable the session state.<br />private void AssignValues(string Code)<br />This is a business logic function that should not be publicly available. We do not want our sensitive business information publicly available on the Web. (Note:- Even if you change the "private" keyword to "public," it will still not be publicly available. You guessed it, the keyword "[Web Method]" is not used.)<br />We can use the business logic in this function to get the newest stock price quote. For the purpose of this article I have added some text to the company code to create the company name. The price value is generated using a random number generator.<br />We may save this file as "SampleService.asmx" under an Internet Information Service (IIS)-controlled directory. I have saved it under a virtual directory called "/work/aspx." I'll bring it up on a Web browser.<br /><br />This is a Web page rendered by the .NET Framework. We did not create this page. (The page is generated automatically by the system. I did not write any code to render it on the browser. This graphic is a by-product of the previous code.) This ready-to-use functionality is quite adequate for a simple Web Service. The presentation of this page can be changed very easily by using ASP.NET pagelets and config.web files. A very good example can be found at <a href="http://www.ibuyspy.com/store/InstantOrder.asmx">http://www.ibuyspy.com/store/InstantOrder.asmx</a>.<br />Notice a link to "SDL Contract." (Even if we are using WSDL, .NET Beta still refers to SDL. Hopefully this will be rectified in the next version). This is the description of the Web Service to create a proxy object. (I will explain this in the next article.) This basically gives an overview of the Web Service and it's public interface. If you look closely, you will only see the "Web-only" methods being illustrated. All the private functions and attributes are not described in the SDL contract. The SDL contract for the SecurityWebService can be found in Appendix A.Jonhttp://www.blogger.com/profile/10247055052512255066noreply@blogger.com1tag:blogger.com,1999:blog-7064022720417563992.post-38438090166046932462007-12-20T01:15:00.001-08:002007-12-20T01:15:40.414-08:00XML Web Services Overview<span style="font-family:arial;">An XML Web service is a programmable entity that provides a particular element of functionality, such as application logic, and is accessible to any number of potentially disparate systems using ubiquitous Internet standards, such as XML and HTTP. XML Web services depend heavily upon the broad acceptance of XML and other Internet standards to create an infrastructure that supports application interoperability at a level that solves many of the problems that previously hindered such attempts.<br />An XML Web service can be used internally by a single application or exposed externally over the Internet for use by any number of applications. Because it is accessible through a standard interface, an XML Web service allows heterogeneous systems to work together as a single web of computation.<br />Instead of pursuing the generic capabilities of code portability, XML Web services provide a viable solution for enabling data and system interoperability. XML Web services use XML-based messaging as a fundamental means of data communication to help bridge the differences that exist between systems that use incongruent component models, operating systems, and programming languages. Developers can create applications that weave together XML Web services from a variety of sources in much the same way that developers traditionally use components when creating a distributed application.<br />One of the core characteristics of an XML Web service is the high degree of abstraction that exists between the implementation and the consumption of a service. By using XML-based messaging as the mechanism by which the service is created and accessed, both the XML Web service client and the XML Web service provider are freed from needing any knowledge of each other beyond inputs, outputs, and location.<br />XML Web services are enabling a new era of distributed application development. It is no longer a matter of object model wars or programming language beauty contests. When systems are tightly coupled using proprietary infrastructures, this is done at the expense of application interoperability. XML Web services deliver interoperability on an entirely new level that negates such counterproductive rivalries. As the next revolutionary advancement of the Internet, XML Web services will become the fundamental structure that links together all computing devices.</span>Jonhttp://www.blogger.com/profile/10247055052512255066noreply@blogger.com0tag:blogger.com,1999:blog-7064022720417563992.post-77530116852838376452007-12-20T01:10:00.000-08:002007-12-20T01:13:05.436-08:00Windows Communication FoundationWCF is Microsoft's unified programming model and runtime for building Web services applications with managed code. It extends the .NET Framework with functionality to build secure, reliable, and transacted Web services that interoperate across platforms.<br />WCF is built from the ground-up to combine and extend the capabilities of existing Microsoft distributed systems technologies, including Enterprise Services, System.Messaging, .NET Remoting, ASMX, and WSE, to deliver a unified development experience based on Web services.<br />WCF supports the WS-* architecture, enabling the development of interoperable Web services <strong>that incorporate end-to-end security, reliability and transaction support:</strong><br /><br /><strong>Messaging:</strong> XML, SOAP, WS-Addressing, and MTOM<br />WCF supports both Representational State Transfer (REST) and SOAP-based Web services. WCF also supports WS-Addressing, which defines additions to the SOAP header for addressing SOAP messages. This frees SOAP from relying on the underlying transport protocol for addressing information. MTOM defines an optimized transmission format for attachments in SOAP messages based on the XML-binary Optimized Packaging (XOP) specification.<br /><br /><strong>Metadata:</strong> WSDL, WS-MetadataExchange, WS-Policy, and WS-SecurityPolicy<br />WCF supports the Web Services Description Language (WSDL), which defines a standard language for specifying services and various aspects of how those services can be used. WCF also supports WS-Policy and WS-SecurityPolicy to describe more dynamic aspects of a service's behavior that cannot be expressed in WSDL, such as a preferred security option. Lastly, WCF's support for WS-MetadataExchange means that clients can request service metadata, such as the WSDL and policies for a service, via SOAP.<br /><br /><strong>Security:</strong> WS-Security, WS-Trust, and WS-SecureConversation<br />WCF supports both transport-level security via SSL and message-level security, by implementing WS-Security, WS-Trust, and WS-SecureConversation. These specifications define additions to SOAP for message-level protection, integrity, authentication, and identity<br /><br /><strong>federation. Message-</strong>level security is not limited to a single type of credential and gives developers more granular control over which message parts should be secured.<br /><br /><strong>Reliability: WS-</strong>ReliableMessaging<br /><br /><strong>WCF supports WS-</strong>ReliableMessaging, which defines additions to the SOAP header that<br />enable<br /><strong>reliable end-to-</strong>end communication, even when multiple SOAP intermediaries are traversed. WS-ReliableMessaging can guarantee that a message arrives, that it arrives exactly once and that it arrives in order.<br /><br /><strong>Transactions: WS-</strong>Coordination, WS-AtomicTransaction<br /><br /><strong>WCF supports WS-</strong>Coordination and WS-AtomicTransaction, enabling two-phase commit<br /><br /><strong>transactions over SOAP-</strong>based exchanges.<br /><br />In addition to implementing the WS-* architecture, WCF also provides opportunities for new messaging scenarios with support for TCP, named pipes, P2P and custom transports. More flexibility is also available around hosting Web services. Windows Forms applications, Windows Presentation Foundation applications, ASP.NET applications, console applications, Windows services and COM+ services can all easily host Web services endpoints over different transports. WCF also has many options for digitally signing and encrypting messages, including the following token support: Kerberos, X.509, Username, and Security Assertion Markup Language (SAML).<br /><br /><strong>Windows Workflow Foundation</strong><br />Another new feature in the .NET Framework 3.0 used for the development of Web services is WF. WF is the programming model, engine, and tools for quickly building workflow-enabled applications on Windows. It provides a common framework for building workflows into Windows applications, whether those workflows coordinate interactions among software, people, or both.<br />WCF and WF are complementary building blocks for distributed application development. Workflows can drive the business process for a given service. Similarly, workflows in turn often need to interact with services to carry out a business process. As such, WCF and WF can be used to create workflow-enabled services and service-enabled workflows.<br />WF ships with a base activity library that includes activities for consuming and exposing services. This means that developers can create service-enabled workflows directly from within the workflow designer. Because WF provides native support for hosting and consuming services, developers can easily create composite applications that invoke other business logic.Jonhttp://www.blogger.com/profile/10247055052512255066noreply@blogger.com0tag:blogger.com,1999:blog-7064022720417563992.post-58231339623055054332007-12-20T01:09:00.001-08:002007-12-20T01:09:49.141-08:00Web Services EnhancementsWhile Visual Studio and the .NET Framework 2.0 provide support for the development of basic Web services, customers in recent years have required advanced Web services functionality, including end-to-end security, routing and message attachments. Web Services Enhancements (WSE) 3.0 is a fully supported extension of the .NET Framework 2.0 and add-on to Visual Studio 2005 for building secure Web services. Released in November 2005 to coincide with the release of Visual Studio 2005, WSE 3.0 implements the latest industry-supported WS-* specifications.<br />Now that the WS-Security family of specifications has, to a large extent, solidified, the main goal for WSE 3.0 is to provide developers with the first complete implementation of these security specifications. As such, WSE 3.0 supports the following WS-* specifications (see <a href="http://msdn2.microsoft.com/en-us/library/aa480728.aspx#wsmsplat_topic14">Appendix</a> for <strong>versioning information): </strong><br /><strong><br />XML, SOAP, WSDL<br />WS-Security<br />WS-Trust<br />WS-SecureConversation<br />WS-Addressing<br />MTOM</strong><br />The focus on security was also one of the reasons why WSE 3.0 supports MTOM. Securing attachments over Direct Internet Message Encapsulation (DIME) requires transport-level security, whereas MTOM attachments can be secured by using either transport- or message-level security. As a result, developers can secure Web services attachments by taking advantage of some of the benefits of message-level security, such as end-to-end security and support for different credential types.<br />WSE 3.0 also introduced a set of "turnkey" security scenarios. These scenarios are high-level security building blocks that allow developers to concentrate on the business logic of a service in the knowledge that the underlying Web services communication is secure. The new configuration editor has also made creating and maintaining WSE policy files much easier. A GUI wizard creates and configures turnkey scenarios, without the developer having to resort to the XML representation of the policy file. WSE 3.0 also defines security sessions via policy, such that any given service can also act as a Security Token Service (STS).<br /><br />One of the main objectives of the WSE 3.0 release is to provide a path to WCF, the unified programming model and runtime for building secure, reliable and transacted Web services. WSE 3.0 offers interoperability with WCF when using the turnkey security scenarios and also provides some programming model parity with WCF.<br /><br /><a name="wsmsplat_topic15"></a><strong>.NET Framework 3.0</strong><br />In parallel to the development of WSE, Microsoft has been developing the .NET Framework 3.0, its next-generation managed code programming model for building applications on the Windows platform. The .NET Framework 3.0 enables developers to create visually stunning, connected, and workflow-enabled applications. It will ship as a core part of Windows Vista and will also be available on Windows XP and Windows Server 2003 through the .NET Framework 3.0 Runtime Components. The main components of the .NET Framework 3.0 for building and leveraging Web services are WCF, the Windows Workflow Foundation (WF) and Windows CardSpace.Jonhttp://www.blogger.com/profile/10247055052512255066noreply@blogger.com0tag:blogger.com,1999:blog-7064022720417563992.post-36478794437976170332007-12-20T01:07:00.000-08:002007-12-20T01:08:42.744-08:00Visual Studio 2005 and the .NET Framework 2.0<strong>The .NET Framework 2.0</strong> is Microsoft's managed code programming model and runtime for building applications on the Windows platform. Visual Studio is the professional development environment for building these applications. Together, Visual Studio and the .NET Framework 2.0 are designed to improve developer productivity and increase application reliability and security by providing a fully managed application environment. Developers can build high-performance, multi-tier applications for Windows and the Web, and use the .NET Compact Framework to build smart device software for mobile devices.<br />The .NET Framework provides Web services support that enables the more than 3.5 million .NET developers to develop, discover, debug, deploy, and consume Web services using any of the more than 20 programming languages supported on .NET. Furthermore, the .NET Framework supports WS-I Basic Profile for cross-platform interoperability. This allows .NET applications to consume and expose Web services that interoperate with virtually any application, regardless of programming language or platform.<br />Visual Studio's "Add Web Reference" dialog box automatically generates proxy code for WSDL-defined Web services, enabling consumption of Web services in Windows, Web, Mobile and <strong>Office-based applications.</strong><br /><br />Visual Studio also makes it easy for developers to publish and locate Web services in UDDI. From the start page of Visual Studio, developers can publish information about their Web Services directly to UDDI. As developers create new services, they can make them known across the enterprise directly from Visual Studio. By connecting to UDDI through the "Add Web Reference" dialog box, a developer may locate available Web Services.<br /><br />Visual Studio also supports unit testing and load testing of Web services. Web services operations can be called directly from unit tests, much like local code. In addition, Visual Studio provides attributes and methods specifically for testing Web services.<br />Lastly, Visual Studio Tools for Office (VSTO) brings the power of Visual Studio and the .NET Framework 2.0 to business solutions built on Word and Excel. All Web services functionality offered by the .NET Framework can be exposed through Word and Excel solutions. As a result, developers can expose, consume, manage, and debug Web services within these solutions.<br /><br /><a name="wsmsplat_topic13"></a><strong>Visual Studio Team System</strong><br />Visual Studio Team System (VSTS) expands the Visual Studio product line to include new software lifecycle tools for operations managers, architects, testers, project managers, and developers. Released in November 2005, VSTS reduces the complexity of delivering distributed applications and facilitates communication among members of a software team.<br />For developers building Web services-enabled software, VSTS extends the core capabilities of Visual Studio 2005, enabling architects to work in teams to visually design collections of Web services and validate a distributed application's architectural design against the requirements of the deployment environment. Developers can define and modify Web methods for ASMX Web services graphically, alleviating the need to manually edit configuration files to specify Web services configuration information. VSTS also gives IT Professionals the tools to graphically specify Web services settings and constraints, such as authentication and security requirements.<br />VSTS includes Visual Studio Team Test (TT), an integrated Visual Studio component that enables code generation of test method stubs, code coverage analysis and running of tests inside the IDE. This functionality is useful for Web services developers that want to perform regression tests and performance tests. Since Web services generally expose a Web page for manual invocation, one can also use the integrated Web testing recorder to quickly record a series of Web services tests. Once activities against the target Web site are recorded, test code is generated and can be extended with further customization.<br />Lastly, Visual Studio Team Foundation Server (a part of VSTS) is the team collaboration server providing functionality such as version control, work item tracking, and enterprise project management for VSTS clients. Partners can extend Team Foundation Server through a set of Web services.Jonhttp://www.blogger.com/profile/10247055052512255066noreply@blogger.com1tag:blogger.com,1999:blog-7064022720417563992.post-59211886111716753152007-12-20T01:03:00.000-08:002007-12-20T01:05:05.113-08:00Vertical Web Services StandardsThe agreement on horizontal Web service standards, such as XML, SOAP, and the WS-* architecture created the foundation for the emergence of vertical Web services standards. Microsoft has played an active role in the creation of these standards, driving over a dozen vertical standards in the education, health care, finance, automotive, and telecommunication industries through working relationships with the following standards bodies:<br />Association for Cooperative Operations Research and Development (ACORD)<br />Association for Retail Industry Standards (ARTS)<br />Automotive Industry Action Group (AIAG)<br />Clinical Data Interchange Standards Consortium (CDISC)<br />Continental Automated Buildings Association (CABA)<br />Distributed Management Task Force (DMTF)<br />EAN International and the Unified Code Council (EAN.UCC)<br />EPCglobal<br />European Forum for Electronic Business (EEMA)<br />Financial Information eXchange (FIX/FPL)<br />Health Level Seven (HL7)<br />Human Resources XML (HR-XML)<br />IMS Global Learning Consortium (IMS)<br />Interactive Financial eXchange Forum (IFX)<br />OPC Foundation (OPC)<br />Open Financial Exchange Consortium (OFX Consortium)<br />Open Travel Alliance (OTA)<br />RosettaNet<br />Schools Interoperability Framework (SIF)<br />Society for Worldwide Interbank Financial Telecommunications (SWIFT)<br />TeleManagement Forum (TM Forum)<br /><br /><strong>Highlights of Microsoft's current working relationships with vertical standards bodies include:</strong><br /><br /><strong>Automotive Industry Action Group (AIAG)—</strong>AIAG is an association of companies involved in the automotive industry charged with developing standards for the automotive supply chain. Microsoft is a sponsoring board member. It co-sponsored a project to define the functional requirements and recommended guidance needed to drive service-oriented architectures (SOA) for next-generation automotive supply chain scenarios leveraging Web services.<br /><strong>Distributed Management Task Force (DMTF)—</strong>DMTF is an industry organization leading the development of management standards such as WS-Management. Microsoft co-founded this organization and is currently a board member.<br /><br /><strong>EPCglobal—</strong>EPCglobal leads the development of industry-driven standards for the Electronic Product Code (EPC) to support the use of Radio Frequency Identification (RFID) in trading networks. Microsoft is participating in the Reader Protocol and Reader Management working groups of EPC Global Software Action Group. Microsoft has also submitted XML message formats for the Reader Protocol specification and recently made contributions to the Reader Management specification.<br /><br /><strong>Health Level Seven (HL7)—</strong>HL7 is one of several American National Standards Institute (ANSI)–accredited Standards Developing Organizations (SDOs) operating in the healthcare arena. Microsoft has been driving the submission of three Web services specifications (WS-Addressing, WS-Security and WS-ReliableMessaging) as an update of the HL7 Web Services Basic Profile.<br /><br /><strong>IMS Global Learning Consortium—</strong>The IMS Global Learning Consortium develops standards for learning technology and several IMS specifications have become worldwide de facto standards for delivering learning products and services. Microsoft is a member of the Technical Board, helping IMS define and deliver e-Learning standards with prescriptive guidance for WS-Security, Addressing and MTOM-based attachments.<br /><br /><strong>Open Financial Exchange Consortium—</strong>The OFX Consortium leads the development of standards for the electronic exchange of financial data. Over 2000 banks and brokerage firms as well as major payroll processing companies use OFX. Microsoft is co-founder of the OFX Consortium and is currently working on OFX 2.0 extensions.<br /><br /><strong>RosettaNet—</strong>RosettaNet is a global standards organization that promotes collaborative commerce. Billions of dollars are transacted each year using RosettaNet standards. Microsoft currently hold seats on the Executive and Architectural Advisory Councils, driving RosettaNet's next-generation architectural specifications and integration framework based on Web services.<br /><br /><strong>TeleManagement Forum—</strong>The TM Forum is a global standards body for communications services, contributing to the Information and Communications Services (ICS) industry for over 15 years. Microsoft has been driving the creation of a specification for enabling Operations/Business Support Systems (OSS/BSS) functions to be exposed as Web services.Jonhttp://www.blogger.com/profile/10247055052512255066noreply@blogger.com0tag:blogger.com,1999:blog-7064022720417563992.post-46685755028668929722007-12-20T00:56:00.000-08:002007-12-20T01:01:43.920-08:00What Are Web Services?<span style="font-family:arial;">In recent years, the imperative to connect people, information, and processes has changed the way software is being developed. Successful IT systems increasingly require interoperability across platforms and flexible services that can easily evolve over time. This has led to the prevalence of XML as the universal language for representing and transmitting structured data that is independent of programming language, software platform, and hardware.<br />Building on the broad acceptance of XML, Web services are applications that use standard transports, encodings, and protocols to exchange information. With broad support across vendors and businesses, Web services enable computer systems on any platform to communicate over corporate intranets, extranets, and across the Internet with support for end-to-end security, reliable messaging, distributed transactions, and more.<br />Web services are based on a core set of standards that describe the syntax and semantics of software communication: XML provides the common syntax for representing data; the Simple Object Access Protocol (SOAP) provides the semantics for data exchange; and the Web Services Description Language (WSDL) provides a mechanism to describe the capabilities of a Web service. Additional specifications, collectively referred to as the WS-* architecture, define functionality for Web services discovery, eventing, attachments, security, reliable messaging, transactions, and management.</span><br /><br /><a name="wsmsplat_topic3"></a><span style="font-family:arial;"><strong>Microsoft Support for Web Services</strong><br />Since their inception, Web services have formed the foundation of Microsoft's interoperability efforts. In addition to building its entire developer platform around Web services with .NET, Microsoft continues its commitment to the standardization process—driving vendor consensus and interoperability for both horizontal and vertical standards.<br />In the coming years, Web services will play an even more pivotal role across the Microsoft platform—with new developer offerings, an amplified focus on IT operations and management, expanded offerings for consumers and information workers, innovation in the business applications market and increased community outreach. For developers, the Windows Communication Foundation (WCF) is Microsoft's next generation platform for building secure, reliable, and transacted Web services. For IT Professionals, Windows Server and Microsoft Operations Manager will enable the management of heterogeneous software and hardware systems using WS-Management. For consumers, Windows Vista will support the discovery of and interaction with Web services-enabled devices, such as printers, digital cameras, and home control systems.<br />In addition, Microsoft's vision for Web services extends beyond support in its own products. As a platform vendor, Microsoft is focused on delivering a Web services platform upon which other vendors and customers can build customized solutions. </span><br /><br /><a name="wsmsplat_topic4"></a><span style="font-family:arial;"><strong>Standards and Interoperability</strong><br />Broad vendor agreement on standards and proven interoperability have set Web services apart from integration technologies of the past. During the ongoing process of interoperability and standardization, Microsoft has driven efforts to create both horizontal as well as industry-specific Web services standards.</span><br /><br /><a name="wsmsplat_topic5"></a><strong><span style="font-family:arial;">Horizontal Web Services Standards</span></strong><br /><strong></strong><br /><a name="wsmsplat_topic6"></a><span style="font-family:arial;"><strong>WS-* Architecture</strong><br />As the Web services market rapidly expanded, the need for advanced standards governing Web services security, reliability, and transactions arose. Microsoft and other vendors across the industry responded to this need by authoring a set of specifications referred to collectively as the WS-* architecture. The goal of these specifications is to provide a blueprint for advanced functionality while retaining the simplicity of basic Web services.<br />The most important attribute of the WS-* architecture is composability. Protocol composability enables incremental development of Web services solutions only as individual requirements (such as security, reliable messaging, attachments, discovery, etc.) are needed. In isolation, each of these requirements solves an elemental need. In composition, they address higher-level functionality commonly required by distributed applications. As such, the WS-* specifications can be used either independently or in combination with one another. This eliminates the complexity and overhead associated with specifications that attempt to define multiple capabilities or are tightly coupled with other specifications. It also enables developers to apply only the specific functionality needed to solve the immediate need. As new application requirements arise, new specifications can be authored without compromising backwards compatibility.</span>Jonhttp://www.blogger.com/profile/10247055052512255066noreply@blogger.com0tag:blogger.com,1999:blog-7064022720417563992.post-90787679307848570742007-12-19T05:57:00.000-08:002007-12-19T05:59:44.967-08:00Creating .NET Web Services Step 5<strong>Step 5 - Show it Off</strong><br />Congratulations are in order, for you have now built your first fully-fledged .NET XML Data Web Service, without any IDE program such a VS .NET I might add, and using a tool as simple as Notepad. Now can anyone really say this was a big ordeal? I didn't think so.<br />Additionally, if you're wondering how anyone else will "discover" your Web service, then look no further: with the XML Web service "discovery", you can advertise your Web service and expose its location and other information, alongside a .discomap file providing links to your files.<br /><br />XML Web Service discovery, called DISCO for short, is Microsoft's Web Services Discovery tool. It "discovers" the URL for a Web Service and saves that information in a file on your local server. Here's how:<br />disco http://<a class="glossary" title=""Localhost" is an alias for the computer system the user is working on. It's also accessible through the 127.0.0.1 address." href="http://www.sitepoint.com/glossary.php?q=L#term_42">localhost</a>/suppliers.asmx?DISCO<br />This creates a static discovery file containing a WSDL file with all the important information pertaining to your Web Service. Opposite this static discovery file is a dynamic discovery .vsdisco file, which notes all the available Web Services located within that URL.<br />Remember from Step 2 the WSDL command for creating the source file with "?WSDL"? Now, for an already "discovered" file, you can use:<br />wsdl.exe /l:CS /n:WService /out:bin/GetSuppliers.cs http://localhost/suppliers.wsdl<br />to create your source file and, in turn, your DLL for Web Service access.<br />When you examine the created .disco file you'll notice it includes the following information:<br /><br /><span style="color:#ffff00;"><contractRef ref="</span><a href="http://localhost/suppliers.asmx?wsdl"><span style="color:#ffff00;">http://localhost/suppliers.asmx?wsdl</span></a><span style="color:#ffff00;">" docRef="</span><a href="http://localhost/suppliers.asmx"><span style="color:#ffff00;">http://localhost/suppliers.asmx</span></a><span style="color:#ffff00;">" xmlns="</span><a href="http://schemas.xmlsoap.org/disco/scl/"><span style="color:#ffff00;">http://schemas.xmlsoap.org/disco/scl/</span></a><span style="color:#ffff00;">" /></span><br />This contains the link to your Web Service so others can discover it, alongside XSD schemas, and service descriptions. Using this information others can parse the WSDL document, build a proxy source file, and implement this Web Service locally!<br />If you do have something you'd like to share, run over to the Microsoft UDDI (Universal Description, Discovery and Integration) Business Registry (UBR) node at <a href="http://uddi.microsoft.com/">http://uddi.microsoft.com</a>, which is currently supported by Microsoft, IBM and Ariba. Here you can find other available Web Services and their details, register your Web Service, and discover more about this whole business.<br />A little "Asynchronousity"<br />Before, I conclude this article I need to mention an additional method of calling Web Services from your application. Web Services by default form are called “synchronously”. As a result, both the application and its inherent Web Service will have to finish simultaneously. As such, a quicker method within the application will have to wait for any slower one to finish, before the application can fully display its results, potentially creating an unnecessary delay for the client. Likewise, since Web Service calls make use of Port 80 for communications, they can at times cause this type of delay. How would you be able to remedy such a situation? With a little asynchronousity, of course!<br />There are four common ways to make asynchronous method calls. Here we will demonstrate waiting for our asynchronous call utilizing the WaitHandle method, which determines when the service call is complete. The other three possible methods for asynchronous calls include:<br />The IsCompleted property of the IasyncResult returned by BeginInvoke, within our BeginSuppliers Method<br />Executing a callback method when the asynchronous call finishes<br />Finally, parallel any processing or code until the call completes prior to calling EndInvoke<br />Given that asynchronous calls can perform a given task without affecting other functions around them, let's implement our chosen technique. Going back to Step 2, you'll remember how we created our proxy class file for our .asmx Web Service file.<br />If you took the time to inspect it, you will have noticed that, aside from our main ShowSuppliers Dataset function, two additional functions were listed: BeginShowSuppliers and EndShowSuppliers. These are the asynchronous functions that will enable us to produce asynchronous Web Service calls implementing the WaitHandle Class’s WaitOne() Method, and here's how.<br />We do all this from the .aspx page we created in Step 4. Here's the additional code:<br />//Instantiate DLL GetInfo supInfo = new GetInfo();<br />// Begin the Asynchronous call to ShowSuppliers IAsyncResult AsyncWS = supInfo.BeginShowSuppliers(Catg, null, null);<br />//We wait for the callback AsyncWS.AsyncWaitHandle.WaitOne();<br />//We return the data bypassing the initial ShowSuppliers Method DataSet MyData = supInfo.EndShowSuppliers(AsyncWS);<br />Notice that just a few more lines of code were added. The only thing that changed was that we added our asynchronous methods right after we instantiated our dll. After this, we create an instance of the IasyncResult object that will let us know when the Web Service process has finished.<br />IAsyncResult AsyncWS = supInfo.BeginShowSuppliers(Catg, null, null);<br />Here, we called the asynchronous BeginShowSuppliers method that accepts our initial dropdown list parameter and two other mandatory arguments that, in this example, were not included, and were substituted with null. The second argument would typically call the AsyncCallBack object responsible for calling another method once the BeginShowSuppliers completes, contrary to our example. The third argument would contain information about the asynchronous operation.<br />We then next implement the AsyncWaitHandle that allows us to incorporate and handle different kinds of synchronization techniques. There are a few AsyncWaitHandles available to us. With the WaitOne method included below, we wait for the WaitHandle to receive a callback signal. Further available methods include: WaitAll(), which waits for all elements to receive a callback signal, and WaitAny(), which waits for any one of the elements to receive a callback signal. Both utilize specified arrays as one of the overloaded element arguments, alongside an Integer for specific time interval waiting, and/or Timespan as well. In any event, all WaitHandles have available to them multiple overload forms that can be further viewed in the .NET SDK documentation.<br />//We wait for the default callback AsyncWS.AsyncWaitHandle.WaitOne();<br />A quick digression regarding the line above: although our WaitOne method as shown in default form will work fine, it can be overloaded. To illustrate, our WaitOne Handler, once overridden in a derived class, will block the current thread until the current WaitHandle receives a signal. The two arguments it allows, paralleling what the other two Wait methods also accept, are:<br />waiting for a set number of milliseconds to pass, and<br />a Boolean value, true or false, specifying whether to exit the synchronization domain before the wait.<br />Once the wait is over, we return our results via the EndShowSuppliers method that got the OK from the WaitHandle.<br />The AsyncWaitHandle method being a resource releaser, OK'd our supInfo.EndShowSuppliers method below, and in turn obtained our data, without letting the rest of our application grow impatient.<br />//We return the data DataSet MyData = supInfo.EndShowSuppliers(AsyncWS);<br />Therefore, in coping with the possible speed limitations resulting from HTTP network traffic, we can implement our Web Service without any concern that the rest of our application will wait impatiently until it’s all completed. With some asynchronous"ity,” our application will run its entire course, in conjunction with our possibly leisurely Web Service, simply jumping in when it's finished.<br />In summing up, our BeginShowSuppliers method, once initialized, returns instantly (though not in this case, as we used the WaitHandler) to notify your applicable callback function that the process is done, and it's OK to call the EndShowSuppliers method and return the results.<br />And there you have it: a quick look at Asynchronous Web Services. As you may have wondered, yes, this can get far more complex than what we’ve discussed. Nevertheless, with the amount you have learned now, it should be a little less intimidating.<br />ConclusionRealizing how fast you can create a nice, functional .NET XML Data Web Service -- and an Asychronous one to boot -– should have put a smile on your face. Additionally, be sure to explore all the .NET documentation for greater detail on what was presented here for additional tweaking, implementing error handling, security, caching, and other aspects you should keep in mind when creating and consuming Web Services. There's plenty of stuff in the .NET documentation and online that goes into more detail about all this.<br />It's really quite easy to create and consume your own Web services, and to discover other available services over the Internet, and to consume and utilize them as if those applications reside on your local server! With each passing moment, .NET reveals itself to be a more truly amazing and extremely powerful platform. Until next time, happy .NETing!Jonhttp://www.blogger.com/profile/10247055052512255066noreply@blogger.com0tag:blogger.com,1999:blog-7064022720417563992.post-77353450677515393662007-12-19T05:54:00.000-08:002007-12-19T05:57:44.226-08:00Creating .NET Web Services Step 3<strong>Step 3 - Build our Object</strong><br />OK, now let's invoke the .NET C# compiler (csc.exe) or VB compiler (vbc.exe) to convert your source file into an assembly or DLL. Create a new .bat file named makelib.bat and type in:<br /><br /><strong>[C#]</strong><br /><br /><span style="color:#33ff33;">csc /t:library /out:bin\GetSuppliers.dll bin\GetSuppliers.cs<br />/reference:System.dll,System.Data.dll,System.Web.dll,<br />System.Web.Services.dll,System.XML.dll /optimize</span><br /><br /><strong>[VB]</strong><br /><br /><span style="color:#33ff33;">vbc /t:library /out:bin\GetSuppliers.dll bin\GetSuppliers.vb<br />/reference:System.dll,System.Data.dll,System.Web.dll,<br />System.Web.Services.dll,System.XML.dll /optimize<br />pause</span><br /><br />All this does is compile the source file from the bin folder to a DLL of set name, to the bin folder.<br />The /t:library instructs the compiler to create a dll (dynamic link library), rather than an exe (executable) file, with /reference: importing the necessary dll's libraries that will be used in our Web service. Finally, we /optimize our dll to produce smaller, faster, and more efficient output.<br /><strong>Step 4 - Put it All Together</strong><br />Now copy and paste the code below to an .aspx .NET page and name it. This code is for the page that will access the assembly/DLL in your bin folder, and with all the Web server controls, pass the appropriate parameters to the Web Service. Go ahead and run it (<a href="http://localhost/Websrvce.aspx">http://<a class="glossary" title=""Localhost" is an alias for the computer system the user is working on. It's also accessible through the 127.0.0.1 address." href="http://www.sitepoint.com/glossary.php?q=L#term_42">localhost</a>/Websrvce.aspx</a>).<br /><br /><span style="color:#ffff00;"><%@ Page Language="C#" Explicit="true" Strict="true" Buffer="true"%> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> <%@ Import Namespace="WService" %><br /><html> <script language="C#" runat="server"><br />void Page_Load(Object sender, EventArgs e) { Response.Flush(); }<br />void SubmitBtn_Click (object src, EventArgs e) {<br /> int RcdCount; string Catg = DropDown1.SelectedItem.Text;<br /> //Instantiate DLL GetInfo supInfo = new GetInfo();<br /> //Pass parameter into DLL function DataSet MyData = supInfo.ShowSuppliers(Catg);<br /> MyDataGrid.DataSource = MyData.Tables[0].DefaultView; MyDataGrid.DataBind(); RcdCount = MyData.Tables[0].Rows.Count; if (RcdCount <= 0) {<br /> Message.InnerHtml = "<b>No results were found for <FONT Color=Red><i>"+ Catg +"</i></font>"; MyDataGrid.Visible = false; //Hide Results until needed<br /> } else {<br /> Message.InnerHtml = "<b><FONT Color=Red><i>" + Catg + "</i></font> has " + RcdCount + " local suppliers</b>"; MyDataGrid.Visible = true; } }<br /></script> <body style="font: 10pt verdana"><br /><h4>Accessing Data with Web Services</h4><br /><form runat="server"><br /><asp:DropDownList id=DropDown1 runat="server"> <asp:ListItem>Australia</asp:ListItem> <asp:ListItem>Brazil</asp:ListItem> <asp:ListItem>Canada</asp:ListItem> <asp:ListItem>Denmark</asp:ListItem> <asp:ListItem>Finland</asp:ListItem> <asp:ListItem>France</asp:ListItem> <asp:ListItem>Germany</asp:ListItem> <asp:ListItem>Italy</asp:ListItem> <asp:ListItem>Japan</asp:ListItem> <asp:ListItem>Netherlands</asp:ListItem> <asp:ListItem>Norway</asp:ListItem> <asp:ListItem>Singapore</asp:ListItem> <asp:ListItem>Spain</asp:ListItem> <asp:ListItem>Sweden</asp:ListItem> <asp:ListItem>UK</asp:ListItem> <asp:ListItem>USA</asp:ListItem> </asp:DropDownList> <asp:button text="Submit" OnClick="SubmitBtn_Click" runat=server/> <p> <span id="Message" runat="server"/><br /><p><br /><ASP:DataGrid id="MyDataGrid" runat="server" AutoGenerateColumns="True" Width="100%" BackColor="White" Border="1" BorderWidth="1" CellPadding="1" CellSpacing="1" Font-Size="10pt" HeaderStyle-BackColor="White" HeaderStyle-ForeColor="Blue" AlternatingItemStyle-BackColor="White" AlternatingItemStyle-ForeColor="Black" ShowFooter="false" /><br /></form><br /></body> </html><br />How It Works<br />Pretty cool, huh? Now, aside from the common data accessing and Web server control usage, I'll outline some specifics. By virtue of creating our proxy class with a namespace in Step 2, we need to import it to the dll we created in Step 3, like this:<br /><%@ Import Namespace="WService" %><br />We then instantiate it or reference our object:[C#]<br />GetInfo supInfo = new GetInfo();<br />[VB]<br />Dim supInfo As New WService.GetInfo()<br />This is our Web Service class. We then retrieve our dropdown list parameter, and pass it to our ShowSuppliers constructor method like so:<br />[C#]string Catg = DropDown1.SelectedItem.Text;<br />DataSet MyData = supInfo.ShowSuppliers(Catg);<br />[VB]<br />Dim Catg As String = DropDown1.SelectedItem.Text<br />Dim MyData As DataSet = supInfo.ShowSuppliers (Catg)<br />And the rest? Just common .NET stuff, which I assume you have some grip on. Nevertheless, it shouldn't be too hard to follow or figure out. The .NET documentation and Quickstart Tutorials will help with plenty more information. Well, guess what? We're done! </span><br /><span style="color:#ffff00;"></span>Jonhttp://www.blogger.com/profile/10247055052512255066noreply@blogger.com0tag:blogger.com,1999:blog-7064022720417563992.post-89275726920666830772007-12-19T05:49:00.000-08:002007-12-19T05:54:06.850-08:00Creating .NET Web Services Step 1 , 2<strong>Aside from your typical data namespace import, you also add the Web Services namespace:</strong><strong><br /></strong><strong><br />using System.Web.Services</strong><br /><strong>In VB this would be:</strong><br />Imports System.Web.ServicesHere I've added the [WebService(Description="My Suppliers List Web Service")], which gives a custom description. Next we create our class, which, in order that it be exposed, and able to inherit the Webservice base class, must be a public class.<br />public class GetInfo : WebService {<br />Now we mark the method that’s to be exposed via the WebMethod attribute. Every class that’s enclosed within a WebMethod will be exposed as a service. Also, I boost performance by setting the BufferResponse to true.<br />[WebMethod (BufferResponse=true)]<br />If you prefer to have the description right below the exposed WebMethod link, you can achieve <strong>it like this in C#:</strong><br />[WebMethod (Description="My Suppliers List Web Service",BufferResponse=true)]<br />The VB version would incorporate the description and BufferResponse in one statement, namely WebMethod, that used angle brackets. This is placed after the class creation and Web service inheriting line, and on the same line with, but before the function, like so:<br /><WebMethod(Description:="My Suppliers List Web Service",BufferResponse:=True)> Public Function ShowSuppliers (ByVal str As String) As DataSet<br />Next, we set up our method or VB function, which will accept a string parameter from our drop down list and pass this to our SQL query (you'll see all this in detail in Step 4). If you're really savvy you can pass this and other parameters with the help of C# structs (scaled down classes) to enumerate your data value types, and provide you with better memory allocation. But for <strong>now, we'll stick to the basics:<br /></strong>public DataSet ShowSuppliers (string str)<br />Here, we set up our dataset method to return us exactly that. Lastly, we perform typical data connection and access and return our results, and we're done! So far so good? After viewing this in your browser, the above code should to start to make sense. Let's go to Step 2.<br /><br /><strong>Step 2 -</strong><br />Consume the Web Service Source FileNext, append ?WSDL to the Web services URI <strong>(Uniform Resource Identifier) like so:</strong><br /><a href="http://localhost/suppliers.asmx?WSDL">http://localhost/suppliers.asmx?WSDL</a><br />“What's this?” you ask. This is the WSDL document that the client will use to access this service.<br />Even so, you don't have to know much about this unreadable code to produce results, which is where the WSDL.exe command-line tool comes into play. Due to the open protocol nature of Web services, this tool enables you to consume non-.NET Web Services as well.<br />You can bypass WSDL and test the XML results instantly through HTTP GET protocol, by <strong>typing the following into your browser:</strong><br /><a href="http://localhost/suppliers.asmx/ShowSuppliers?str=USA">http://localhost/suppliers.asmx/ShowSuppliers?str=USA</a><br />This passes USA as a parameter to the ShowSuppliers class method. Note that if you're using .NET SDK Beta 1.1 (v.1.1.4322), it seems to prefer HTTP POST protocol, so invoke the Web Service through its exposed method link. The XML results? A little crazy, huh?<br />Nevertheless, scroll down a little and you'll see the query results of our class call. Later in Step 4, all this gobbledygook will make much more readable sense.<br />So, to create our proxy class sourcefile, make a batch file named makeWS.bat and type in:<br />[C#] wsdl.exe /l:CS /n:WService /out:bin/GetSuppliers.cs <a href="http://localhost/suppliers.asmx?WSDL">http://localhost/suppliers.asmx?WSDL</a><br /><strong>[VB]<br /></strong>wsdl.exe /l:VB /n:WService /out:bin/GetSuppliers.vb <a href="http://localhost/suppliers.asmx?WSDL">http://localhost/suppliers.asmx?WSDL</a> pause<br />This tells our WSDL tool that /l is the language you’re using.<br />/n: creates the Wservice namespace so you can reference it from your .aspx page, and finally send the C#/VB source file to the bin folder from which we'll create the dll assembly that we’ll<br /><br /><strong>use in Step 3.</strong><br />Also add pause, so after this is all said and done, you'll be prompted to press any key to continue, and more importantly, you’ll know for sure that it all went according to plan.<br />Now locate your new batch file, and double-click on it to run it. Once you’ve done this, you will have created, rather consumed, the proxy class or source file GetSuppliers.cs right from the .asmx file. Have a look in your bin folder.<br />Note that you could run these commands via the command-line prompt, but for the sake of convenience, I prefer the good old' batch file. You may be wondering where the phrase “consuming” came from? In this regard, it simply refers to the presentation of the Web Service to the "consumer”.Jonhttp://www.blogger.com/profile/10247055052512255066noreply@blogger.com0tag:blogger.com,1999:blog-7064022720417563992.post-50310378544660284182007-12-19T05:46:00.000-08:002007-12-19T05:49:08.823-08:00Create the Web ServiceFirst we’ll create the Web service function or method that'll you'll call (or “expose”) over the Internet as you would any object-oriented class. The difference is that we’ll have to incorporate and import all the necessary Web Services namespaces, syntax and attributes, as well as our data namespaces, in this case. As this article uses C#, any important differences regarding VB will be shown as well.<br /><br />So go ahead and copy the code below to a file called suppliers.asmx. Save it to your Inetpub/wwwroot folder, and then run it in your browser using http://localhost/suppliers.asmx. What you'll see is a list of the Web Service Descriptions, including the Web service name and the exposed method.<br /><br />By clicking the exposed method link, you'll be presented with the three main protocols that are available for your use. Just so you know, the file with the .asmx extension is the actual Web Service file that enables the ASP.NET runtime to return all pertinent exposed Web service methods and information.<br /><br /><span style="color:#ffff00;"><%@ WebService Language="C#" Class="GetInfo" %><br /><br />using System;<br />using System.Data;<br />using System.Data.SqlClient;<br />using System.Web.Services;<br /><br />[WebService(Description="My Suppliers List Web Service")]<br /><br />public class GetInfo : WebService<br />{<br /><br />[WebMethod(BufferResponse=true)]<br /><br />public DataSet ShowSuppliers (string str)<br />{<br /><br />SqlConnection dbConnection = new SqlConnection("server=(local);<br />uid=sa;pwd=;database=Northwind;");<br /><br />SqlDataAdapter objCommand = new SqlDataAdapter("select<br />ContactName, CompanyName, City, Phone from Suppliers<br />where Country = '" + str + "' order by ContactName<br />asc", dbConnection);<br /><br />DataSet DS = new DataSet();<br /><br />objCommand.Fill(DS);<br /><br />return DS;<br /><br />dbConnection.Close();<br />dbConnection = null;<br /><br />}<br /><br />}<br /></span><br />The <span style="color:#ffff33;"><%@ WebService Language="C#" Class="GetInfo" %></span> directive sets up the file as a Web Service, gives it a name and specifies the language it uses.Jonhttp://www.blogger.com/profile/10247055052512255066noreply@blogger.com0tag:blogger.com,1999:blog-7064022720417563992.post-62567931146305375162007-12-19T05:35:00.000-08:002007-12-19T05:39:21.138-08:00Creating and Consuming .NET Web Services in 5 Easy StepsThe Internet has a new player on the scene. It’s been surrounded by a great deal of hype -- and even some television commercials! Apparently, this new, "next generation technology" will <strong>change the way business is done on the Web. It seems that soon, companies, their</strong> applications or software, and any Internet-enabled devices will easily be able to communicate with, and provide services to, one another regardless of platform or language. Sounds revolutionary!<br />So, what exactly is it that will open these boundless lines of communication? Web Services, that's what!<br /><strong>Web services give developers the ability to utilize four open Web standards: </strong><br /><strong><br />HTTP -</strong> Hypertext Transfer ProtocolThe standard protocol used over Port 80, which traverses firewalls, and is responsible for requesting and transmitting data over the Internet.<br /><strong>SOAP -</strong> Simple Object Access Protocol An XML-inherent protocol that encloses a set of rules for data description and process. As a standard, this is the center-piece that complements the other three standards mentioned here.<br /><strong>XML -</strong> Extensible Markup LanguageThe most common markup language in which all this information is written.<br /><br /><strong>WSDL -</strong> Web Services Description LanguageAn XML-based method used to identify Web Services and their access at runtime. .NET provides a tool called WSDL.exe, which essentially makes it quite easy to generate an XML Web service as an XML file. This contains all the methods and instructions the Web Service has, and typically uses SOAP as its default.<br />This article will see you create and consume a data-driven .NET XML Web service in 5 quick and easy steps!<br />I’ll assume that you have a decent grasp of common .NET data access, Web server controls, such a datagrid, and some object-oriented programming concepts. If not, don't worry too much. If you complete the examples, and view the results, you should have no difficulty in keeping up and observing the causes and effects of what this tutorial entails.<br />Prior to .NET, there were other alternatives that could be used to access a Web service, such as Microsoft's MSXML component, which enabled you to communicate with the given Web Service over HTTP POST. However, this process, while acceptable, is just not .NET.<br />Ok, let’s begin!Jonhttp://www.blogger.com/profile/10247055052512255066noreply@blogger.com0