web service中的方法返回类型可以是void 吗?
可以吗可以吗?
[解决办法]
测试了一下,是完全可以的
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld(ref string hi)
{
hi = " I'm " + hi;
return "Hello World. " + hi;
}
[WebMethod]
public void HelloWorldVoidRef(ref string hi)
{
hi = "Void I'm " + hi;
}
[WebMethod]
public void HelloWorldVoid()
{
// do something
}
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
WpfApplication15.ServiceReference1.HelloWorldResponse WpfApplication15.ServiceReference1.WebService1Soap.HelloWorld(WpfApplication15.ServiceReference1.HelloWorldRequest request) {
return base.Channel.HelloWorld(request);
}
public string HelloWorld(ref string hi) {
WpfApplication15.ServiceReference1.HelloWorldRequest inValue = new WpfApplication15.ServiceReference1.HelloWorldRequest();
inValue.Body = new WpfApplication15.ServiceReference1.HelloWorldRequestBody();
inValue.Body.hi = hi;
WpfApplication15.ServiceReference1.HelloWorldResponse retVal = ((WpfApplication15.ServiceReference1.WebService1Soap)(this)).HelloWorld(inValue);
hi = retVal.Body.hi;
return retVal.Body.HelloWorldResult;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
WpfApplication15.ServiceReference1.HelloWorldVoidRefResponse WpfApplication15.ServiceReference1.WebService1Soap.HelloWorldVoidRef(WpfApplication15.ServiceReference1.HelloWorldVoidRefRequest request) {
return base.Channel.HelloWorldVoidRef(request);
}
public void HelloWorldVoidRef(ref string hi) {
WpfApplication15.ServiceReference1.HelloWorldVoidRefRequest inValue = new WpfApplication15.ServiceReference1.HelloWorldVoidRefRequest();
inValue.Body = new WpfApplication15.ServiceReference1.HelloWorldVoidRefRequestBody();
inValue.Body.hi = hi;
WpfApplication15.ServiceReference1.HelloWorldVoidRefResponse retVal = ((WpfApplication15.ServiceReference1.WebService1Soap)(this)).HelloWorldVoidRef(inValue);
hi = retVal.Body.hi;
}
public void HelloWorldVoid() {
base.Channel.HelloWorldVoid();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ServiceReference1.WebService1SoapClient client = new ServiceReference1.WebService1SoapClient();
string hi = "Bill Gates";
MessageBox.Show( client.HelloWorld(ref hi) );
MessageBox.Show(hi);
hi = "Bill Gates";
client.HelloWorldVoidRef(ref hi);
MessageBox.Show(hi);
client.HelloWorldVoid();
MessageBox.Show("OK");
}