I developed this class in C# to illustrate the basics of Operator overloading and Typecasting This sample also contains a use of the ToString method. This example is divided into three parts:-
Program.cs
//************************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Operator_Overloading
{
class Program
{
static void Main(string[] args)
{
Currency c1 = new Currency(-12, 234);
Currency c2 = new Currency(12, 234);
Currency sum = c1 + c2;
Console.WriteLine(sum );
if (c1 < c2)
Console.WriteLine(c1);
else
Console.WriteLine(c2);
double d = c1;
Console.WriteLine(d);
int n =(int) c1;
Console.WriteLine(n);
Console.WriteLine(c1["rupees"]);
Console.ReadKey();
}
}
}
//************************************************************************************
Currency,cs
//**********************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Operator_Overloading
{
public partial class Currency
{
public int this[string n]
{
get
{
n = n.Trim().ToLower();
int p = 2;
if (n.Equals("rs") || n.Equals("rupees"))
p = 0;
if (n.Equals("paise") || n.Equals("p"))
p = 1;
return this[p];
}
}
public int this[int n]
{
get
{
if (n == 0)
return paise / 100;
if (n == 1)
return paise % 100;
throw new Exception("Index out of range");
}
}
public static Currency operator +(Currency c1, Currency c2)
{
return new Currency(c1.paise + c2.paise);
}
private int paise;
public Currency()
{
this.paise = 0;
}
private Currency(int paise)
{
this.paise = paise;
}
public Currency(int rupees, int paise)
{
this.paise = 100 * rupees + paise;
}
public override string ToString()
{
string s;
if (paise < 0)
{
s = "-";
paise = -paise;
}
else
s = "";
int r = paise / 100;
int p = paise % 100;
string ps;
if(p<=9)
ps="0" + p;
else
ps="" + p;
return s + "Rs " + r + "." + ps;
}
}
}
//**********************************************************************************
OperatorsOfCurrency.cs
//**********************************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Operator_Overloading
{
public partial class Currency
{
public static explicit operator int(Currency c)
{
return Convert.ToInt32 ( Math .Round(c.paise/100.0,0));
}
public static implicit operator double(Currency c)
{
return c.paise /100.0;
}
public static bool operator <(Currency c1, Currency c2)
{
if (c1.paise < c2.paise)
return true;
else
return false;
}
public static bool operator >(Currency c1, Currency c2)
{
if (c1.paise > c2.paise)
return true;
else
return false;
}
}
}
//**********************************************************************************
Tuesday, November 30, 2010
Monday, November 15, 2010
Implementing Binary Trees in C
This is a program that I had in my mind for almost 3 years before I actually implemented it.
This program uses RECURSION to implement most of the algorithms here.
The DrawTree function is the one that draws the tree. It's based on the simple concept that at the Root Level we have just one node, two at the next, 4 at the next, in general 2 to the power h at level h.
// *******************************Trees.c***********************************
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
#include<math.h>
typedef struct mynode
{
int value;
struct mynode* left;
struct mynode* right;
}TreeNode;
void AddNode(TreeNode** root,int n);
void InOrder(TreeNode* root);
void PreOrder(TreeNode* root);
void PostOrder(TreeNode* root);
int Max(int a,int b);
int height(TreeNode* root);
void DrawTree(TreeNode* root,int yPosition,int xPosition,int dy,int dx,int level);
void main()
{
int gdriver = DETECT, gmode, errorcode;
TreeNode *root=NULL;
char ch=`1`;
int n;
clrscr();
while(ch!=27)
{
switch(ch)
{
case `A`:
case `a`:printf("\nEnter value to Add = ");
scanf("%d",&n);
AddNode(&root,n);
break;
case `I`:
case `i`:printf("\n Inorder = ");
InOrder(root);
printf("\n");
break;
case `P`:
case `p`:printf("\n PreOrder=");
PreOrder(root);
printf("\n");
break;
case `T`:
case `t`:printf("\n PostOrder=");
PostOrder(root);
printf("\n");
break;
case `d`:
case `D`:initgraph(&gdriver, &gmode, "");
DrawTree(root,10,getmaxx()/2,getmaxy()/height(root),getmaxx()/2,1);
getch();
closegraph();
}
ch=getch();
}
}
void AddNode(TreeNode** root,int n)
{
if(*root==NULL)
{
*root=malloc(sizeof(TreeNode));
(*root)->value=n;
(*root)->left=NULL;
(*root)->right=NULL;
return;
}
if(n<(*root)->value)
AddNode(&(*root)->left,n);
else
AddNode(&(*root)->right,n);
}
void InOrder(TreeNode* root)
{
if(root==NULL)
return;
InOrder(root->left);
printf("%d,",root->value);
InOrder(root->right);
}
void PreOrder(TreeNode* root)
{
if(root==NULL)
return;
printf("%d,",root->value);
PreOrder(root->left);
PreOrder(root->right);
}
void PostOrder(TreeNode* root)
{
if(root==NULL)
return;
PostOrder(root->left);
PostOrder(root->right);
printf("%d,",root->value);
}
void DrawTree(TreeNode* root,int yPosition,int xPosition,int dy,int dx,int level)
{
char s[80];
int radius=10,cx,cy,adjust=5;
if(root==NULL)
return;
if(level==1)
{
circle(xPosition,yPosition,radius);
itoa(root->value,s,10);
outtextxy(xPosition-adjust,yPosition-adjust,s);
DrawTree(root->left,yPosition,xPosition,dy,-dx/2,level+1);
DrawTree(root->right,yPosition,xPosition,dy,dx/2,level+1);
}
else
{
cx=xPosition + dx;
cy=yPosition + dy;
circle(cx,cy,radius);
itoa(root->value,s,10);
outtextxy(cx-adjust,cy-adjust,s);
line(xPosition,yPosition,cx,cy);
DrawTree(root->left,cy,cx,dy,-abs(dx)/2,level+1);
DrawTree(root->right,cy,cx,dy,abs(dx)/2,level+1);
}
}
int Max(int a,int b)
{
if(a>b)
return(a);
else
return(b);
}
int height(TreeNode* root)
{
if(root==NULL)
return(0);
return(1 + Max(height(root->left),height(root->right)));
}
// *******************************Trees.c***********************************
There is a supplementary post
This program uses RECURSION to implement most of the algorithms here.
The DrawTree function is the one that draws the tree. It's based on the simple concept that at the Root Level we have just one node, two at the next, 4 at the next, in general 2 to the power h at level h.
// *******************************Trees.c***********************************
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
#include<math.h>
typedef struct mynode
{
int value;
struct mynode* left;
struct mynode* right;
}TreeNode;
void AddNode(TreeNode** root,int n);
void InOrder(TreeNode* root);
void PreOrder(TreeNode* root);
void PostOrder(TreeNode* root);
int Max(int a,int b);
int height(TreeNode* root);
void DrawTree(TreeNode* root,int yPosition,int xPosition,int dy,int dx,int level);
void main()
{
int gdriver = DETECT, gmode, errorcode;
TreeNode *root=NULL;
char ch=`1`;
int n;
clrscr();
while(ch!=27)
{
switch(ch)
{
case `A`:
case `a`:printf("\nEnter value to Add = ");
scanf("%d",&n);
AddNode(&root,n);
break;
case `I`:
case `i`:printf("\n Inorder = ");
InOrder(root);
printf("\n");
break;
case `P`:
case `p`:printf("\n PreOrder=");
PreOrder(root);
printf("\n");
break;
case `T`:
case `t`:printf("\n PostOrder=");
PostOrder(root);
printf("\n");
break;
case `d`:
case `D`:initgraph(&gdriver, &gmode, "");
DrawTree(root,10,getmaxx()/2,getmaxy()/height(root),getmaxx()/2,1);
getch();
closegraph();
}
ch=getch();
}
}
void AddNode(TreeNode** root,int n)
{
if(*root==NULL)
{
*root=malloc(sizeof(TreeNode));
(*root)->value=n;
(*root)->left=NULL;
(*root)->right=NULL;
return;
}
if(n<(*root)->value)
AddNode(&(*root)->left,n);
else
AddNode(&(*root)->right,n);
}
void InOrder(TreeNode* root)
{
if(root==NULL)
return;
InOrder(root->left);
printf("%d,",root->value);
InOrder(root->right);
}
void PreOrder(TreeNode* root)
{
if(root==NULL)
return;
printf("%d,",root->value);
PreOrder(root->left);
PreOrder(root->right);
}
void PostOrder(TreeNode* root)
{
if(root==NULL)
return;
PostOrder(root->left);
PostOrder(root->right);
printf("%d,",root->value);
}
void DrawTree(TreeNode* root,int yPosition,int xPosition,int dy,int dx,int level)
{
char s[80];
int radius=10,cx,cy,adjust=5;
if(root==NULL)
return;
if(level==1)
{
circle(xPosition,yPosition,radius);
itoa(root->value,s,10);
outtextxy(xPosition-adjust,yPosition-adjust,s);
DrawTree(root->left,yPosition,xPosition,dy,-dx/2,level+1);
DrawTree(root->right,yPosition,xPosition,dy,dx/2,level+1);
}
else
{
cx=xPosition + dx;
cy=yPosition + dy;
circle(cx,cy,radius);
itoa(root->value,s,10);
outtextxy(cx-adjust,cy-adjust,s);
line(xPosition,yPosition,cx,cy);
DrawTree(root->left,cy,cx,dy,-abs(dx)/2,level+1);
DrawTree(root->right,cy,cx,dy,abs(dx)/2,level+1);
}
}
int Max(int a,int b)
{
if(a>b)
return(a);
else
return(b);
}
int height(TreeNode* root)
{
if(root==NULL)
return(0);
return(1 + Max(height(root->left),height(root->right)));
}
// *******************************Trees.c***********************************
There is a supplementary post
Breadth First traversal in Binary Trees.
Sunday, November 14, 2010
Getting Global Weather Via Web Services using ASP.NET
Windows Communication Foundation is Microsoft's new technology for implementing Remote Procedure Calls. It is intended to integrate all the previous variations like Messaging,Message Queuing, Remoting, and Web Services. Web Services use the HTTP port, and use an XML standard SOAP(Simple Object Transfer Protocol) for remote access. Web Services are described through the WSDL(Web Services Description Language) There are many free Web Services available on the Internet.
For this application I used the following URL http://www.webservicex.net/globalweather.asmx
Here is the Complete Application :---
1) Start a new ASP.NET Application.
2) Add A Service reference to the above URL
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Get Weather By City" />
<asp:TextBox ID="txtForecast" runat="server" Height="352px"
TextMode="MultiLine" Width="448px"></asp:TextBox>
Country<asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
City<asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
<asp:TextBox ID="txtCities" runat="server" Height="210px" TextMode="MultiLine"
Width="358px"></asp:TextBox>
</div>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="Get Cities By City" />
</form>
</body>
</html>
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
GlobalWeather.GlobalWeatherSoapClient gw = new GlobalWeather.GlobalWeatherSoapClient("GlobalWeatherSoap");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
txtCities.Text = "";
txtForecast.Text = "";
txtForecast.Text = gw.GetWeather(txtCity.Text, txtCountry.Text);
}
catch
{
}
}
protected void Button2_Click(object sender, EventArgs e)
{
try
{
txtCities.Text = "";
txtForecast .Text ="";
txtCities.Text = gw.GetCitiesByCountry(txtCountry.Text);
}
catch
{
}
}
}
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings/>
<connectionStrings/>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="OptionInfer" value="true"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory"/>
<remove name="ScriptHandlerFactoryAppServices"/>
<remove name="ScriptResource"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="GlobalWeatherSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<customBinding>
<binding name="GlobalWeatherSoap12">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://www.webservicex.net/globalweather.asmx"
binding="basicHttpBinding" bindingConfiguration="GlobalWeatherSoap"
contract="GlobalWeather.GlobalWeatherSoap" name="GlobalWeatherSoap" />
<endpoint address="http://www.webservicex.net/globalweather.asmx"
binding="customBinding" bindingConfiguration="GlobalWeatherSoap12"
contract="GlobalWeather.GlobalWeatherSoap" name="GlobalWeatherSoap12" />
</client>
</system.serviceModel>
</configuration>
*********************************Web.config**************************************
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET">
<s:element name="GetWeather">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="CityName" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="CountryName" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetWeatherResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetWeatherResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetCitiesByCountry">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="CountryName" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetCitiesByCountryResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetCitiesByCountryResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="string" nillable="true" type="s:string" />
</s:schema>
</wsdl:types>
<wsdl:message name="GetWeatherSoapIn">
<wsdl:part name="parameters" element="tns:GetWeather" />
</wsdl:message>
<wsdl:message name="GetWeatherSoapOut">
<wsdl:part name="parameters" element="tns:GetWeatherResponse" />
</wsdl:message>
<wsdl:message name="GetCitiesByCountrySoapIn">
<wsdl:part name="parameters" element="tns:GetCitiesByCountry" />
</wsdl:message>
<wsdl:message name="GetCitiesByCountrySoapOut">
<wsdl:part name="parameters" element="tns:GetCitiesByCountryResponse" />
</wsdl:message>
<wsdl:message name="GetWeatherHttpGetIn">
<wsdl:part name="CityName" type="s:string" />
<wsdl:part name="CountryName" type="s:string" />
</wsdl:message>
<wsdl:message name="GetWeatherHttpGetOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:message name="GetCitiesByCountryHttpGetIn">
<wsdl:part name="CountryName" type="s:string" />
</wsdl:message>
<wsdl:message name="GetCitiesByCountryHttpGetOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:message name="GetWeatherHttpPostIn">
<wsdl:part name="CityName" type="s:string" />
<wsdl:part name="CountryName" type="s:string" />
</wsdl:message>
<wsdl:message name="GetWeatherHttpPostOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:message name="GetCitiesByCountryHttpPostIn">
<wsdl:part name="CountryName" type="s:string" />
</wsdl:message>
<wsdl:message name="GetCitiesByCountryHttpPostOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:portType name="GlobalWeatherSoap">
<wsdl:operation name="GetWeather">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get weather report for all major cities around the world.</wsdl:documentation>
<wsdl:input message="tns:GetWeatherSoapIn" />
<wsdl:output message="tns:GetWeatherSoapOut" />
</wsdl:operation>
<wsdl:operation name="GetCitiesByCountry">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get all major cities by country name(full / part).</wsdl:documentation>
<wsdl:input message="tns:GetCitiesByCountrySoapIn" />
<wsdl:output message="tns:GetCitiesByCountrySoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="GlobalWeatherHttpGet">
<wsdl:operation name="GetWeather">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get weather report for all major cities around the world.</wsdl:documentation>
<wsdl:input message="tns:GetWeatherHttpGetIn" />
<wsdl:output message="tns:GetWeatherHttpGetOut" />
</wsdl:operation>
<wsdl:operation name="GetCitiesByCountry">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get all major cities by country name(full / part).</wsdl:documentation>
<wsdl:input message="tns:GetCitiesByCountryHttpGetIn" />
<wsdl:output message="tns:GetCitiesByCountryHttpGetOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="GlobalWeatherHttpPost">
<wsdl:operation name="GetWeather">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get weather report for all major cities around the world.</wsdl:documentation>
<wsdl:input message="tns:GetWeatherHttpPostIn" />
<wsdl:output message="tns:GetWeatherHttpPostOut" />
</wsdl:operation>
<wsdl:operation name="GetCitiesByCountry">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get all major cities by country name(full / part).</wsdl:documentation>
<wsdl:input message="tns:GetCitiesByCountryHttpPostIn" />
<wsdl:output message="tns:GetCitiesByCountryHttpPostOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="GlobalWeatherSoap" type="tns:GlobalWeatherSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetWeather">
<soap:operation soapAction="http://www.webserviceX.NET/GetWeather" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetCitiesByCountry">
<soap:operation soapAction="http://www.webserviceX.NET/GetCitiesByCountry" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="GlobalWeatherSoap12" type="tns:GlobalWeatherSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetWeather">
<soap12:operation soapAction="http://www.webserviceX.NET/GetWeather" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetCitiesByCountry">
<soap12:operation soapAction="http://www.webserviceX.NET/GetCitiesByCountry" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="GlobalWeatherHttpGet" type="tns:GlobalWeatherHttpGet">
<http:binding verb="GET" />
<wsdl:operation name="GetWeather">
<http:operation location="/GetWeather" />
<wsdl:input>
<http:urlEncoded />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetCitiesByCountry">
<http:operation location="/GetCitiesByCountry" />
<wsdl:input>
<http:urlEncoded />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="GlobalWeatherHttpPost" type="tns:GlobalWeatherHttpPost">
<http:binding verb="POST" />
<wsdl:operation name="GetWeather">
<http:operation location="/GetWeather" />
<wsdl:input>
<mime:content type="application/x-www-form-urlencoded" />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetCitiesByCountry">
<http:operation location="/GetCitiesByCountry" />
<wsdl:input>
<mime:content type="application/x-www-form-urlencoded" />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="GlobalWeather">
<wsdl:port name="GlobalWeatherSoap" binding="tns:GlobalWeatherSoap">
<soap:address location="http://www.webservicex.net/globalweather.asmx" />
</wsdl:port>
<wsdl:port name="GlobalWeatherSoap12" binding="tns:GlobalWeatherSoap12">
<soap12:address location="http://www.webservicex.net/globalweather.asmx" />
</wsdl:port>
<wsdl:port name="GlobalWeatherHttpGet" binding="tns:GlobalWeatherHttpGet">
<http:address location="http://www.webservicex.net/globalweather.asmx" />
</wsdl:port>
<wsdl:port name="GlobalWeatherHttpPost" binding="tns:GlobalWeatherHttpPost">
<http:address location="http://www.webservicex.net/globalweather.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
For this application I used the following URL http://www.webservicex.net/globalweather.asmx
Here is the Complete Application :---
1) Start a new ASP.NET Application.
2) Add A Service reference to the above URL
***************************************Default.aspx****************************
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ValidateRequest="false" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Get Weather By City" />
<asp:TextBox ID="txtForecast" runat="server" Height="352px"
TextMode="MultiLine" Width="448px"></asp:TextBox>
Country<asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
City<asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
<asp:TextBox ID="txtCities" runat="server" Height="210px" TextMode="MultiLine"
Width="358px"></asp:TextBox>
</div>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="Get Cities By City" />
</form>
</body>
</html>
***************************************Default.aspx****************************
***************************************Default.aspx.cs****************************
using System;
using System.Configuration;using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
GlobalWeather.GlobalWeatherSoapClient gw = new GlobalWeather.GlobalWeatherSoapClient("GlobalWeatherSoap");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
txtCities.Text = "";
txtForecast.Text = "";
txtForecast.Text = gw.GetWeather(txtCity.Text, txtCountry.Text);
}
catch
{
}
}
protected void Button2_Click(object sender, EventArgs e)
{
try
{
txtCities.Text = "";
txtForecast .Text ="";
txtCities.Text = gw.GetCitiesByCountry(txtCountry.Text);
}
catch
{
}
}
}
***************************************Default.aspx.cs****************************
***************************************Web.config*******************************
<?xml version="1.0"?>
<!-- Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings/>
<connectionStrings/>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="OptionInfer" value="true"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory"/>
<remove name="ScriptHandlerFactoryAppServices"/>
<remove name="ScriptResource"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="GlobalWeatherSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<customBinding>
<binding name="GlobalWeatherSoap12">
<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
messageVersion="Soap12" writeEncoding="utf-8">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
useDefaultWebProxy="true" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="http://www.webservicex.net/globalweather.asmx"
binding="basicHttpBinding" bindingConfiguration="GlobalWeatherSoap"
contract="GlobalWeather.GlobalWeatherSoap" name="GlobalWeatherSoap" />
<endpoint address="http://www.webservicex.net/globalweather.asmx"
binding="customBinding" bindingConfiguration="GlobalWeatherSoap12"
contract="GlobalWeather.GlobalWeatherSoap" name="GlobalWeatherSoap12" />
</client>
</system.serviceModel>
</configuration>
*********************************Web.config**************************************
********************************globalweather.wsdl********************************
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://www.webserviceX.NET" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://www.webserviceX.NET" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET">
<s:element name="GetWeather">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="CityName" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="CountryName" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetWeatherResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetWeatherResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetCitiesByCountry">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="CountryName" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetCitiesByCountryResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetCitiesByCountryResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="string" nillable="true" type="s:string" />
</s:schema>
</wsdl:types>
<wsdl:message name="GetWeatherSoapIn">
<wsdl:part name="parameters" element="tns:GetWeather" />
</wsdl:message>
<wsdl:message name="GetWeatherSoapOut">
<wsdl:part name="parameters" element="tns:GetWeatherResponse" />
</wsdl:message>
<wsdl:message name="GetCitiesByCountrySoapIn">
<wsdl:part name="parameters" element="tns:GetCitiesByCountry" />
</wsdl:message>
<wsdl:message name="GetCitiesByCountrySoapOut">
<wsdl:part name="parameters" element="tns:GetCitiesByCountryResponse" />
</wsdl:message>
<wsdl:message name="GetWeatherHttpGetIn">
<wsdl:part name="CityName" type="s:string" />
<wsdl:part name="CountryName" type="s:string" />
</wsdl:message>
<wsdl:message name="GetWeatherHttpGetOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:message name="GetCitiesByCountryHttpGetIn">
<wsdl:part name="CountryName" type="s:string" />
</wsdl:message>
<wsdl:message name="GetCitiesByCountryHttpGetOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:message name="GetWeatherHttpPostIn">
<wsdl:part name="CityName" type="s:string" />
<wsdl:part name="CountryName" type="s:string" />
</wsdl:message>
<wsdl:message name="GetWeatherHttpPostOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:message name="GetCitiesByCountryHttpPostIn">
<wsdl:part name="CountryName" type="s:string" />
</wsdl:message>
<wsdl:message name="GetCitiesByCountryHttpPostOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:portType name="GlobalWeatherSoap">
<wsdl:operation name="GetWeather">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get weather report for all major cities around the world.</wsdl:documentation>
<wsdl:input message="tns:GetWeatherSoapIn" />
<wsdl:output message="tns:GetWeatherSoapOut" />
</wsdl:operation>
<wsdl:operation name="GetCitiesByCountry">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get all major cities by country name(full / part).</wsdl:documentation>
<wsdl:input message="tns:GetCitiesByCountrySoapIn" />
<wsdl:output message="tns:GetCitiesByCountrySoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="GlobalWeatherHttpGet">
<wsdl:operation name="GetWeather">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get weather report for all major cities around the world.</wsdl:documentation>
<wsdl:input message="tns:GetWeatherHttpGetIn" />
<wsdl:output message="tns:GetWeatherHttpGetOut" />
</wsdl:operation>
<wsdl:operation name="GetCitiesByCountry">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get all major cities by country name(full / part).</wsdl:documentation>
<wsdl:input message="tns:GetCitiesByCountryHttpGetIn" />
<wsdl:output message="tns:GetCitiesByCountryHttpGetOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="GlobalWeatherHttpPost">
<wsdl:operation name="GetWeather">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get weather report for all major cities around the world.</wsdl:documentation>
<wsdl:input message="tns:GetWeatherHttpPostIn" />
<wsdl:output message="tns:GetWeatherHttpPostOut" />
</wsdl:operation>
<wsdl:operation name="GetCitiesByCountry">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">Get all major cities by country name(full / part).</wsdl:documentation>
<wsdl:input message="tns:GetCitiesByCountryHttpPostIn" />
<wsdl:output message="tns:GetCitiesByCountryHttpPostOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="GlobalWeatherSoap" type="tns:GlobalWeatherSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetWeather">
<soap:operation soapAction="http://www.webserviceX.NET/GetWeather" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetCitiesByCountry">
<soap:operation soapAction="http://www.webserviceX.NET/GetCitiesByCountry" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="GlobalWeatherSoap12" type="tns:GlobalWeatherSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetWeather">
<soap12:operation soapAction="http://www.webserviceX.NET/GetWeather" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetCitiesByCountry">
<soap12:operation soapAction="http://www.webserviceX.NET/GetCitiesByCountry" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="GlobalWeatherHttpGet" type="tns:GlobalWeatherHttpGet">
<http:binding verb="GET" />
<wsdl:operation name="GetWeather">
<http:operation location="/GetWeather" />
<wsdl:input>
<http:urlEncoded />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetCitiesByCountry">
<http:operation location="/GetCitiesByCountry" />
<wsdl:input>
<http:urlEncoded />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="GlobalWeatherHttpPost" type="tns:GlobalWeatherHttpPost">
<http:binding verb="POST" />
<wsdl:operation name="GetWeather">
<http:operation location="/GetWeather" />
<wsdl:input>
<mime:content type="application/x-www-form-urlencoded" />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetCitiesByCountry">
<http:operation location="/GetCitiesByCountry" />
<wsdl:input>
<mime:content type="application/x-www-form-urlencoded" />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="GlobalWeather">
<wsdl:port name="GlobalWeatherSoap" binding="tns:GlobalWeatherSoap">
<soap:address location="http://www.webservicex.net/globalweather.asmx" />
</wsdl:port>
<wsdl:port name="GlobalWeatherSoap12" binding="tns:GlobalWeatherSoap12">
<soap12:address location="http://www.webservicex.net/globalweather.asmx" />
</wsdl:port>
<wsdl:port name="GlobalWeatherHttpGet" binding="tns:GlobalWeatherHttpGet">
<http:address location="http://www.webservicex.net/globalweather.asmx" />
</wsdl:port>
<wsdl:port name="GlobalWeatherHttpPost" binding="tns:GlobalWeatherHttpPost">
<http:address location="http://www.webservicex.net/globalweather.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
********************************globalweather.wsdl********************************
Saturday, November 13, 2010
Two String functions in C using Pointers.
Getting back to what I love the most C Programming using Pointers.
StringPointers.c
#include<stdio.h>
#include<conio.h>
int strlen(char s[]);
void strcat(char src1[],char src2[],char dest[]);
void main()
{
int l;
char *str;
char s1[50],s2[50],s3[100];
clrscr();
gets(str);
l=strlen("Apple");
printf("\n%d",l);
l=strlen(str);
printf("\n%d",l);
printf("\nEnter s1 = ");
gets(s1);
printf("\nEnter s2 = ");
gets(s2);
strcat(s1,s2,s3);
printf("\n%s",s3);
getch();
}
void strcat(char src1[],char src2[],char dest[])
{
while((*dest++=*src1++)!='\0')
;
dest--;
while((*dest++=*src2++)!='\0')
;
}
int strlen(char s[])
{
int n=0;
while(*s++!='\0')
n++;
return(n);
}
To be continued . . .
StringPointers.c
#include<stdio.h>
#include<conio.h>
int strlen(char s[]);
void strcat(char src1[],char src2[],char dest[]);
void main()
{
int l;
char *str;
char s1[50],s2[50],s3[100];
clrscr();
gets(str);
l=strlen("Apple");
printf("\n%d",l);
l=strlen(str);
printf("\n%d",l);
printf("\nEnter s1 = ");
gets(s1);
printf("\nEnter s2 = ");
gets(s2);
strcat(s1,s2,s3);
printf("\n%s",s3);
getch();
}
void strcat(char src1[],char src2[],char dest[])
{
while((*dest++=*src1++)!='\0')
;
dest--;
while((*dest++=*src2++)!='\0')
;
}
int strlen(char s[])
{
int n=0;
while(*s++!='\0')
n++;
return(n);
}
To be continued . . .
Labels:
C#,
Champak,
Champak Roy,
Pandepur,
Pointers in C,
strcat,
Strings,
strlen,
Varanasi
Tuesday, November 9, 2010
Creating and entering a new Bean into Net Beans
This article will create and enter a TimerLabel into a Palette inside NetBeans from where we can use it in any Project. The Timer label will simply display the current date and time.
Starting the Project: Create a File called TimerLabel.java with the following Contents.
TimerLabel.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package timerbeansproject;
import java.util.Date;
import javax.swing.JLabel;
/**
*
* @author Champak */
public class TimerLabel extends JLabel {
public TimerLabel()
{
TimerThread t=new TimerThread();
t.start();
}
private class TimerThread extends Thread
{
@Override
public void run()
{
while(true)
{
try
{
Date d=new Date();
TimerLabel.this.setText("" + d);
Thread.sleep(1000);
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package timerbeansproject;
import java.util.Date;
import javax.swing.JLabel;
/**
*
* @author Champak */
public class TimerLabel extends JLabel {
public TimerLabel()
{
TimerThread t=new TimerThread();
t.start();
}
private class TimerThread extends Thread
{
@Override
public void run()
{
while(true)
{
try
{
Date d=new Date();
TimerLabel.this.setText("" + d);
Thread.sleep(1000);
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
}
}
TimerFrame.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* TimerFrame.java
*
* Created on Nov 9, 2010, 1:09:28 PM
*/
package timerbeansproject;
/**
*
* @author Champak */
public class TimerFrame extends javax.swing.JFrame {
/** Creates new form TimerFrame */
public TimerFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
timerLabel1 = new timerbeansproject.TimerLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(102, 102, 102)
.addComponent(timerLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(150, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(timerLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(275, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TimerFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private timerbeansproject.TimerLabel timerLabel1;
// End of variables declaration
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* TimerFrame.java
*
* Created on Nov 9, 2010, 1:09:28 PM
*/
package timerbeansproject;
/**
*
* @author Champak */
public class TimerFrame extends javax.swing.JFrame {
/** Creates new form TimerFrame */
public TimerFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
timerLabel1 = new timerbeansproject.TimerLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(102, 102, 102)
.addComponent(timerLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(150, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(timerLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(275, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TimerFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private timerbeansproject.TimerLabel timerLabel1;
// End of variables declaration
}
The series of Steps
- Starting the New Project
2. Building the Project.
3.Opening the Palette.
4.The Palette Manager
5.Selecting the Project containing the New Bean
6.Choosing the Component.
7.Adding the Timer Label to a JFrame
Subscribe to:
Posts (Atom)