Posted by: இராய் அந்தோனி அர்னால்டு | August 13, 2010

New Namespaces in the .NET Framework 4

New Namespaces in the .NET Framework 4

The following namespaces are new in the .NET Framework version 4.

Posted by: இராய் அந்தோனி அர்னால்டு | November 26, 2008

Two Marks – Unit 1 & Unit 2

Click Here

2marks-2008

Posted by: இராய் அந்தோனி அர்னால்டு | November 4, 2008

Building Web Service – Part VI

Client Code in ASP.NET

MathClient.aspx

<%@
Page
Language=”C#”
AutoEventWireup=”true”
CodeFile=”MathClient.aspx.cs”
Inherits=”MathClient”
%>

<!DOCTYPE
html
PUBLIC
“-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html
xmlns=”http://www.w3.org/1999/xhtml”
>

<head
runat=”server”>

<title>Untitled Page</title>

<script
language=”C#”
runat=”server”>

float operand1 = 0;

float operand2 = 0;

public
void Submit_Click(Object sender, EventArgs E)

{

try

{

operand1 = float.Parse(Operand1.Text);

operand2 = float.Parse(Operand2.Text);

}

catch (Exception) { /* ignored */ }

Service service = new
Service();

//change this URL if the location of the Web service changes

switch (((Control)sender).ID)

{ case
“Add” : Result.Text = “<b>Result</b> = “ + service.Add(operand1, operand2).ToString(); break;

case
“Subtract” : Result.Text = “<b>Result</b> = “ + service.Subtract(operand1, operand2).ToString(); break;

case
“Multiply” : Result.Text = “<b>Result</b> = “ + service.Multiply(operand1, operand2).ToString(); break;

case
“Divide” : Result.Text = “<b>Result</b> = “ + service.Divide(operand1, operand2).ToString(); break;

}

}

</script>

</head>

<body>

<form
id=”form1″
runat=”server”>

<div>

Operand 1: <br/><asp:TextBox
id=”Operand1″
Text=”15″
runat=”server”/><br/>

Operand 2: <br/><asp:TextBox
id=”Operand2″
Text=”5″
runat=”server”/><br/>

<input
type=”submit”
id=”Add”
value=”Add”
onserverclick=”Submit_Click”
runat=”server”/>

<input
type=”submit”
id=”Subtract”
value=”Subtract”
onserverclick=”Submit_Click”
runat=”server”/>

<input
type=”submit”
id=”Multiply”
value=”Multiply”
onserverclick=”Submit_Click”
runat=”server”/>

<input
type=”submit”
id=”Divide”
value=”Divide”
onserverclick=”Submit_Click”
runat=”server”/>

<asp:Label
id=”Result”
runat=”server”/>

</div>

</form>

</body>

</html>

 

Output

 

 

Posted by: இராய் அந்தோனி அர்னால்டு | November 4, 2008

Building Web Service – Part V

A Console Client Program to test the calculator web service

using System;

// driver program to test the web service

public class Tester

{

public static void Main( )

{

Tester t = new Tester( );

t.Run( );

}

public void Run( )

{

int var1 = 5;

int var2 = 7;

// instantiate the web service proxy

WebSite3.Service theWebSvc = new WebSite3.Service( );

// call the add method

Console.WriteLine(“{0} + {1} = {2}”, var1, var2, theWebSvc.Add(var1, var2));

// build a table by repeatedly calling the mul method

for (int i = 2;i<10; i++)

for (int j = 1;j <=10;j++)

{

Console.WriteLine(“{0} X {1} = {2}”, i, j,theWebSvc.Mul(i, j));

}

}

}

Output (excerpt):

5 + 7 = 12

2 X 1 = 2

2 X 2 = 4

2 X 3 = 6

2 X 4 = 8

2 X 5 = 10

2 X 6 = 12

2 X 7 = 14

2 X 8 = 16

2 X 9 = 18

2 X 10 = 20

3 X 1 = 3

 

The calculator service is now more available than you might have imagined (depending on your security settings) through the web protocols of HTTP-Get, HTTP-Post, or SOAP.

 

The client uses the SOAP protocol, but he could certainly create a client that would use HTTPGet:

http://localhost:3396/WebSite3/Service.asmx/Add?x=23&y=22

In fact, if you put that URL into your browser, the browser will respond with the following answer:

<?xml version=”1.0″ encoding=”utf-8″?>

<float>45</float>

 

The key advantage SOAP has over HTTP-Get and HTTP-Post is that SOAP can support a rich set of datatypes, including all of the C# intrinsic types (int, double, etc.), as well as enums, classes, structs, and ADO.NET DataSets, and arrays of any of these types.

 

Also, while HTTP-Get and HTTP-Post protocols are restricted to name/value pairs of primitive types and enums, SOAP’s rich XML grammar offers a more robust alternative for data exchange.

Posted by: இராய் அந்தோனி அர்னால்டு | November 4, 2008

Building Web Service – Part IV

Creating the Proxy

 

Figure shows the communication between a Web browser client and a Web service over the Internet.

 

  • The proxy object is the basic concept of the Web Service invocation. So the first step to creating Web service clients is to create a proxy object.
  • Then we can use multiple platforms (Web browsers, WAP, Personal Digital Assistant [PDA], SOAP clients) to extract data from the proxy object.
  • Before creating a client application to interact with the calculator web service, first create a proxy class.
  • Once again, you can do this by hand, but that would be hard work.
  • The folks at Microsoft have provided a tool called wsdl that generates the source code for the proxy based on the information in the WSDL file.
  • To create the proxy, enter wsdl at the Windows command-line prompt, followed by the path to the WSDL contract.
  • For example, you might enter: wsdl http://localhost:3396/WebSite3/Service.asmx?wsdl

 


 

  • The result is the creation of a C# client file named Service.cs, an excerpt of which appears below.
  • You must add the namespace WebSite3 because you’ll need it when you build your client (the tool does not insert it for you).

 

 

 

 

The sample Service.cs code is as follows:

 

using System;

using System.ComponentModel;

using System.Diagnostics;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Xml.Serialization;

 

namespace WebSite3

{

[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]

[System.Diagnostics.DebuggerStepThroughAttribute()]

[System.ComponentModel.DesignerCategoryAttribute("code")]

[System.Web.Services.WebServiceBindingAttribute(Name="ServiceSoap", Namespace="http://tempuri.org/")]

 

public
partial
class Service : System.Web.Services.Protocols.SoapHttpClientProtocol {

private System.Threading.SendOrPostCallback AddOperationCompleted;

private System.Threading.SendOrPostCallback SubtractOperationCompleted;

private System.Threading.SendOrPostCallback MultiplyOperationCompleted;

private System.Threading.SendOrPostCallback DivideOperationCompleted;

///
<remarks/>

public Service() {

this.Url = “http://localhost:3396/WebSite3/Service.asmx”;

}

///
<remarks/>

public
event AddCompletedEventHandler AddCompleted;

///
<remarks/>

public
event SubtractCompletedEventHandler SubtractCompleted;

///
<remarks/>

public
event MultiplyCompletedEventHandler MultiplyCompleted;

///
<remarks/>

public
event DivideCompletedEventHandler DivideCompleted;

///
<remarks/>

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/Add", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]

public
float Add(float a, float b) {

object[] results = this.Invoke(“Add”, new
object[] {

a,

b});

return ((float)(results[0]));

}

///
<remarks/>

public System.IAsyncResult BeginAdd(float a, float b, System.AsyncCallback callback, object asyncState) {

return
this.BeginInvoke(“Add”, new
object[] {

a,

b}, callback, asyncState);

}

///
<remarks/>

public
float EndAdd(System.IAsyncResult asyncResult) {

object[] results = this.EndInvoke(asyncResult);

return ((float)(results[0]));

}

///
<remarks/>

public
void AddAsync(float a, float b) {

this.AddAsync(a, b, null);

}

///
<remarks/>

public
void AddAsync(float a, float b, object userState) {

if ((this.AddOperationCompleted == null)) {

this.AddOperationCompleted = new System.Threading.SendOrPostCallback(this.OnAddOperationCompleted);

}

this.InvokeAsync(“Add”, new
object[] {

a,

b}, this.AddOperationCompleted, userState);

}

 

private
void OnAddOperationCompleted(object arg) {

if ((this.AddCompleted != null)) {

System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));

this.AddCompleted(this, new AddCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));

}

}

 


 

Older Posts »

Categories

Follow

Get every new post delivered to your Inbox.