WebService
<% @ WebService Language = "C #" class = "samples. ASPnet. simplewebservice" %>
Using system;
Using system. Web;
Using system. Web. Services;
Using system. xml;
Using system. Web. Services. Protocols;
Using system. Web. Script. Services;
Namespace samples. ASPnet
{
[WebService (namespace = "http://tempuri.org/")]
[Webservicebinding (conformsto = wsiprofiles. basicprofile1_1)]
[Scriptservice]
Public class simplewebservice: system. Web. Services. WebService
{
[Webmethod]
Public String echoinput (string input)
{
String inputstring = server. htmlencode (input );
If (! String. isnullorempty (inputstring ))
{
Return string. Format ("You entered {0}."
+ "Current time is {1}.", inputstring, datetime. Now );
}
Else
{
Return "the input string was null or empty .";
}
}
}
}
Sample. aspx
<% @ Page Language = "C #" %>
<! 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 id = "head1" runat = "server">
<Style type = "text/CSS">
Body {Font: 11pt trebuchet MS;
Font-color: #000000;
Padding-top: 72px;
Text-align: Center}
. Text {Font: 8pt trebuchet MS}
</Style>
<Title> simple Web Service </title>
<SCRIPT type = "text/JavaScript">
// This function callthe web service method.
Function echouserinput ()
{
VaR echoelem = Document. getelementbyid ("enteredvalue ");
Samples. ASPnet. simplewebservice. echoinput (echoelem. value,
Succeededcallback );
}
// This is the callback function that
// Processes the Web service return value.
Function succeededcallback (result)
{
VaR rsltelem = Document. getelementbyid ("Results ");
Rsltelem. innerhtml = result;
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Asp: scriptmanager runat = "server" id = "scriptmanager">
<Services>
<Asp: servicereference Path = "simplewebservice. asmx"/>
</Services>
</ASP: scriptmanager>
<Div>
<H2> simple Web Service </H2>
<P> calling a simple service that echoes the user's input and
Returns the current server time. </P>
<Input id = "enteredvalue" type = "text"/>
<Input id = "echobutton" type = "button"
Value = "Echo" onclick = "echouserinput ()"/>
</Div>
</Form>
<HR/>
<Div>
<Span id = "Results"> </span>
</Div>
</Body>
</Html>