如何在桌面应用程序中使用webservice ..? [英] How to consume webservice in desktop application..?

查看:463
本文介绍了如何在桌面应用程序中使用webservice ..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Web服务,我通过它与数据库进行交互。



我在c#中完成了桌面应用程序,我想调用web方法进行插入,使用网络服务更新,删除和选择数据...





请帮助我.... !!!

解决方案

创建Web服务的步骤:



1.创建Web服务应用程序

2.在解决方案资源管理器中,右键单击.asmx文件并选择查看代码。

3.创建一个添加的Web服务方法



 [WebMethod] 
public int WebAdd( int x, int y)
{
返回 x + y;
}





同步调用XML Web服务



1.创建基于Windows的新应用程序

2.在解决方案资源管理器中,右键单击项目的引用节点,然后单击添加Web引用。将打开添加Web引用对话框。

3.在地址框中键入以下Web服务URI

http://localhost/WebService1/Service1.asm [ ^ ]

4.这是您在上一过程中创建的Web服务的URI。 WebAdd和WebMultiply Web方法显示在添加Web引用对话框的左窗格中。

5.在Codebehind文件中添加代码



  private   void  button1_Click( object  sender,System.EventArgs e)
{
// 创建实例操作数和结果。
int x,y,z;
// 将文本框的内容解析为整数。
x = < span class =code-keyword> int .Parse(textBox1.Text);
y = int .Parse(textBox2.Text);
// 从Web服务实例调用WebAdd Web服务方法。
z = MathServiceClass.WebAdd(x,y);
textBox3.Text = z.ToString();
}





运行应用程序



希望这会有所帮助。



Senthil S


只需添加服务引用,并使用生成的代理类。



http://stackoverflow.com/ questions / 621440 / calling-asp-net-web-service-from-c-application [ ^ ]


这可能会有所帮助,



创建和使用您的第一个WCF服务 [ ^ ]



:)

I have created an web service, through which i interact with database.

I have desktop application done in c#, and i want to call web method for insert,update,delete and selecting data using web service...


Please Help me....!!!

解决方案

Steps to create Web service:

1. Create a Web service application
2. In Solution Explorer, right-click the .asmx file and choose View Code.
3. Create a Web service method that does addition

[WebMethod]
public int WebAdd(int x, int y)
{
   return x + y;
}



To call an XML Web service synchronously

1. Create a new Windows-based application
2. In Solution Explorer, right-click the References node of the project, and then click Add Web Reference. The Add Web Reference dialog box opens.
3. Type the following Web Service URI in the Address box
http://localhost/WebService1/Service1.asm[^]
4. This is the URI of the Web Service you created in the previous procedure. The WebAdd and WebMultiply Web methods appear in the left pane of the Add Web Reference dialog box.
5.Add the code in Codebehind file

private void button1_Click(object sender, System.EventArgs e)
{
// Create instances of the operands and result.
   int x, y, z;
// Parse the contents of the text boxes into integers.
   x = int.Parse(textBox1.Text);
   y = int.Parse(textBox2.Text);
// Call the WebAdd Web service method from the instance of the Web service.
   z = MathServiceClass.WebAdd(x, y);
   textBox3.Text = z.ToString();
}



Run the application

Hope this helps.

Senthil S


Just add service reference, and use the generated proxy class.

http://stackoverflow.com/questions/621440/calling-asp-net-web-service-from-c-application[^]


It might be helpful,

Creating and Consuming Your First WCF Service[^]

:)


这篇关于如何在桌面应用程序中使用webservice ..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆