XML Web Service Development Instance -- call web service through Windows Forms

Source: Internet
Author: User
Development Platform:. NET 2.0
Development tools: Visual Web Developer 2005 express edition beta Visual C #2005 express edition Beta

 

Service. asmx
<% @ WebService Language = "C #" codebehind = "~ /Code/service. cs "class =" myservicecs "%>

Service. CS
Using system;
Using system. Web;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. diagnostics;
Using system. Web. Services;
Using system. Web. Services. Protocols;

[Webservicebinding (conformanceclaims = wsiclaims. BP10, emitconformanceclaims = true)]
Public class myservicecs: system. Web. Services. WebService
{
Public myservicecs ()
{
}

[Webmethod]
Public int addnumbers (INT num1, int num2)
{
Return (num1 + num2 );
}

[Webmethod]
Public int subnumbers (INT num1, int num2)
{
Return (num1-num2 );
}

[Webmethod]
Public int mulnumbers (INT num1, int num2)
{
Return (num1 * num2 );
}

[Webmethod]
Public int divnumbers (INT num1, int num2)
{
Return (num1/num2 );
}
}

Form1.cs
# Region using directives

Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Windows. forms;

# Endregion

Namespace arithcalculatorwebserviceclient
{
Partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}

Private myservicecs csservice = new myservicecs ();

Private void lblresult_click (Object sender, eventargs E)
{
Int result = csservice. addnumbers (int32.parse (txtnum1.text), int32.parse (txtnum2.text ));
Lblresult. Text = result. tostring ();
}

Private void btnsub_click (Object sender, eventargs E)
{
Int result = csservice. subnumbers (int32.parse (txtnum1.text), int32.parse (txtnum2.text ));
Lblresult. Text = result. tostring ();
}

Private void btnmul_click (Object sender, eventargs E)
{
Int result = csservice. mulnumbers (int32.parse (txtnum1.text), int32.parse (txtnum2.text ));
Lblresult. Text = result. tostring ();
}

Private void btndiv_click (Object sender, eventargs E)
{
Int result = csservice. divnumbers (int32.parse (txtnum1.text), int32.parse (txtnum2.text ));
Lblresult. Text = result. tostring ();
}

Private void form1_load (Object sender, eventargs E)
{

}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.