c#调用java的webservice方法_C#调用webservice的三种方法总结

本文详细介绍了如何使用C#调用Java编写的WebService。提供了直接添加服务引用和POST请求两种调用方式,并提供了客户端调用的示例代码。通过HttpWebRequest和HttpWebResponse对象实现POST请求,读取响应数据。同时提到了使用PostMan工具进行测试的方法,强调了参数匹配的重要性。
摘要由CSDN通过智能技术生成

【1】直接添加服务引用,然后调用相关方法。

public class WebServiceDemo : System.Web.Services.WebService

{

[WebMethod]

public string HelloWorld()

{

return "Hello World";

}

[WebMethod]

public string Sum(string param1, string param2)

{

int num1 = Convert.ToInt32(param1);

int num2 = Convert.ToInt32(param2);

int sum = num1 + num2;

return sum.ToString();

}

}

客户端调用代码:

class Program

{

static void Main(string[] args)

{

Program program = new Program();

string url = "http://localhost:12544/WebServiceDemo.asmx";

string method = "Sum";

string num1 = "1";

string num2 = "2";

string result = program.HttpPostWebService

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值