<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Eduzine© - Web Services</title>
    <link>http://eduzine.edujini-labs.com/</link>
    <description>Articles from Edujini Team</description>
    <dc:language>en</dc:language>
    <admin:errorReportsTo rdf:resource="mailto:" />
    <generator>Serendipity 0.8.2 - http://www.s9y.org/</generator>
    <pubDate>Sat, 30 Jun 2007 08:04:45 GMT</pubDate>

    <image>
        <url>http://www.edujini-labs.com/images/newmasthead.gif</url>
        <title>RSS: Eduzine© - Web Services - Articles from Edujini Team</title>
        <link>http://eduzine.edujini-labs.com/</link>
        <width></width>
        <height></height>
    </image>
<item>
    <title>Web Service Specifications</title>
    <link>http://eduzine.edujini-labs.com/archives/25-Web-Service-Specifications.html</link>
<category>Web Services</category>    <comments>http://eduzine.edujini-labs.com/archives/25-Web-Service-Specifications.html#comments</comments>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=25</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=2.0&amp;type=comments&amp;cid=25</wfw:commentRss>
    <author>eduzine@edujinionline.com (Eduzine)</author>
    <content:encoded>

&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;
This article enlists the various specifications related to web services. The list covers both the first generation specifications as well as second generation specifications.
&lt;/p&gt;

&lt;p&gt;
The article also provides hyperlinks to the specifications and their maintainers.
&lt;/p&gt;


 
&lt;h2&gt;1&lt;sup&gt;st&lt;/sup&gt; Generation Specifications&lt;/h2&gt;

&lt;p&gt;
The web-service framework by W3C consists of a foundation built on three core XML-based specifications: WSDL, SOAP, and UDDI. The standards, in conjunction with SO-Design Principles, form a basic XML-based web-service driven SOA.
&lt;/p&gt;

&lt;p&gt;
The 1&lt;sup&gt;st&lt;/sup&gt; generation architecture allows for the creation of independent web-services. It has several limitations addressed in 2&lt;sup&gt;nd&lt;/sup&gt; generation specifications.
&lt;/p&gt;

&lt;p&gt;
&lt;b&gt;Simple Object Acccess Protocol&lt;/b&gt;: Establishes a standard message format that consists of an XML document capable of hosting RPC and document-centric data.
&lt;/p&gt;&lt;ul&gt;
  &lt;li&gt;SOAP v1.1: Maintained by W3C. Specification is available &lt;a href=&quot;http://www.w3.org/TR/2000/NOTE-SOAP-20000508/&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;

  &lt;li&gt;SOAP v1.2: Maintained by W3C. Specification is divided in four parts - &lt;a href=&quot;http://www.w3.org/TR/soap12-part0/&quot;&gt;Primer&lt;/a&gt;, &lt;a href=&quot;http://www.w3.org/TR/soap12-part1/&quot;&gt;Messaging&lt;/a&gt;, &lt;a href=&quot;http://www.w3.org/TR/soap12-part2/&quot;&gt;Adjuncts&lt;/a&gt; and &lt;a href=&quot;http://www.w3.org/TR/soap12-part3/&quot;&gt;Assertions and Test Collection&lt;/a&gt;
&lt;/li&gt;

&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
&lt;b&gt;Web Service Description Language&lt;/b&gt;: Providing the foremost language for the description of Web service definitions.
&lt;/p&gt;&lt;ul&gt;
  &lt;li&gt;WSDL v1.1: Mantained by W3C. Specification available &lt;a href=&quot;http://www.w3.org/TR/wsdl&quot;&gt;here&lt;/a&gt;
  &lt;/li&gt;&lt;li&gt; WSDL v1.2: Maintained by W3C. Specification available in two parts - &lt;a href=&quot;http://www.w3.org/TR/wsdl20/&quot;&gt;Core Language&lt;/a&gt; and &lt;a href=&quot;http://www.w3.org/TR/wsdl20-patterns/&quot;&gt;Message Patterns&lt;/a&gt;.
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;


&lt;/p&gt;&lt;h2&gt;2&lt;sup&gt;nd&lt;/sup&gt; Generation Specifications&lt;/h2&gt;

&lt;p&gt;
The 2&lt;sup&gt;nd&lt;/sup&gt; generation specifications position SOA as a viable successor to the prior distributed-platforms.
&lt;/p&gt;

&lt;p&gt;
&lt;b&gt;Reliability and Messaging&lt;/b&gt;: Propose features that deal with reliabile delivery, self-governing messaging, message attachments, and message transmission performance.
&lt;/p&gt;&lt;ul&gt;
  &lt;li&gt;WS-ReliableMessaging: Available at &lt;a href=&quot;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnglobspec/html/wsrmspecindex.asp&quot;&gt;MSDN&lt;/a&gt; and &lt;a href=&quot;http://www-128.ibm.com/developerworks/webservices/library/specification/ws-rm/&quot;&gt;DeveloperWorks&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;WS-Addressing: Available at &lt;a href=&quot;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnglobspec/html/wsmsgspecindex.asp&quot;&gt;MSDN&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;MTOM, DIME: Available at &lt;a href=&quot;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnglobspec/html/wsmsgspecindex.asp&quot;&gt;MSDN&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;MTOM and XOP: Available at &lt;a href=&quot;http://www.w3.org/2000/xp/Group/&quot;&gt;W3C&lt;/a&gt; &lt;/li&gt;
   &lt;li&gt;WS-Attachments: Available at &lt;a href=&quot;http://www-128.ibm.com/developerworks/library/specification/ws-attach/&quot;&gt;DeveloperWorks&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;

&lt;p&gt;
&lt;b&gt;Policies and Metadata&lt;/b&gt;: The WS-Policy framework comprises of a set of specifications that allow for the description of policies like business-rules, security etc
&lt;/p&gt;&lt;ul&gt;
 &lt;li&gt;WS-Policy: Available at &lt;a href=&quot;http://schemas.xmlsoap.org/ws/2004/09/policy&quot;&gt;XML-SOAP.org&lt;/a&gt;, and a newer proposed version at &lt;a href=&quot;http://www.w3.org/Submission/WS-Policy/&quot;&gt;W3C&lt;/a&gt;. Also available at &lt;a href=&quot;http://www-128.ibm.com/developerworks/library/specification/ws-polfram/&quot;&gt;DeveloperWorks&lt;/a&gt; &lt;/li&gt;
 &lt;li&gt;WS-PolicyAssertions: Available at &lt;a href=&quot;http://www.ibm.com/developerworks/library/specification/ws-polas/&quot;&gt;DeveloperWorks&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;WS-MetadatExchange: Aavailable at &lt;a href=&quot;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnglobspec/html/wsmetaspecindex.asp&quot;&gt;MSDN&lt;/a&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
&lt;b&gt;Security&lt;/b&gt;: The WS-Security framework provides a thorough security model consisting of a host of specifications
&lt;/p&gt;&lt;ul&gt;
 &lt;li&gt;WS-Security: Maintained by &lt;a href=&quot;http://www.oasis-open.org/committees/wss&quot;&gt;OASIS&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;WS-SecureConversation, WS-Federation, WS-Trust: All maintained by &lt;a href=&quot;http://www.oasis-open.org/specs/&quot;&gt;OASIS&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;XML Encryption, XML Signature, XKMS, XACML, SAML: Maintained by &lt;a href=&quot;http://www.w3.org/Consortium/siteindex.html#X&quot;&gt;W3C&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;WS-I Basic Security Profile: Maintained by &lt;a href=&quot;http://www.ws-i.org/deliverables/workinggroup.aspx?wg=basicsecurity&quot;&gt;WS-I&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;
&lt;b&gt;Context and Transaction Management&lt;/b&gt;: The WS-Coordination specification provides a context management system. Supports atomic and long-running transactions.
&lt;/p&gt;&lt;ul&gt;
 &lt;li&gt;WS-Coordination: Maintained by &lt;a href=&quot;http://docs.oasis-open.org/ws-tx/wscoor/2006/06/&quot;&gt;OASIS&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;WS-Transaction: Maintained by &lt;a href=&quot;http://www.oasis-open.org/committees/ws-tx/&quot;&gt;OASIS&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;WS-AtomicTransaction: Maintained by &lt;a href=&quot;http://docs.oasis-open.org/ws-tx/wsat/2006/06&quot;&gt;OASIS&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;WS-BusinessActivity: Maintained by &lt;a href=&quot;http://docs.oasis-open.org/ws-tx/wsba/2006/06&quot;&gt;OASIS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
&lt;b&gt;Business Process Definitions&lt;/b&gt;: Provides support for workflow - orchestration and choreography.
&lt;/p&gt;&lt;ul&gt;
 &lt;li&gt;BPEL: Maintained by &lt;a href=&quot;http://docs.oasis-open.org/wsbpel/2.0/wsbpel-v2.0.pdf&quot;&gt;OASIS&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;WSCI: Maintained by &lt;a href=&quot;http://www.w3.org/TR/wsci/&quot;&gt;W3C&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;BPML: Maintained by &lt;a href=&quot;http://www.bpmi.org/&quot;&gt;BPMI&lt;/a&gt; (Note that there are not many takers for BPML. BPEL has a wider acceptance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt; &lt;/p&gt;
    </content:encoded>
    <pubDate>Sat, 30 Jun 2007 00:08:27 -0700</pubDate>
    <guid isPermaLink="false">http://eduzine.edujini-labs.com/archives/25-guid.html</guid>
    </item>
<item>
    <title>Exploring Windows Communication Foundation - Part 2</title>
    <link>http://eduzine.edujini-labs.com/archives/22-Exploring-Windows-Communication-Foundation-Part-2.html</link>
<category>SOA</category><category>Web Services</category><category>.Net</category><category>WCF</category>    <comments>http://eduzine.edujini-labs.com/archives/22-Exploring-Windows-Communication-Foundation-Part-2.html#comments</comments>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=22</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=2.0&amp;type=comments&amp;cid=22</wfw:commentRss>
    <author>eduzine@edujinionline.com (Eduzine)</author>
    <content:encoded>

&lt;p&gt;
In our second article of the series &amp;quot;Exploring Windows Communication Foundation&amp;quot;, we explore the customization of
the service and working with faults and errors. Specifically, we look at the following:
&lt;/p&gt;&lt;ul&gt;
  &lt;li&gt;Hosting the service in IIS/ASP.Net Runtime&lt;/li&gt;
  &lt;li&gt;Customizing the details of a service contract, like the name of contract, namespace-URI to which it belongs etc&lt;/li&gt;
  &lt;li&gt;Customizing the details of an operation contract, like the name of contract, it's parameters, order etc&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;h2&gt;Downloads&lt;/h2&gt;
&lt;p&gt;The code for the project is available for download at &lt;a href=&quot;http://downloads.edujini-labs.com&quot;&gt;Edujini Downloads&lt;/a&gt; in the &lt;a href=&quot;http://www.edujini-labs.com/pafiledb/index.php?act=category&amp;id=6&quot;&gt;Windows Communication Foundation&lt;/a&gt; category.

&lt;/p&gt;
 
&lt;h2&gt;Hosting WCF Service in IIS/ASP.Net&lt;/h2&gt;

&lt;p&gt;
To host a service in IIS/ASP.Net, we need to do the following:
&lt;/p&gt;&lt;ol&gt;
  &lt;li&gt;Install IIS, if not already installed.&lt;/li&gt;
  &lt;li&gt;Register ASP.Net 2.0 with IIS, if not already registered.&lt;/li&gt;
  &lt;li&gt;Register WCF with IIS and ASP.Net 2.0.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
If you have installed IIS and .Net Framework 2.0 Redistributable in this order, you do not need to register ASP.Net Runtime.
You can check if ASP.Net Runtime is registered with a website or not by checking the properties of the website as shown below:
&lt;/p&gt;

&lt;img border=&quot;1&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/dotNet/wcf/edujini_wcf_scart_02_iis_01.jpg&quot; alt=&quot;iis website properties&quot; title=&quot;iis website properties&quot; /&gt;
&lt;p&gt; &lt;/p&gt;
&lt;img border=&quot;1&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/dotNet/wcf/edujini_wcf_scart_02_iis_02.jpg&quot; alt=&quot;iis asp.net runtime&quot; title=&quot;iis asp.net runtime&quot; /&gt;

&lt;p&gt;
If the ASP.Net Runtime is not registered with IIS, execute the following on the commandline for the registration:
&lt;/p&gt;

&lt;pre&gt;%windir%\Microsoft.Net\Framework\v2.0.50727\aspnet_regiis.exe -i
&lt;/pre&gt;

&lt;p&gt;
To register the WCF with IIS and ASP.Net 2.0, execute the following on the commandline:
&lt;/p&gt;

&lt;pre&gt;ServiceModelReg.exe -i -x
&lt;/pre&gt;

&lt;p&gt;
The application &lt;code&gt;ServiceModelReg.exe&lt;/code&gt; can be found in the folder
&lt;code&gt;&amp;quot;%windir%\Microsoft.Net\Framework\v3.0\Windows Communication Foundation&amp;quot;&lt;/code&gt;.
The &lt;code&gt;-i&lt;/code&gt; option is for registering WCF with IIS and ASP.Net Runtime and &lt;code&gt;-x&lt;/code&gt; option is to execute the
custom action scripts also. The two important things that the registration does are registering &lt;code&gt;.svc&lt;/code&gt; extension
with IIS asking it to be handled by ASP.Net 2.0 Runtime and the registering &lt;code&gt;.svc&lt;/code&gt; extension with the ASP.Net
Runtime to be handled by its &lt;code&gt;IHttpHandler&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
The next step is to create an ASP.Net Website. Let's call it &lt;code&gt;ShoppingCart&lt;/code&gt;.
To the website created, add a new WCF service and name
it &lt;code&gt;ShoppingCartService.svc&lt;/code&gt;.
&lt;/p&gt;

&lt;img border=&quot;1&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/dotNet/wcf/edujini_wcf_scart_02_website_svc_01.jpg&quot; title=&quot;adding wcf service&quot; alt=&quot;adding wcf service&quot; /&gt;

&lt;p&gt;
Incase you do not find the template for adding a new WCF service, don't be disheartened. You can simply add a new text file
and name it &lt;code&gt;ShoppingCartService.svc&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Open the &lt;code&gt;ShoppingCartService.svc&lt;/code&gt; file if not already opened. Modify it to have the following contents:
&lt;/p&gt;

&lt;pre&gt;&amp;lt;%@ ServiceHost Debug=&amp;quot;true&amp;quot; Service=&amp;quot;ShoppingCartLibrary.ShoppingCartImpl&amp;quot; %&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
Create the folder &lt;code&gt;Bin&lt;/code&gt; inside your project. Add the assembly &lt;code&gt;ShoppingCartLibrary&lt;/code&gt; that we created
in our previous article. If you don't have it, you can get it from
&lt;a href=&quot;http://eduzine.edujinionline.com/archives/21-Exploring-Windows-Communication-Foundation-Part-1.html&quot;&gt;the previous article&lt;/a&gt;.
For all those working with Visual Studio, you may wish to delete the class &lt;code&gt;ShoppingCartService&lt;/code&gt; created
automatically for the code-behind, placed in &lt;code&gt;App_Code&lt;/code&gt; folder. We don't need it.
&lt;/p&gt;

&lt;p&gt;
Modify the configuration file &lt;code&gt;web.config&lt;/code&gt; to include the following content:
&lt;/p&gt;

&lt;pre&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;
&amp;lt;configuration&amp;gt;
    &amp;lt;system.serviceModel&amp;gt;
        &amp;lt;behaviors&amp;gt;
            &amp;lt;serviceBehaviors&amp;gt;
                &amp;lt;behavior name=&amp;quot;HttpGetBehaviour&amp;quot;&amp;gt;
                    &amp;lt;serviceMetadata httpGetEnabled=&amp;quot;true&amp;quot;/&amp;gt;
                &amp;lt;/behavior&amp;gt;
            &amp;lt;/serviceBehaviors&amp;gt;
        &amp;lt;/behaviors&amp;gt;
        &amp;lt;services&amp;gt;
            &amp;lt;service name=&amp;quot;ShoppingCartLibrary.ShoppingCartImpl&amp;quot;
                behaviorConfiguration=&amp;quot;HttpGetBehaviour&amp;quot;&amp;gt;
                &amp;lt;endpoint binding=&amp;quot;mexHttpBinding&amp;quot;
                    contract=&amp;quot;ShoppingCartLibrary.IShoppingCartService&amp;quot; address=&amp;quot;&amp;quot;/&amp;gt;
            &amp;lt;/service&amp;gt;
        &amp;lt;/services&amp;gt;
    &amp;lt;/system.serviceModel&amp;gt;
&amp;lt;/configuration&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
Hurray! The service has been deployed. Browse to the location &lt;code&gt;http://localhost/ShoppingCart/ShoppingCartService.svc&lt;/code&gt;.
If you see the output as shown below, the scriptmaps are not registered appropriately.
&lt;/p&gt;

&lt;img border=&quot;1&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/dotNet/wcf/edujini_wcf_scart_02_website_svc_02.jpg&quot; alt=&quot;uncompiled output&quot; title=&quot;uncompiled output&quot; /&gt;

&lt;p&gt;
In that case (or uncompiled output), execute the following on the commandline:
&lt;/p&gt;

&lt;pre&gt;ServiceModelReg.exe -s:W3SVC/1/ROOT/ShoppingCart
&lt;/pre&gt;

&lt;p&gt;
Refresh the page in browser. Now, you should be able to see an output as shown below:
&lt;/p&gt;

&lt;img border=&quot;1&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/dotNet/wcf/edujini_wcf_scart_02_website_svc_03.jpg&quot; alt=&quot;service output&quot; title=&quot;service output&quot; /&gt;

&lt;h2&gt;Updating the client&lt;/h2&gt;
&lt;p&gt;
The next step is to update the client (proxy class and configuration) to connect to our new service.
&lt;/p&gt;

&lt;p&gt;
Ah! We don't need to regenerate everything. Open the client application configuration file and modify the endpoint-address
(in the section &lt;code&gt;configuration/system.serviceModel/client/endpoint&lt;/code&gt;, the attribute &lt;code&gt;address&lt;/code&gt;) with
a value of &lt;code&gt;http://localhost/ShoppingCart/ShoppingCartService.svc&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
The client should give identical results as what we got while working with self-hosted service (created in previous article).
&lt;/p&gt;

&lt;h2&gt;Service Customization&lt;/h2&gt;

&lt;p&gt;
Let us now look at important aspect of decoupling the WCF contract names and .Net names (data-types and/or parameters).
&lt;/p&gt;

&lt;p&gt;
In general, we do not want to have dependency on the field/parameter/data-type names that we choose in .Net and
what we publish to the world. Not only it may put under risk the application but also may be mandatorily required.
Say, for example, if we need to have a parameter by the name &lt;code&gt;in&lt;/code&gt; or &lt;code&gt;for&lt;/code&gt;, we cannot have it
because these are keywords in C# (technically speaking, yes we can have it in C# but what about C++.Net or VB.Net?).
As such, we would like to remove this interdependency.
&lt;/p&gt;
&lt;br /&gt;
&lt;h3&gt;Service Contract Name&lt;/h3&gt;
&lt;p&gt;
The first requirement that we look at it isolating the service name and the namespace-URI to which it belongs, and
the name of the interface.
&lt;/p&gt;

&lt;p&gt;
The &lt;code&gt;ServiceContractAttribute&lt;/code&gt; has two properties - &lt;code&gt;Name&lt;/code&gt; and &lt;code&gt;Namespace&lt;/code&gt; that can
be used to control this. The default of values of the two are the name of the interface and &lt;code&gt;http://www.tempuri.org&lt;/code&gt;.
Let us change them to &lt;code&gt;Shopping-Cart-Service&lt;/code&gt; and &lt;code&gt;http://www.edujinionline.com/ns/wcf/tutorial/scart&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Update the interface &lt;code&gt;IShoppingCartService&lt;/code&gt; to as given below (code in bold are the changes done):
&lt;/p&gt;

&lt;pre lang=&quot;cs&quot;&gt;using System;
using System.ServiceModel;

namespace ShoppingCartLibrary
{
    &lt;b&gt;[ServiceContract(Name=&amp;quot;Shopping-Cart-Service&amp;quot;,
        Namespace=&amp;quot;http://www.edujinionline.com/ns/wcf/tutorial/scart&amp;quot;)]&lt;/b&gt;
    public interface IShoppingCartService
    {
        [OperationContract]
        bool CheckUserExists(string username);

        [OperationContract]
        DateTime? GetLastTransactionTime(string username);
    }
}
&lt;/pre&gt;

&lt;p&gt;
Starting the hosting application that we created in the previous article.
Browse to the location &lt;code&gt;http://localhost:8080/ShoppingCartService?wsdl&lt;/code&gt;. You will notice that the WSDL
generated is conspicuously short and has reference to another WSDL. Browse to
&lt;code&gt;http://localhost:8080/ShoppingCartService?wsdl=wsdl0&lt;/code&gt;. You will notice that all definitions of types,
messages and operations (in portTypes section) now belong to the new namespace-URI that we gave.
&lt;/p&gt;

&lt;p&gt;
Also notice that the new name of the portType is now &lt;code&gt;Shopping-Cart-Service&lt;/code&gt; instead of &lt;code&gt;IShoppingCart&lt;/code&gt;.
Note that portType section is the one that defines the service-contract (operations and related messages). Also the bindings
are now also from the type &lt;code&gt;Shopping-Cart-Service&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
However, if we need to change the name of the service (in service section of WSDL) and the namespace-URI of the same, we
need to change the service-behaviour rather than the contract details.
The default value of the same are the name of the implementation class and http://tempuri.org.
Let us update them to &lt;code&gt;Shopping-Cart-Impl&lt;/code&gt; and
&lt;code&gt;http://www.edujinionline.com/ns/wcf/tutorial/scart/impl&lt;/code&gt; respectively.
&lt;/p&gt;

&lt;p&gt;
We shall make use of the &lt;code&gt;System.ServiceModel.ServiceBehaviorAttribute&lt;/code&gt; to specify the name and namespace-uri
of the service.
&lt;/p&gt;

&lt;p&gt;
Update the class &lt;code&gt;ShoppingCartImpl&lt;/code&gt; to as given below (code in bold are the changes done):
&lt;/p&gt;

&lt;pre lang=&quot;cs&quot;&gt;using System;
using System.ServiceModel;

namespace ShoppingCartLibrary
{
    &lt;b&gt;[ServiceBehavior(Name=&amp;quot;Shopping-Cart-Impl&amp;quot;,
        Namespace=&amp;quot;http://www.edujinionline.com/ns/wcf/tutorials/scart/impl&amp;quot;)]&lt;/b&gt;
    public class ShoppingCartImpl : IShoppingCartService
    {
        //Other code not shown
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;h3&gt;Operation Names&lt;/h3&gt;

&lt;p&gt;
Similarly, to change the value of the operation, one can make use of &lt;code&gt;Name&lt;/code&gt; property of
&lt;code&gt;System.ServiceModel.OperationContractAttribute&lt;/code&gt;. Let us update the name of the operations from their default
names to &lt;code&gt;UserExists&lt;code&gt; and &lt;code&gt;LastTransactionTime&lt;/code&gt; respectively.
Update the interface &lt;code&gt;IShoppingCartService&lt;/code&gt; to as shown below:
&lt;/code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;pre lang=&quot;cs&quot;&gt;using System;
using System.ServiceModel;

namespace ShoppingCartLibrary
{
    [ServiceContract(Name=&amp;quot;Shopping-Cart-Service&amp;quot;,
        Namespace=&amp;quot;http://www.edujinionline.com/ns/wcf/tutorial/scart&amp;quot;)]
    public interface IShoppingCartService
    {
        &lt;b&gt;[OperationContract(Name=&amp;quot;UserExists&amp;quot;)]&lt;/b&gt;
        bool CheckUserExists(string username);

        &lt;b&gt;[OperationContract(Name=&amp;quot;LastTransactionTime&amp;quot;)]&lt;/b&gt;
        DateTime? GetLastTransactionTime(string username);
    }
}
&lt;/pre&gt;

&lt;h3&gt;Action URIs for input and output messages&lt;/h3&gt;

&lt;p&gt;
Launch the hosting application and browse to &lt;code&gt;http://localhost:8080/ShoppingCartService?wsdl=wsdl0&lt;/code&gt;.
Look at the updated operation names. However, the &lt;code&gt;Action&lt;/code&gt; of input and output
messages doesn't look too good. Let us update them to
&lt;code&gt;http://www.edujinionline.com/wcf/tutorials/scart/actions/UserExists&lt;/code&gt; and
&lt;code&gt;http://www.edujinionline.com/wcf/tutorials/scart/actions/LastTransactionTime&lt;/code&gt; (input), and
&lt;code&gt;http://www.edujinionline.com/wcf/tutorials/scart/actions/UserExistsOut&lt;/code&gt; and
&lt;code&gt;http://www.edujinionline.com/wcf/tutorials/scart/actions/LastTransactionTimeOut&lt;/code&gt; (output) respectively.
&lt;/p&gt;

&lt;p&gt;
The properties &lt;code&gt;Action&lt;/code&gt; and &lt;code&gt;ReplyAction&lt;/code&gt; may be used to customize the action-URI for
the input and output operations.
Again, make changes to the interface as shown below (code in bold are the changes done):
&lt;/p&gt;

&lt;pre lang=&quot;cs&quot;&gt;using System;
using System.ServiceModel;

namespace ShoppingCartLibrary
{
    [ServiceContract(Name=&amp;quot;Shopping-Cart-Service&amp;quot;,
        Namespace=&amp;quot;http://www.edujinionline.com/ns/wcf/tutorial/scart&amp;quot;)]
    public interface IShoppingCartService
    {
        [OperationContract(Name=&amp;quot;UserExists&amp;quot;,
            &lt;b&gt;Action=&amp;quot;http://www.edujinionline.com/wcf/tutorials/scart/actions/UserExists&amp;quot;,
            ReplyAction=&amp;quot;http://www.edujinionline.com/wcf/tutorials/scart/actions/UserExistsOut&amp;quot;&lt;/b&gt;)]
        bool CheckUserExists(string username);

        [OperationContract(Name=&amp;quot;LastTransactionTime&amp;quot;,
            &lt;b&gt;Action=&amp;quot;http://www.edujinionline.com/wcf/tutorials/scart/actions/LastTranactionTime&amp;quot;,
            ReplyAction=&amp;quot;http://www.edujinionline.com/wcf/tutorials/scart/actions/LastTranactionTimeOut&amp;quot;&lt;/b&gt;)]
        DateTime? GetLastTransactionTime(string username);
    }
}&lt;/pre&gt;

&lt;p&gt;
Similarly, the order in which the operations should appear in the WSDL can be defined by setting the property
&lt;code&gt;Order&lt;/code&gt; of the &lt;code&gt;System.ServiceModel.OperationContractAttribute&lt;/code&gt; appropriately.
By default, the WCF engine would show the operations in the order it retrieves from the IL (using reflection).
&lt;/p&gt;

&lt;h3&gt;Parameter Names&lt;/h3&gt;

&lt;p&gt;
Let us say that our shopping cart works with email address as far the interface to the world is concerned.
Internally, we would like to refer to it as username, like we have been doing so far.
&lt;/p&gt;

&lt;p&gt;
&lt;code&gt;System.ServiceModel.MessageParameterAttribute&lt;/code&gt; can be used to customize the name of the input parameters
as well as that of the output paramter in the response.
Update the code to look as follows (code in bold shows the changes made):
&lt;/p&gt;

&lt;pre lang=&quot;cs&quot;&gt;using System;
using System.ServiceModel;

namespace ShoppingCartLibrary
{
    [ServiceContract(Name=&amp;quot;Shopping-Cart-Service&amp;quot;,
        Namespace=&amp;quot;http://www.edujinionline.com/ns/wcf/tutorial/scart&amp;quot;)]
    public interface IShoppingCartService
    {
        [OperationContract(Name=&amp;quot;UserExists&amp;quot;,
            Action=&amp;quot;http://www.edujinionline.com/wcf/tutorials/scart/actions/UserExists&amp;quot;,
            ReplyAction=&amp;quot;http://www.edujinionline.com/wcf/tutorials/scart/actions/UserExistsOut&amp;quot;)]
        &lt;b&gt;[return: MessageParameter(Name=&amp;quot;ExistsInfo&amp;quot;)]&lt;/b&gt;
        bool CheckUserExists(
            &lt;b&gt;[MessageParameter(Name=&amp;quot;email&amp;quot;)]&lt;/b&gt; string username);

        [OperationContract(Name=&amp;quot;LastTransactionTime&amp;quot;,
            Action=&amp;quot;http://www.edujinionline.com/wcf/tutorials/scart/actions/LastTranactionTime&amp;quot;,
            ReplyAction=&amp;quot;http://www.edujinionline.com/wcf/tutorials/scart/actions/LastTranactionTimeOut&amp;quot;)]
        &lt;b&gt;[return: MessageParameter(Name=&amp;quot;TimeInfo&amp;quot;)]&lt;/b&gt;
        DateTime? GetLastTransactionTime(
            &lt;b&gt;[MessageParameter(Name=&amp;quot;email&amp;quot;)]&lt;/b&gt; string username);
    }
}&lt;/pre&gt;

&lt;p&gt;
With all these changes, we need to regenerate the proxy-client (using &lt;code&gt;svcutil&lt;/code&gt;). You will notice that the
default class file generated this time is &lt;code&gt;Shopping-Cart-Service.cs&lt;/code&gt;, which happens to be the
name of our service!
&lt;/p&gt;

&lt;p&gt;
Now, before proceeding ahead with any transaction, let us enable tracing to have a look at the message being transported.
Update the application configuration file for the host to have the following entries:
&lt;/p&gt;

&lt;pre&gt;&amp;lt;configuration&amp;gt;
    &amp;lt;system.diagnostics&amp;gt;
        &amp;lt;sources&amp;gt;
            &amp;lt;source name=&amp;quot;System.ServiceModel.MessageLogging&amp;quot;
                switchValue=&amp;quot;Verbose&amp;quot;&amp;gt;
                &amp;lt;listeners&amp;gt;
                    &amp;lt;add name=&amp;quot;xml&amp;quot;
                    type=&amp;quot;System.Diagnostics.XmlWriterTraceListener&amp;quot;
                    initializeData=&amp;quot;..\..\..\wcf_scart.svclog&amp;quot; /&amp;gt;
                &amp;lt;/listeners&amp;gt;
            &amp;lt;/source&amp;gt;
        &amp;lt;/sources&amp;gt;
        &amp;lt;trace autoflush=&amp;quot;true&amp;quot; /&amp;gt;
    &amp;lt;/system.diagnostics&amp;gt;

    &amp;lt;system.serviceModel&amp;gt;
        &amp;lt;diagnostics&amp;gt;
            &amp;lt;messageLogging logEntireMessage=&amp;quot;true&amp;quot; maxMessagesToLog=&amp;quot;300&amp;quot;
                   logMessagesAtServiceLevel=&amp;quot;false&amp;quot;
                   logMalformedMessages=&amp;quot;true&amp;quot;
                   logMessagesAtTransportLevel=&amp;quot;true&amp;quot; /&amp;gt;
        &amp;lt;/diagnostics&amp;gt;
        &amp;lt; ... &amp;gt;
    &amp;lt;/system.ServiceModel&amp;gt;
&amp;lt;/configuration&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
Update the client application to as shown below (code in bold are the updates done):
&lt;/p&gt;

&lt;pre lang=&quot;cs&quot;&gt;using System;

namespace ShoppingCartConsumer
{
    public class MainClass
    {
        public static void Main(string[] args)
        {
            ShoppingCartServiceClient client = new ShoppingCartServiceClient();

            string[] users = new string[] { &amp;quot;gvaish&amp;quot;, &amp;quot;edujini&amp;quot;, &amp;quot;other&amp;quot; };

            foreach(string user in users)
            {
                Console.WriteLine(&amp;quot;User: {0}&amp;quot;, user);
                Console.WriteLine(&amp;quot;\tExists:           {0}&amp;quot;, client.&lt;b&gt;UserExists&lt;/b&gt;(user));
                DateTime? time = client.&lt;b&gt;LastTransactionTime&lt;/b&gt;(user);
                if(time.HasValue)
                {
                    Console.WriteLine(&amp;quot;\tLast Transaction: {0}&amp;quot;, time.Value);
                } else
                {
                    Console.WriteLine(&amp;quot;\tNever transacted&amp;quot;);
                }
            }

            Console.WriteLine();
        }
    }
}&lt;/pre&gt;

&lt;p&gt;
Notice that there no longer exists the methods &lt;code&gt;CheckUserExists&lt;/code&gt; and/or &lt;code&gt;GetLastTransactionTime&lt;/code&gt;
in the proxy-client generated.
&lt;/p&gt;

&lt;p&gt;
Launch the &lt;code&gt;Service Trace Viewer&lt;/code&gt;, the application &lt;code&gt;SvcTraceViewer.exe&lt;/code&gt; found in the &lt;code&gt;bin&lt;/code&gt;
where the &lt;code&gt;Windows SDK for Windows Vista and .Net Framework 3.0 Runtime Components&lt;/code&gt; was installed.
Open the file &lt;code&gt;wcf_scart.svclog&lt;/code&gt; generated. Notice the important changes in the request sent and response received.
&lt;/p&gt;

&lt;img width=&quot;444&quot; height=&quot;150&quot; border=&quot;1&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/dotNet/wcf/edujini_wcf_scart_02_trace_viewer_01.jpg&quot; alt=&quot;input message&quot; title=&quot;input message&quot; /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;img width=&quot;444&quot; height=&quot;150&quot; border=&quot;1&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/dotNet/wcf/edujini_wcf_scart_02_trace_viewer_02.jpg&quot; alt=&quot;output message&quot; title=&quot;output message&quot; /&gt;

&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;
We looked at how to host the service in IIS/ASP.Net. We also looked at how we can isolate the .Net parameter and operation paramter
names. That's it for now. We would discuss about the faults and error-handling in WCF in the next article.
&lt;/p&gt;

    </content:encoded>
    <pubDate>Tue, 23 Jan 2007 12:47:34 -0700</pubDate>
    <guid isPermaLink="false">http://eduzine.edujini-labs.com/archives/22-guid.html</guid>
    </item>
<item>
    <title>Exploring Windows Communication Foundation - Part 1</title>
    <link>http://eduzine.edujini-labs.com/archives/21-Exploring-Windows-Communication-Foundation-Part-1.html</link>
<category>Web Services</category><category>.Net</category><category>WCF</category>    <comments>http://eduzine.edujini-labs.com/archives/21-Exploring-Windows-Communication-Foundation-Part-1.html#comments</comments>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=21</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=2.0&amp;type=comments&amp;cid=21</wfw:commentRss>
    <author>eduzine@edujinionline.com (Eduzine)</author>
    <content:encoded>

&lt;p&gt;
Starting with this article, we shall explore various aspects of WCF.
&lt;/p&gt;

&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;
Microsoft .Net Framework 3.0 introduces, among other components, Windows Communication Foundation or simply, WCF. The framework
allows us, the development community, to build more service-oriented application. It incorporates several Web Service related
specifications, mostly driven by W3C and OASIS consortiums. I will just list a few of them:
&lt;/p&gt;&lt;ol&gt;
 &lt;li&gt;SOAP 1.1, 1.2 with Basic Profile 1.1&lt;/li&gt;
 &lt;li&gt;WSDL 1.1&lt;/li&gt;
 &lt;li&gt;MTOM&lt;/li&gt;
 &lt;li&gt;WS Policy and WS Policy Attachments&lt;/li&gt;
 &lt;li&gt;WS Metadata Exchange&lt;/li&gt;
 &lt;li&gt;WSS SOAP Message Security 1.0, 1.1&lt;/li&gt;
 &lt;li&gt;WSS SOAP Message Security Username Token Profile 1.0, 1.1&lt;/li&gt;
 &lt;li&gt;WSS SOAP Message Security X.509 Token Profile 1.0, 1.1&lt;/li&gt;
 &lt;li&gt;WS Addressing 2005/08&lt;/li&gt;
 &lt;li&gt;WSS SOAP Message Security Kerberos Token Profile 1.1&lt;/li&gt;
 &lt;li&gt;WS Secure Conversation&lt;/li&gt;
 &lt;li&gt;WS Reliable Messaging&lt;/li&gt;
 &lt;li&gt;WS Coordination&lt;/li&gt;
 &lt;li&gt;WS Atomic Transaction&lt;/li&gt;
 &lt;li&gt;WS Federation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
Starting with this article, let us tour various key aspects of WCF.
&lt;/p&gt;

&lt;h2&gt;Downloads&lt;/h2&gt;
&lt;p&gt;The code for the project is available for download at &lt;a href=&quot;http://downloads.edujini-labs.com&quot;&gt;Edujini Downloads&lt;/a&gt; in the &lt;a href=&quot;http://downloads.edujini-labs.com/index.php?act=category&amp;id=6&quot;&gt;Windows Communication Foundation&lt;/a&gt; category.
&lt;/p&gt;

 
&lt;h2&gt;Case Study&lt;/h2&gt;

&lt;p&gt;
We shall take a simple shopping cart as a case-study. We start with simple data-types and slowly build on to work
with custom, more complex data-types. In the sequence of articles, we shall explore various key aspects of WCF.
The minimum features that I wish to explore in the series are:
&lt;/p&gt;&lt;ul&gt;
 &lt;li&gt;Publishing WCF Service&lt;/li&gt;
 &lt;li&gt;Writing WCF Client&lt;/li&gt;
 &lt;li&gt;Customising the operation contract details, say decoupling the .Net and contract names or pushing part
 of the content in &lt;code&gt;Headers&lt;/code&gt; of the Soap-&lt;code&gt;Envelope&lt;/code&gt;
 &lt;/li&gt;
 &lt;li&gt;Working with faults and errors&lt;/li&gt;
 &lt;li&gt;Working with custom data-types&lt;/li&gt;
 &lt;li&gt;Working with generic data in operations&lt;/li&gt;
 &lt;li&gt;Working with interface-types in operations&lt;/li&gt;
 &lt;li&gt;Working with collections in operations&lt;/li&gt;
 &lt;li&gt;Working with large data in operations&lt;/li&gt;
 &lt;li&gt;Working with sessions and transactions&lt;/li&gt;
&lt;/ul&gt;
Yeah.. it's a long list, but I'll try to fulfil my promise. No, all the articles are not ready right now.
Will keep posting as and when ready, and also update this article with references to them.
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
Ok.. so, let's start!
&lt;/p&gt;

&lt;p&gt;
We will need the following items to work with WCF:
&lt;/p&gt;&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.microsoft.com/downloads/details.aspx?familyid=0856eacb-4362-4b0d-8edd-aab15c5e04f5&amp;displaylang=en&quot;&gt;Microsoft .Net Framework 2.0 Redistributable&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.microsoft.com/downloads/details.aspx?familyid=fe6f2099-b7b4-4f47-a244-c96d69c35dec&amp;displaylang=en&quot;&gt;Microsoft .Net Framework 2.0 SDK&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.microsoft.com/downloads/details.aspx?FamilyId=10CC340B-F857-4A14-83F5-25634C3BF043&amp;displaylang=en&quot;&gt;Microsoft .Net Framework 3.0 Redistributable&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.microsoft.com/downloads/details.aspx?FamilyId=C2B1E300-F358-4523-B479-F53D234CDCCF&amp;displaylang=en&quot;&gt;Microsoft Windows SDK for Windows Vista and .Net Framework 3.0 Runtime Components&lt;/a&gt;
              You may download the complete image &lt;a href=&quot;http://download.microsoft.com/download/1/b/3/1b3f749d-e215-482c-a004-5d9c26c75c92/6.0.6000.0.0.WindowsSDK_Vista_rtm.DVD.Rel.img&quot;&gt;here&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;If you are working with Visual Studio, download the &lt;a href=&quot;http://www.microsoft.com/downloads/details.aspx?FamilyId=F54F5537-CC86-4BF5-AE44-F5A1E805680D&amp;displaylang=en&quot;&gt;Visual Studio Extensions&lt;/a&gt;
&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;

&lt;/p&gt;&lt;h2&gt;Service Definition&lt;/h2&gt;

&lt;p&gt;
Our shopping-cart service, to begin with, publishes the following operations:
&lt;/p&gt;

&lt;pre lang=&quot;cs&quot;&gt;bool      CheckUserExists(string username);
DateTime? GetLastTransactionTime(string username);
&lt;/pre&gt;

&lt;p&gt;
The job of the first operation is to check whether or not the user is registered in our database or not.
The second operation returns the date and time of last transaction done by the last user, if any. Yes, you note
the operation correctly, the return type is not &lt;code&gt;System.DateTime&lt;/code&gt; but &lt;code&gt;System.DateTime?&lt;/code&gt;,
the C# syntax for &lt;code&gt;System.Nullable&amp;lt;System.DateTime&amp;gt;&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
To publish any service in WCF, we require four steps in general:
&lt;/p&gt;&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;#Step1&quot;&gt;Service contract definition&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#Step2&quot;&gt;Contract implementation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#Step3&quot;&gt;Service configuration&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#Step4&quot;&gt;Service hosting&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;

&lt;/p&gt;&lt;h2&gt;&lt;a name=&quot;Step1&quot;&gt;Service Contract Definition&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;
In WCF, service contract is the term used for the final service being published. Note that a service may have one or more related
operations, referred to as operation contracts in WCF.
&lt;/p&gt;

&lt;p&gt;
If you are working in Visual Studio, create a new project of type &amp;quot;Class Library&amp;quot;. Yes, you read it right, it is
&amp;quot;Class Library&amp;quot; and &lt;i&gt;not&lt;/i&gt; &amp;quot;WCF Service Library&amp;quot;.
&lt;/p&gt;

&lt;p&gt;
We start by creating an interface &lt;code&gt;IShoppingCartService&lt;/code&gt; as follows:
&lt;/p&gt;

&lt;pre lang=&quot;cs&quot;&gt;using DateTime;

namespace ShoppingCartLibrary
{
    public interface IShoppingCartService
    {
        bool CheckUserExists(string username);

        DateTime? GetLastTransactionTime(string username);
    }
}
&lt;/pre&gt;

&lt;h2&gt;&lt;a name=&quot;Step2&quot;&gt;Contract Implementation&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;
The next obvious step is to provide implementation to the service. We create a class &lt;code&gt;ShoppingCartImpl&lt;/code&gt;
that implements the interface &lt;code&gt;IShoppingCartService&lt;/code&gt;.
&lt;/p&gt;

&lt;pre lang=&quot;cs&quot;&gt;using DateTime;

namespace ShoppingCartLibrary
{
    public class ShoppingCartImpl : IShoppingCartService
    {
        public bool CheckUserExists(string username)
        {
            if(username == &amp;quot;gvaish&amp;quot; || username == &amp;quot;edujini&amp;quot;)
            {
                return true;
            }
            return false;
        }

        public DateTime? GetLastTransactionTime(string username)
        {
            if(username == &amp;quot;gvaish&amp;quot;)
            {
                return DateTime.Now.AddDays(-3);
            }
            if(username == &amp;quot;edujini&amp;quot;)
            {
                return DateTime.Now.AddHours(-3);
            }
            return null;
        }
    }
}
&lt;/pre&gt;

&lt;h2&gt;&lt;a name=&quot;Step3&quot;&gt;Service Configuration&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;
We need configuration at two levels:
&lt;/p&gt;&lt;ol&gt;
  &lt;li&gt;Using attributes, we need to tell WCF about the &lt;a href=&quot;#config1&quot;&gt;service
     contract and operation contracts&lt;/a&gt;. The information would be used to define service, operations, messages and types&lt;/li&gt;
  &lt;li&gt;Using configuration entries, we need to tell WCF about the &lt;a href=&quot;#config2&quot;&gt;implementation class to be
     used and binding details&lt;/a&gt;. These details would be used for hosting purpose.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;

&lt;/p&gt;&lt;h3&gt;&lt;a name=&quot;config1&quot;&gt;Contract Configuration&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;
If you are using Visual Studio, add a reference to the assembly &lt;code&gt;System.ServiceModel.dll&lt;/code&gt; from GAC.
Add the attribute &lt;code&gt;System.ServiceModel.ServiceContractAttribute&lt;/code&gt; to the interface. It tells the WCF that
there is a service associated with the corresponding type.
Add the attribute &lt;code&gt;System.ServiceModel.OperationContractAttribute&lt;/code&gt; to the methods in the interface. It informs the
WCF about the operations to be published in the service. It will take care of messages and types associated on its own.
&lt;/p&gt;

&lt;p&gt;
So, our final code looks as follows:
&lt;/p&gt;

&lt;pre lang=&quot;cs&quot;&gt;using DateTime;
using ServiceModel;

namespace ShoppingCartLibrary
{
    [ServiceContract]
    public interface IShoppingCartService
    {
        [OperationContract]
        bool CheckUserExists(string username);

        [OperationContract]
        DateTime? GetLastTransactionTime(string username);
    }
}
&lt;/pre&gt;

&lt;h3&gt;&lt;a name=&quot;config2&quot;&gt;Service Configuration&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;
We shall provide these details to our &lt;a href=&quot;#Step4&quot;&gt;hosting application&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
Compile the files to the assembly. I name it &lt;code&gt;ShoppingCartLibrary.dll&lt;/code&gt;. If you are compiling
the code at the commandline, do not forget to add reference to &lt;code&gt;System.ServiceModel.dll&lt;/code&gt;.
&lt;/p&gt;

&lt;h2&gt;&lt;a name=&quot;Step4&quot;&gt;Service Hosting&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;
Having defined our service completely, we need a runtime (engine) to host the service - an application that can allow
the clients to connect and invoke the operations. For this, we shall create a console application. The application
has just one class, &lt;code&gt;MainClass&lt;/code&gt;, with the &lt;code&gt;Main&lt;/code&gt; method.
&lt;/p&gt;

&lt;p&gt;
For Visual Studio users, we name the project as &lt;code&gt;ShoppingCartHost&lt;/code&gt;. Rename the class
&lt;code&gt;Program&lt;/code&gt; to &lt;code&gt;MainClass&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Add reference to &lt;code&gt;System.ServiceModel.dll&lt;/code&gt; and to the &lt;code&gt;ShoppingCartLibrary.dll&lt;/code&gt;
Write the following code to the &lt;code&gt;MainClass&lt;/code&gt;.
&lt;/p&gt;

&lt;pre&gt;using System;
using System.ServiceModel;

using ShoppingCartLibrary;

namespace ShoppingCartHost
{
    public class MainClass
    {
        public static void Main(string[] args)
        {
            Uri uri = new Uri(&amp;quot;http://localhost:8080/ShoppingCartService&amp;quot;);

            using(ServiceHost host = new ServiceHost(typeof(ShoppingCartImpl), uri))
            {
                host.Open();

                Console.Write(&amp;quot;Hit &amp;lt;enter&amp;gt; to stop service...&amp;quot;);
                Console.ReadLine();
            }
        }
    }
}
&lt;/pre&gt;

&lt;p&gt;
Now, we need the service configuration as mentioned &lt;a href=&quot;#config2&quot;&gt;earlier&lt;/a&gt;.
Write the following code to the application configuration file.
&lt;/p&gt;

&lt;pre lang=&quot;xml&quot;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; ?&amp;gt;
&amp;lt;configuration&amp;gt;
    &amp;lt;system.serviceModel&amp;gt;
        &amp;lt;behaviors&amp;gt;
            &amp;lt;serviceBehaviors&amp;gt;
                &amp;lt;behavior name=&amp;quot;HttpGetBehaviour&amp;quot;&amp;gt;
                    &amp;lt;serviceMetadata httpGetEnabled=&amp;quot;true&amp;quot;/&amp;gt;
                &amp;lt;/behavior&amp;gt;
            &amp;lt;/serviceBehaviors&amp;gt;
        &amp;lt;/behaviors&amp;gt;
        &amp;lt;services&amp;gt;
            &amp;lt;service name=&amp;quot;ShoppingCartLibrary.ShoppingCartImpl&amp;quot;
                behaviorConfiguration=&amp;quot;HttpGetBehaviour&amp;quot;&amp;gt;
                &amp;lt;endpoint binding=&amp;quot;mexHttpBinding&amp;quot;
                    contract=&amp;quot;ShoppingCartLibrary.IShoppingCartService&amp;quot; address=&amp;quot;&amp;quot;/&amp;gt;
            &amp;lt;/service&amp;gt;
        &amp;lt;/services&amp;gt;
    &amp;lt;/system.serviceModel&amp;gt;
&amp;lt;/configuration&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
Compile your code. Start the console application. You should see your server up and running.
&lt;/p&gt;

&lt;img border=&quot;1&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/dotNet/wcf/host_application.jpg&quot; title=&quot;host application&quot; alt=&quot;host application&quot; /&gt;

&lt;p&gt;
Browse to the location &lt;code&gt;http://localhost:8080/ShoppingCartService&lt;/code&gt;.
&lt;/p&gt;

&lt;img border=&quot;1&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/dotNet/wcf/browse_location.jpg&quot; title=&quot;browse location&quot; alt=&quot;browse location&quot; /&gt;

&lt;p&gt;
Hurray! We are ready with our first service. Let's now design a client to consume the service.
&lt;/p&gt;

&lt;h2&gt;Client Application&lt;/h2&gt;
&lt;p&gt;
For our client, we need two items: the proxy client code and the configuration items. No no, you don't write any of them.
You can generate them using the WCF tool &lt;code&gt;svcutil.exe&lt;/code&gt;. You can locate this tool in the folder where your Visual Studio
IDE is installed (default location being %PROGRAMFILES%\Microsoft Visual Studio 8\Common7\IDE) or where you install
the .Net 3.0 SDK is installed (default location being %PROGRAMFILES%\Micrsofot Windows SDK\v6.0\bin).
&lt;/p&gt;

&lt;p&gt;
Ensure that the location to &lt;code&gt;svcutil.exe&lt;/code&gt; is in your path. Invoke the following at commandline.
&lt;/p&gt;

&lt;pre&gt;svcutil.exe /nologo /config:App.config http://localhost:8080/ShoppingCartService?wsdl
&lt;/pre&gt;

&lt;p&gt;
It will generate two files: &lt;code&gt;ShoppingCartImpl.cs&lt;/code&gt; and &lt;code&gt;App.config&lt;/code&gt;. We just need a &lt;code&gt;MainClass&lt;/code&gt;
with &lt;code&gt;Main&lt;/code&gt; method on the client side to consume the service published. Write the following code to the class:
&lt;/p&gt;

&lt;pre lang=&quot;cs&quot;&gt;using System;

namespace ShoppingCartConsumer
{
    public class MainClass
    {
        public static void Main(string[] args)
        {
            ShoppingCartServiceClient client = new ShoppingCartServiceClient();

            string[] users = new string[] { &amp;quot;gvaish&amp;quot;, &amp;quot;edujini&amp;quot;, &amp;quot;other&amp;quot; };

            foreach(string user in users)
            {
                Console.WriteLine(&amp;quot;User: {0}&amp;quot;, user);
                Console.WriteLine(&amp;quot;\tExists:           {0}&amp;quot;, client.CheckUserExists(user));
                DateTime? time = client.GetLastTransactionTime(user);
                if(time.HasValue)
                {
                    Console.WriteLine(&amp;quot;\tLast Transaction: {0}&amp;quot;, time.Value);
                } else
                {
                    Console.WriteLine(&amp;quot;\tNever transacted&amp;quot;);
                }
            }

            Console.WriteLine();
        }
    }
}
&lt;/pre&gt;

&lt;p&gt;
Don't forget to add reference to &lt;code&gt;System.ServiceModel.dll&lt;/code&gt;. Build your project.
Execute the client. You should get an output similar to shown below:
&lt;/p&gt;

&lt;img border=&quot;1&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/dotNet/wcf/client_application.jpg&quot; title=&quot;client application&quot; alt=&quot;client application&quot; /&gt;

&lt;p&gt;
Note that this is only a start... so, please have a little patience if you are looking for advanced topics.
&lt;img src=&quot;http://us.i1.yimg.com/us.yimg.com/i/mesg/emoticons7/1.gif&quot; alt=&quot;:)&quot; title=&quot;:)&quot; /&gt;
&lt;/p&gt;

&lt;h2&gt;Notes&lt;/h2&gt;
&lt;p&gt;
We chose to have an interface as our service contract. In general, we can have a class directly as a service contract.
However, it is always a good idea to have an interface and then provide an implementation. In this way, we can keep and
maintain the declaration of the contract and implementation of the contract independently and modularly.
&lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;
&lt;p&gt;
With WCF, it is possible to publish and consume web services in a very simple way. Although publishing a web service
is not as simple as in ASP.Net. However, as may be seemingly noticeable, the WCF may turn out to be much more flexible
than ASP.Net service. One of the flexibilities that we saw was to host it outside ASP.Net Runtime.
&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;
    </content:encoded>
    <pubDate>Mon, 22 Jan 2007 21:00:21 -0700</pubDate>
    <guid isPermaLink="false">http://eduzine.edujini-labs.com/archives/21-guid.html</guid>
    </item>
<item>
    <title>HOWTO: Web Service Transactions</title>
    <link>http://eduzine.edujini-labs.com/archives/11-HOWTO-Web-Service-Transactions.html</link>
<category>Web Services</category>    <comments>http://eduzine.edujini-labs.com/archives/11-HOWTO-Web-Service-Transactions.html#comments</comments>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=11</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=2.0&amp;type=comments&amp;cid=11</wfw:commentRss>
    <author>eduzine@edujinionline.com (Eduzine)</author>
    <content:encoded>

&lt;p class=&quot;question&quot;&gt;
  How do I access two separate methods of same class publishing multiple operations in a webservice with the state being maintained?
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
  The answer to this question, put in the newsgroup, is making use of transaction techniques. What you are trying to say is that I would like to have operations being done successfully to indicate that my job is done.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 Strictly speaking, the problem does not make a concrete sense in the realm of web services since multiple operations at an end-point may or may not be implemented by a single class. So, let me rephrase the problem so that it becomes technically correct w.r.t. Web Services.
&lt;/p&gt;
 
&lt;p class=&quot;question&quot;&gt;
 How to do I share information across two operations in one or more web services?
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 There are multiple ways in which this can be achieved. For extreme cases, you may want to look into the WS-Transactions &lt;a target=&quot;_edujini_window&quot; href=&quot;http://www-128.ibm.com/developerworks/library/specification/ws-tx/&quot;&gt;Web Services Transactions Specification @IBM&lt;/a&gt;
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;

 For simple cases as the original query above, one may want to use simple techniques of server side caching.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 Let us assume that there are two classes involved in the complete transaction. One is WebService and another is InternalData. Let us also say that WebService class publishes two operations PerformTaskOne and PerformTaskTwo. And also that execution of PerformTaskTwo require some information of PerformTaskOne, and PerformTaskOne is to return DataOne.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 What we do is a simple trick. Along with DataOne, we also return a Token when PerformTaskOne is executed. On the server side, we cache DataOne and InternalData with the key as Token. Note that the Token has to be generated randomly and must be unique for each visit to PerformTaskOne.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 For PerformTaskTwo, apart from other inputs may be required, we also ask another parameter as Token.

&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 In PerformTaskTwo, before starting execution, we rebuilt InternalData and DataOne using the Token from the cache.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 Now that we have rebuilt the previous state, we can go ahead and complete our PerformTaskTwo.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 We have put a small working demo at &lt;a href=&quot;http://www.codeproject.com/useritems/edujini_stateful_ws.asp&quot; target=&quot;_edujinionlnie_nw&quot;&gt;CodeProject&lt;/a&gt;. You may download the code and play with it. Please note that if the article gets approved, the URL may change. Please do vote for the article if you like it.
&lt;/p&gt;
    </content:encoded>
    <pubDate>Mon, 09 Oct 2006 00:01:00 -0700</pubDate>
    <guid isPermaLink="false">http://eduzine.edujini-labs.com/archives/11-guid.html</guid>
    </item>
<item>
    <title>&quot;405 - Method Not Allowed&quot; error with ASP.Net based Web Service</title>
    <link>http://eduzine.edujini-labs.com/archives/10-405-Method-Not-Allowed-error-with-ASP.Net-based-Web-Service.html</link>
<category>Web Services</category>    <comments>http://eduzine.edujini-labs.com/archives/10-405-Method-Not-Allowed-error-with-ASP.Net-based-Web-Service.html#comments</comments>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=10</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=2.0&amp;type=comments&amp;cid=10</wfw:commentRss>
    <author>eduzine@edujinionline.com (Eduzine)</author>
    <content:encoded>

&lt;p class=&quot;question&quot;&gt;
 I get a 405 error while working with ASP.Net based web service. The request synopsis is:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;POST / HTTP/1.0
Host: my.machine.host.name
Content-Type: text/xml
Content-Length: NNNN
...&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p class=&quot;answer&quot;&gt;
 The problem is not anywhere else but with the request itself. To be able to appreciate the solution, one must understand the HTTP specifications.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 1.0 version of HTTP does not specify any 'Host' header. It was introducted in 1.1. One needs to change the request to look something like:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;POST http://my.machine.host.name/ HTTP/1.0
Content-Type: text/xml
Content-Length: NNNN
...&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt; 
&lt;p class=&quot;answer&quot;&gt;
 Or one may simply update the request to reflect &amp;quot;HTTP/1.1&amp;quot; instead of &amp;quot;HTTP/1.0&amp;quot;.
&lt;/p&gt;
    </content:encoded>
    <pubDate>Sun, 08 Oct 2006 00:01:00 -0700</pubDate>
    <guid isPermaLink="false">http://eduzine.edujini-labs.com/archives/10-guid.html</guid>
    </item>
<item>
    <title>Web Services in ASP.Net: HTTP-POST vs. HTTP-SOAP</title>
    <link>http://eduzine.edujini-labs.com/archives/9-Web-Services-in-ASP.Net-HTTP-POST-vs.-HTTP-SOAP.html</link>
<category>Web Services</category>    <comments>http://eduzine.edujini-labs.com/archives/9-Web-Services-in-ASP.Net-HTTP-POST-vs.-HTTP-SOAP.html#comments</comments>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=9</wfw:comment>
    <slash:comments>4</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=2.0&amp;type=comments&amp;cid=9</wfw:commentRss>
    <author>eduzine@edujinionline.com (Eduzine)</author>
    <content:encoded>

&lt;p class=&quot;question&quot;&gt;
 What is HTTP SOAP and how does it differ from HTTP POST as far as Web Services in ASP.Net are concerned?
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 To get an answer to the question, one must first have an understanding of the HTTP Protocol - how does it work.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 HTTP Protocol allows, among other methods, two most widely methods - GET and POST. You may consider them as the commands given to the server to perform specific tasks.
&lt;/p&gt;
 
&lt;p class=&quot;answer&quot;&gt;
 Associated with every command given by the client is a set of headers that follows the command and optionally some data that is sent for further parsing. This data can be username and password using which you logon to your favourite webmail or it can be the contents of the file that you upload.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 When you go to a website by typing a URL in the browser, the browser sends a GET command to the server. A sample data sent by the browser to the server may be:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
GET / HTTP/1.1
Host: http://www.edujinionline.com
Connection: close
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p class=&quot;answer&quot;&gt;
 GET command consists of just two parts -- a line containing the command and optionally a set of headers following thereafter.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 Similar to GET is the command POST. POST command has three parts -- a line containing the command, a set of headers and data to be sent to the server. A sample POST command may look like:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
POST /SomePage HTTP/1.1
Host: http://www.edujinionline.com
Content-Type: application/x-www-url-encoded
Content-Length: 33
Connection: close

username=edujini&amp;amp;password=online
&lt;/code&gt;&lt;/pre&gt;
OR
&lt;pre&gt;&lt;code&gt;
POST /SomePage HTTP/1.1
Host: http://www.edujinionline.com
Content-Type: multipart/form-data;
      boundary=--EduJiniOnlineBndry
Content-Length: &lt;i&gt;Some-Length&lt;/i&gt;

Connection: close

--EduJiniOnlineBndry
&lt;i&gt;Some Data&lt;/i&gt;
--EduJiniOnlineBndry--
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p class=&quot;answer&quot;&gt;
 For the server to be able to parse the contents after the headers correctly, one must send at least two headers &lt;code&gt;Content-Length&lt;/code&gt; indicating the number of bytes of the content (after headers) and &lt;code&gt;Content-Type&lt;/code&gt; providing the type of the content.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 When you submit a form, the content-type would generally by &lt;code&gt;application/x-www-url-encoded&lt;/code&gt; and when you upload a file it must be &lt;code&gt;multipart/form-data&lt;/code&gt;
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 When one works with SOAP-based Web Services on HTTP Protocol, the &lt;code&gt;Content-Type&lt;/code&gt; must be &lt;code&gt;text/xml&lt;/code&gt; and nothing else.

&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 Enabling HTTP-POST for the Web Services means that one can connect to a URL like &lt;code&gt;http://www.edujinionline.com/WebService.asmx?op=Op1&lt;/code&gt;, submit the form (automatically generated by the engine) and get the results back (in XML format).
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 Enabling HTTP-SOAP for the Web Services means that one can connect to the URL (&lt;code&gt;http://www.edujinionline.com/WebService.asmx&lt;/code&gt;) using the POST method and using the content type as 'text/xml' and providing the content (after headers) as the SOAP-Message and expect a SOAP-Message in response.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;

 Still unable to figure the what's the difference between HTTP-POST and HTTP-SOAP... drop in a comment and we shall get back to you.
&lt;/p&gt;
    </content:encoded>
    <pubDate>Sat, 07 Oct 2006 00:01:00 -0700</pubDate>
    <guid isPermaLink="false">http://eduzine.edujini-labs.com/archives/9-guid.html</guid>
    </item>
<item>
    <title>Java, PHP and .Net: Web Services, SOA and InterOP</title>
    <link>http://eduzine.edujini-labs.com/archives/8-Java,-PHP-and-.Net-Web-Services,-SOA-and-InterOP.html</link>
<category>Web Services</category>    <comments>http://eduzine.edujini-labs.com/archives/8-Java,-PHP-and-.Net-Web-Services,-SOA-and-InterOP.html#comments</comments>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=8</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=2.0&amp;type=comments&amp;cid=8</wfw:commentRss>
    <author>eduzine@edujinionline.com (Eduzine)</author>
    <content:encoded>

&lt;p class=&quot;question&quot;&gt;
 How does the interoperability of Web Services between Java, PHP and .Net fare?
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 In this entry and may be a couple more to follow, I plan to bring out how the three leading web-platforms fare when it comes to Web Services. Few questions, not exhaustive by any means, that would be of interest may be:
&lt;/p&gt;&lt;ul&gt;
 &lt;li&gt;What level of support is available in individual platform?&lt;/li&gt;
 &lt;li&gt;How good is individual platform when it comes to all standards and specifications around WebServices?&lt;/li&gt;
 &lt;li&gt;How good is individual platform when it comes to inter-operability with others?&lt;/li&gt;
 &lt;li&gt;What resources are available in terms of bundled libraries, additional libraries, 3rd party tools and libraries and documentation / tutorials thereof?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;/p&gt; 
&lt;p class=&quot;answer&quot;&gt; &lt;/p&gt;
&lt;p class=&quot;answer&quot;&gt;
 Ok.. as I continue writing further, I have changed my mind. No further discussion in this entry. I will create new entries to address individual topic.
&lt;/p&gt;
    </content:encoded>
    <pubDate>Fri, 06 Oct 2006 00:21:00 -0700</pubDate>
    <guid isPermaLink="false">http://eduzine.edujini-labs.com/archives/8-guid.html</guid>
    </item>
<item>
    <title>HOWTO: Using Arrays in WebServices</title>
    <link>http://eduzine.edujini-labs.com/archives/7-HOWTO-Using-Arrays-in-WebServices.html</link>
<category>Web Services</category>    <comments>http://eduzine.edujini-labs.com/archives/7-HOWTO-Using-Arrays-in-WebServices.html#comments</comments>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=7</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=2.0&amp;type=comments&amp;cid=7</wfw:commentRss>
    <author>eduzine@edujinionline.com (Eduzine)</author>
    <content:encoded>

&lt;p class=&quot;question&quot;&gt;
 How do I use arrays in a Web Service?
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 Probably one of the more frequently asked questions regarding web services. I thought I will answer this prior to starting my discussion on comparing platforms.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 Attempting to answer this question from the perspective of all three major enterprise platforms...
&lt;/p&gt;
 
&lt;ul&gt;
&lt;li&gt;ASP.Net:
&lt;p&gt;Using from ASP.Net based Web Services, or for that matter, even using &lt;code&gt;SOAPFormatter&lt;/code&gt; in .Net Remoting is simple. There are two ways to achieve it.&lt;/p&gt;
&lt;p&gt;1. If you need an array of data as one of the parameters to the method, you can apply the attributes &lt;code&gt;XmlArrayAttribute&lt;/code&gt; and &lt;code&gt;XmlArrayItemAttribute&lt;/code&gt; to the parameter configuring the name of the element.&lt;/p&gt;
&lt;p&gt;2. If you need to pass a parameter whose type is not primitive, you should again look at the attributes in &lt;code&gt;System.Xml.Serialization&lt;/code&gt; namespace on how you can serialize the class in the way that you want it to...&lt;/p&gt; 

&lt;/li&gt;

&lt;li&gt;PHP:
&lt;p&gt;Probably the simplest and the toughest of all three. Toughest because in PHP one has to first generate the WSDL by hand.
&lt;/p&gt;
&lt;p&gt;On the server side one doesn't need to do anything... can treat any parameter as an array. For the client to be able to work perflectly fine, one needs to generate appropriate WSDL. That's it. An example of the generated WSDL may be (data-type):&lt;/p&gt;&lt;pre&gt;&lt;code&gt;  &amp;lt;element name='userNames'&amp;gt;
    &amp;lt;complexType&amp;gt;
      &amp;lt;sequence&amp;gt;
        &amp;lt;element name='name' type='xsd:string'
           minOccurs='1' maxOccurs='unbounded' /&amp;gt;
      &amp;lt;/sequence&amp;gt;
    &amp;lt;/complexType&amp;gt;
  &amp;lt;/element&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
 One good example of how dynamic-structure can be useful in PHP is &lt;a href=&quot;http://msdn.microsoft.com/library/en-us/dnmapnet30/html/MWS_PHPLoc.asp&quot; target=&quot;_blank&quot;&gt;using PHP to access MapPoint Services&lt;/a&gt;.
&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;Java using Axis:
&lt;p&gt;Again, a very simple implementation though one would need to have a look into the WSDD file.&lt;/p&gt;
&lt;p&gt;Looking into the &lt;a href=&quot;http://ws.apache.org/axis/java/user-guide.html&quot; target=&quot;_blank&quot;&gt;User Guide&lt;/a&gt; of Axis, the &lt;code&gt;arrayMapping&lt;/code&gt; element can be used to maximize returns.&lt;/p&gt;
&lt;p&gt;On the page search for the topic of '&lt;code&gt;Deploying array mappings - the &amp;lt;arrayMapping&amp;gt; tag&lt;/code&gt;'... or just find for the word '&lt;code&gt;arrayMapping&lt;/code&gt;'. I am quoting the example here for completeness:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  &amp;lt;arrayMapping qname='ns:&lt;i&gt;ArrayOfMyDataType&lt;/i&gt;' xmlns:ns='&lt;i&gt;uri&lt;/i&gt;'
    languageSpecificType='java:&lt;i&gt;f.q.t.MyDataType&lt;/i&gt;[]'
    innerType='ns2:&lt;i&gt;MyDataType&lt;/i&gt;' xmlns:ns2='&lt;i&gt;uri2&lt;/i&gt;'
    encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;f.q.n&lt;/code&gt;: stands for fully qualified name.&lt;/p&gt;

&lt;p&gt;The reference for the element can be found &lt;a href=&quot;http://ws.apache.org/axis/java/reference.html&quot;&gt;here&lt;/a&gt;.

&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;    </content:encoded>
    <pubDate>Thu, 05 Oct 2006 17:40:35 -0700</pubDate>
    <guid isPermaLink="false">http://eduzine.edujini-labs.com/archives/7-guid.html</guid>
    </item>
<item>
    <title>HOWTO: Transfer Files using Web Services</title>
    <link>http://eduzine.edujini-labs.com/archives/6-HOWTO-Transfer-Files-using-Web-Services.html</link>
<category>Web Services</category>    <comments>http://eduzine.edujini-labs.com/archives/6-HOWTO-Transfer-Files-using-Web-Services.html#comments</comments>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=6</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=2.0&amp;type=comments&amp;cid=6</wfw:commentRss>
    <author>eduzine@edujinionline.com (Eduzine)</author>
    <content:encoded>

&lt;p class=&quot;question&quot;&gt;
 How to transfer files using Web Services?
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 There are actually multiple ways of doing so.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;

 The first, simplest approach, is to send the contents of the file as a raw-string parameter. In case, the file content is binary, do not forget to base64 encode it.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 The advantage of this approach is that you don't need to download any extra features / extensions / add-ons for any Web Service engine that you are using, be it on .Net, Java, PHP or whatever.
&lt;/p&gt;
 
&lt;p class=&quot;answer&quot;&gt;
 The disadvantage is that all manipulation needs to be done manually. What more, metadata like filename etc needs to be passed as a few more parameters... all manipulation to be done manually.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 The other option is to use MIME or DIME (now, superseded by MTOM) attachments. For .Net based webservices, one would need to download &amp;quot;Web Service Enhancements (WSE)&amp;quot;. WSE 2.0 is for .Net 1.1 and WSE 3.0 is for .Net 2.0. Take you pick. Java guys can continue to use Axis (Axis2 is what I have been waiting for). PHP -- I sill don't know about the libraries that would support these.

&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 The advantage of MTOM attachments is that the APIs are fairly abstracted and one doesn't need to perform any manual compuations or calculations.
&lt;/p&gt;
    </content:encoded>
    <pubDate>Wed, 04 Oct 2006 17:38:00 -0700</pubDate>
    <guid isPermaLink="false">http://eduzine.edujini-labs.com/archives/6-guid.html</guid>
    </item>
<item>
    <title> ASP.Net: Disable non-SOAP Requests</title>
    <link>http://eduzine.edujini-labs.com/archives/5-ASP.Net-Disable-non-SOAP-Requests.html</link>
<category>Web Services</category>    <comments>http://eduzine.edujini-labs.com/archives/5-ASP.Net-Disable-non-SOAP-Requests.html#comments</comments>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=5</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=2.0&amp;type=comments&amp;cid=5</wfw:commentRss>
    <author>eduzine@edujinionline.com (Eduzine)</author>
    <content:encoded>

&lt;p class=&quot;question&quot;&gt;
 How to disable non-SOAP and non-Documentation Requests to ASP.Net based Web Services?
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 ASP.Net WebServices (ASMX handlers) are highly configurable in terms of the protocols that they can handle. By protocol, I mean the WebServices protocols like Get, Post, Document, SOAP-1.1, SOAP-1.2 etc.
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 The configuration section &lt;code&gt;/configuration/system.web/webServices&lt;/code&gt; is handled by &lt;code&gt;System.Web.Services.Configuration.WebServicesSection&lt;/code&gt;. Now, this section has a sub-section of &lt;code&gt;procotols&lt;/code&gt; that is mapped to the &lt;code&gt;Protocols&lt;/code&gt; property of the class mentioned.
&lt;/p&gt;
 
&lt;p class=&quot;answer&quot;&gt;
 By default, the following protocols are enabled:

&lt;/p&gt;&lt;ul&gt;
 &lt;li&gt;HttpGet&lt;/li&gt;
 &lt;li&gt;HttpPostLocalhost&lt;/li&gt;
 &lt;li&gt;HttpSoap&lt;/li&gt;
 &lt;li&gt;HttpSoap12&lt;/li&gt;
 &lt;li&gt;Documentation&lt;/li&gt;
&lt;/ul&gt;

 These elements, technically, are members of the enumeration &lt;code&gt;System.Web.Services.Configuration.WebServiceProtocols&lt;/code&gt;.
&lt;p&gt;

&lt;/p&gt;&lt;p class=&quot;answer&quot;&gt;
 To disable non-SOAP and non-Documentation requests, all that needs to be done is remove the other protocols. To do so, add the following code in your application &lt;code&gt;web.config&lt;/code&gt; under the &lt;code&gt;/configuration/system.web/webServices&lt;/code&gt; section:
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;protocols&amp;gt;
   &amp;lt;remove name='HttpGet' /&amp;gt;
   &amp;lt;remove name='HttpPostLocalhost' /&amp;gt;
&amp;lt;/protocols&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p class=&quot;answer&quot;&gt;
 You are done. As always, if in trouble, either post a comment or contact EduJini!
&lt;/p&gt;    </content:encoded>
    <pubDate>Tue, 03 Oct 2006 17:34:00 -0700</pubDate>
    <guid isPermaLink="false">http://eduzine.edujini-labs.com/archives/5-guid.html</guid>
    </item>
<item>
    <title>HOWTO: How to Use WSDL in .Net Applications</title>
    <link>http://eduzine.edujini-labs.com/archives/4-HOWTO-How-to-Use-WSDL-in-.Net-Applications.html</link>
<category>Web Services</category>    <comments>http://eduzine.edujini-labs.com/archives/4-HOWTO-How-to-Use-WSDL-in-.Net-Applications.html#comments</comments>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=4</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=2.0&amp;type=comments&amp;cid=4</wfw:commentRss>
    <author>eduzine@edujinionline.com (Eduzine)</author>
    <content:encoded>

&lt;p class=&quot;question&quot;&gt;
 How to use this WSDL file in my own .NET application?
&lt;/p&gt;

&lt;p class=&quot;answer&quot;&gt;
 The action requires a maximum of 4 steps.
&lt;/p&gt;

 
&lt;ul&gt;
 &lt;li&gt;Step 1: Right click on the 'project' in 'Solution Explorer' and select 'Add Web Reference...'&lt;/li&gt;
 &lt;li&gt;Step 2 (optional): Browse to the service location. If you know the location of the WSDL file, skip this step.&lt;/li&gt;
 &lt;li&gt;Step 3: Browse to the WSDL file.&lt;/li&gt;
 &lt;li&gt;Step 4: Give the name of the proxy class to be generated for the service.&lt;/li&gt;
&lt;/ul&gt;

&lt;p class=&quot;answer&quot;&gt;
 See the screenshots below.
&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;
&lt;p class=&quot;answer&quot;&gt;
 Step 1: &lt;br /&gt;
 &lt;a href=&quot;uploads/technology/ws_and_soa/01.WebReference.01.jpg&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;uploads/technology/ws_and_soa/01.WebReference.01.jpg&quot; style=&quot;border: 0px none ; padding-left: 5px; padding-right: 5px;&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;
&lt;p class=&quot;answer&quot;&gt;
 Step 2: &lt;br /&gt;
 &lt;a href=&quot;uploads/technology/ws_and_soa/01.WebReference.02.jpg&quot;&gt;&lt;img src=&quot;uploads/technology/ws_and_soa/01.WebReference.02.jpg&quot; style=&quot;border: 0px none ; padding-left: 5px; padding-right: 5px;&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;
&lt;p class=&quot;answer&quot;&gt;
 Step 3: &lt;br /&gt;
 &lt;a href=&quot;uploads/technology/ws_and_soa/01.WebReference.03.jpg&quot;&gt;&lt;img src=&quot;uploads/technology/ws_and_soa/01.WebReference.03.jpg&quot; style=&quot;border: 0px none ; padding-left: 5px; padding-right: 5px;&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;
&lt;p class=&quot;answer&quot;&gt;
 Step 4: &lt;br /&gt;
 &lt;a href=&quot;uploads/technology/ws_and_soa/01.WebReference.04.jpg&quot;&gt;&lt;img src=&quot;uploads/technology/ws_and_soa/01.WebReference.04.jpg&quot; style=&quot;border: 0px none ; padding-left: 5px; padding-right: 5px;&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;
    </content:encoded>
    <pubDate>Mon, 02 Oct 2006 17:05:00 -0700</pubDate>
    <guid isPermaLink="false">http://eduzine.edujini-labs.com/archives/4-guid.html</guid>
    </item>
<item>
    <title>ASP.Net: Using Asynchronous Calls in Web Service</title>
    <link>http://eduzine.edujini-labs.com/archives/2-ASP.Net-Using-Asynchronous-Calls-in-Web-Service.html</link>
<category>Web Services</category>    <comments>http://eduzine.edujini-labs.com/archives/2-ASP.Net-Using-Asynchronous-Calls-in-Web-Service.html#comments</comments>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=2</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=2.0&amp;type=comments&amp;cid=2</wfw:commentRss>
    <author>eduzine@edujinionline.com (Eduzine)</author>
    <content:encoded>

&lt;p class=&quot;question&quot;&gt;
 What is the best approach to perform asynchronous call in Web Services?
&lt;/p&gt;
&lt;br /&gt;
&lt;p class=&quot;answer&quot;&gt;
 There are three approaches. Depending upon the requirement, one or more may be chosen.
&lt;/p&gt;&lt;ul&gt;
 &lt;li&gt;&lt;b&gt;Asynchronous Delegate-Call&lt;/b&gt;&lt;/li&gt;
 &lt;li&gt;&lt;b&gt;Threads&lt;/b&gt;&lt;/li&gt;
 &lt;li&gt;&lt;b&gt;Message Queues (MSMQ)&lt;/b&gt;&lt;/li&gt;
&lt;/ul&gt; 
&lt;p&gt;Let us explore these options in depth...&lt;/p&gt;
&lt;ul&gt;
 &lt;li&gt;
   &lt;b&gt;Asynchronous Delegate-Call&lt;/b&gt;
   &lt;p&gt;Simplest way to call a method asynchronously.&lt;/p&gt;
   &lt;p&gt;Create a delegate with the same signature as the method that you wish to invoke. Then, create a new instance of the delegate using the method-instance as the parameter (similar to what you write while adding an event handler to an event). Then use the methods BeginInvoke and EndInvoke to call it.
   &lt;/p&gt;
   &lt;p&gt;Use this mechanism if you want to call the method asynchronously but the result to the client is synchronous. The method &lt;code&gt;WebMethod&lt;/code&gt; in the above example will not return unless &lt;code&gt;iar.IsComplete&lt;/code&gt; is true.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p style=&quot;margin-top: -20px;&quot; /&gt;&lt;pre&gt;&lt;code&gt;
     public static object MethodToCall(params) { ... }
     public delegate object MethodDelegate(params);

     public WebService
     {
       public string WebMethod(params)
       {
         MethodDelegate md = new MethodDelegate(MethodToCall);
         IAsyncResult iar = md.BeginInvoke(...);

         //Do other work of yours
         //And then check for the other method
         while(!iar.IsComplete)
         {
           Thread.Sleep(20);
         }
         object returnValue = md.EndInvoke(...);
       }
     }&lt;/code&gt;&lt;/pre&gt;&lt;p /&gt;&lt;p&gt;

&lt;/p&gt;&lt;p class=&quot;answer&quot;&gt;
&lt;/p&gt;&lt;ul&gt;
 &lt;li&gt;
   &lt;b&gt;Threads&lt;/b&gt;
   &lt;p&gt;This approach may be used in scenario where a task needs to be started by a web service while another web-service may be used to monitor the progress of the service.
   &lt;/p&gt;

   &lt;p&gt;Example is long. Will post the URL from where the code may be downloaded.
   &lt;/p&gt;
 &lt;/li&gt;
 &lt;li&gt;
   &lt;b&gt;Message Queues (MSMQ)&lt;/b&gt;
   &lt;p&gt;The scenario would be same as for Threads. However, here there is a flexibility. The MS-MQ server can be anywhere in the world and the monitoring web service can, as such, be anywhere - need not be on the same server as the invoking service.&lt;/p&gt;
   &lt;p&gt;Example is long. Will post the URL from where the code may be downloaded.&lt;/p&gt;
 &lt;/li&gt;
&lt;/ul&gt;    </content:encoded>
    <pubDate>Sun, 01 Oct 2006 23:28:00 -0700</pubDate>
    <guid isPermaLink="false">http://eduzine.edujini-labs.com/archives/2-guid.html</guid>
    </item>
</channel>
</rss>
