如何从Web服务返回响应 [英] How to return response from webservice

查看:101
本文介绍了如何从Web服务返回响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我已经做了一个Web服务,客户端将调用它的方法.假设一个方法有四个参数,并且我想检查一下其中的任何一个是否为空,我想将响应发送回客户端,并且希望将其发送给客户端.发出警报,以便客户端知道什么参数为空.我无法强制客户端准确地提供所有参数.如果可以,请告诉我是否有可能.
谢谢.

Hello
I have made a web service and clients will call its methods.Suppose one method takes four parameters and i want to check that if any one of these is empty i want to send a response back to the client and i want to send it like an alerts so client knows what argument is empty.I can not force client to give all parameters accurate.Now tell is this possible if yes please help.
Thanks.

[WebMethod]
Public void Method1(string str1,string str2,string str3,string str4)
{
if((str1=="") || (str2==""))
{
//send response back to client in form of an alert
}
}

推荐答案

如果声明了void方法,除了返回值之外,您怎么能做到.首先要考虑获得返回值的响应,不是吗?

如果仅查看System.Web.Services.WebMethodAttribute上的MSDN帮助页面,您将看到一个返回字符串结果的代码示例:
http://msdn.microsoft.com/en-us/library/system. web.services.webmethodattribute.aspx [ ^ ].

另请参阅以下文章:
http://msdn.microsoft.com/en-us/library/byxd99hx%28v = vs.90%29.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/4ef803zd%28v = vs.90%29.aspx [ ^ ].

似乎没有人想到void返回的想法.但是,例如当您不需要任何响应时,此类void方法没有任何问题.

我觉得您可能在通用编程中缺少一些非常基本的东西:类型,方法,静态vs.实例,参数,堆栈…在进行Web开发之前,我建议您多加注意一些基本知识.

—SA
How can you except some return if you declared a void method. Getting a response in a return value is first thing to think about, is it not?

If you simply look at the MSDN help page on System.Web.Services.WebMethodAttribute, you will see a code sample which returns string result:
http://msdn.microsoft.com/en-us/library/system.web.services.webmethodattribute.aspx[^].

See also these articles:
http://msdn.microsoft.com/en-us/library/byxd99hx%28v=vs.90%29.aspx[^],
http://msdn.microsoft.com/en-us/library/4ef803zd%28v=vs.90%29.aspx[^].

It looks like the idea of void return did not come to anyone''s mind. However, there is nothing wrong with such void methods, for example, when you don''t need any response.

I feel you might be missing something very basic in general programming: types, method, static vs. instance, parameters, stack… I would advise to pay more attention for the basics before doing Web development.

—SA


这篇关于如何从Web服务返回响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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