Web Services uses the out parameter. In the SOAP protocol, it returns the same content as the return value as the SOAP response.
Web Services Definition:
1: public class WebService1 : System.Web.Services.WebService
2: {
3: [WebMethod]
4: public string HelloWorld(out int outParamInt,out TestClass outParamObject)
5: {
6: outParamInt = 10;
7: outParamObject = new TestClass() { ID=1,Name="XX"};
8: return "Hello World";
9: }
10: }
11:
12: public class TestClass
13: {
14: public int ID{get;set;}
15: public string Name{get;set;}
16: }
17:
Defines two out parameters: an int and a complex type. Generated SOAP:
HTTP/1.1 200 OKContent-Type: text/xml; charset=utf-8Content-Length: length<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <HelloWorldResponse xmlns="http://tempuri.org/"> <HelloWorldResult>string</HelloWorldResult> <outParamInt>int</outParamInt> <outParamObject> <ID>int</ID> <Name>string</Name> </outParamObject> </HelloWorldResponse> </soap:Body></soap:Envelope>
The generated client code is as follows:
1: public string HelloWorld(out int outParamInt, out Client.localhost.TestClass outParamObject) {
2: Client.localhost.HelloWorldRequest inValue = new Client.localhost.HelloWorldRequest();
3: inValue.Body = new Client.localhost.HelloWorldRequestBody();
4: Client.localhost.HelloWorldResponse retVal = ((Client.localhost.WebService1Soap)(this)).HelloWorld(inValue);
5: outParamInt = retVal.Body.outParamInt;
6: outParamObject = retVal.Body.outParamObject;
7: return retVal.Body.HelloWorldResult;
8: }
9:
Test code:
1: static void Main(string[] args)
2: {
3: localhost.WebService1SoapClient c = new localhost.WebService1SoapClient();
4: localhost.TestClass testClass1;
5: int i;
6: c.HelloWorld(out i,out testClass1);
7: }
8:
For other clients, you can obtain the out parameter like the return value. For example, Flex:
Flex test code:
1: <?xml version="1.0" encoding="utf-8"?>
2: <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
3: xmlns:s="library://ns.adobe.com/flex/spark"
4: xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
5: creationComplete="app_creationCompleteHandler(event)" >
6: <fx:Declarations>
7: <! -- Place non-visual elements (such as services and value objects) Here -->
8: <s:WebService id="MyService" wsdl="http://localhost:1552/WebService1.asmx?WSDL">
9: <s:operation name="HelloWorld" result="onResult(event)"/>
10: </s:WebService>
11: </fx:Declarations>
12: <fx:Script>
13: <![CDATA[
14: import mx.events.FlexEvent;
15: import mx.rpc.events.ResultEvent;
16:
17: private function onResult(evnet:ResultEvent):void
18: {
19:
20: }
21: protected function app_creationCompleteHandler(event:FlexEvent):void
22: {
23: MyService.HelloWorld();
24: }
25:
26: ]]>
27: </fx:Script>
28: </s:Application>
The result of the event that tracks onResult: