如何在Web服务的帮助下显示消息。如果A大于B [英] How Can I Display Message With The Help Of Webservice..If A Is Greater Than B
本文介绍了如何在Web服务的帮助下显示消息。如果A大于B的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebService2
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public int add( int a, int b)
{
if (a > b)
{
}
int c;
c = a + b;
return c;
}
}
}
推荐答案
你可以返回对象,创建如下所示的类
you can return object, create class like below
public class Results
{
public string Message {get; set;}
public int Value {get; set;}
}
then
then
[WebMethod]
public Results add( int a, int b)
{
Results res new Results();
if (a > b)
{
res.Message ="a is grater than b";
}
res.Value = a + b;
return res;
}
致电
when you call
localhost.Service1 client = new localhost.Service1();
int a = int.Parse(TextBox1.Text);
int b = int.Parse(TextBox2.Text);
var res = client.add(a, b);
LabelValue.Text = "Add Result : " + res.Value;
LabelMessage.Text = "Add Message : " + res.Message;
[WebMethod]
public String add( int a, int b)
{
String res="";
if (a > b)
{
res="a is grater than b";
}
return res;
}
您可以使用SOAP FAULT消息抛出异常。 请参阅有关肥皂故障的文章
You can throw the exception by using SOAP FAULT message. See article about soap fault
这篇关于如何在Web服务的帮助下显示消息。如果A大于B的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文