[转]Web Services使用out参数
本文转自:http://www.cnblogs.com/zhaozhan/archive/2010/10/25/1860837.html
Web Services使用out参数,在SOAP协议中会跟返回值一样作为SOAP响应的内容返回。
Web Services定义:
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:
定义两个out参数:一个int,一个复杂类型的。生成的SOAP:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-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>
客户端的使用,生成的客户端代码:
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:
测试代码:
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:
对于其他的客户端,可以跟返回值一样获取out参数。如Flex:
Flex测试代码:
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: <!-- 将非可视元素(例如服务、值对象)放在此处 -->
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>
跟踪onResult的event的result:
[转]Web Services使用out参数的更多相关文章
- 跟我一起学WCF(3)——利用Web Services开发分布式应用
一.引言 在前面文章中分别介绍了MSMQ和.NET Remoting技术,今天继续分享.NET 平台下另一种分布式技术——Web Services 二.Web Services 详细介绍 2.1 We ...
- 利用Web Services开发分布式应用
一.引言 在前面文章中分别介绍了MSMQ和.NET Remoting技术,今天继续分享.NET 平台下另一种分布式技术——Web Services 二.Web Services 详细介绍 2.1 We ...
- .NET RESTful Web Services入门
很早之前看到过RESTful Web Services,并未在意,也没找相关资料进行学习.今天偶尔有一机会,就找了点资料进行研究,发现RESTful真是“简约而不简单”.下面用示例来说明: 1 项目结 ...
- 分分钟带你玩转 Web Services
当大型需求被数个公司分割开来,各公司系统相互交换数据的问题就会接踵而来. 毕竟是多家不同的公司的产品,研发开发语言.采用技术框架基本上是百花齐放. 怎样让自家系统提供的服务具有跨平台.跨语言.跨各种防 ...
- Jersey the RESTful Web Services in Java
Jersey 是一个JAX-RS的实现, JAX-RS即Java API for RESTful Web Services, 支持按照表述性状态转移(REST)架构风格创建Web服务. REST 中最 ...
- 使用 Spring 3 来创建 RESTful Web Services
来源于:https://www.ibm.com/developerworks/cn/web/wa-spring3webserv/ 在 Java™ 中,您可以使用以下几种方法来创建 RESTful We ...
- 利用WSCF进行契约先行的Web Services开发
http://www.cnblogs.com/goody9807/archive/2007/06/05/772107.html 什么是契约先行(Contract-First)? 如果说一个新的软件开发 ...
- Web Services 中XML、SOAP和WSDL的一些必要知识
Web Services 是由xml来定义数据格式的,通过SOAP协议在各个系统平台中传输,那么接下来讨论下SOAP和WSDL的各自作用. SOAP和WSDL对Web Service.WCF进行深入了 ...
- 就是这么简单!使用Rest-assured 测试Restful Web Services
使用 Rest-assured 测试 Restful Web Services 转载注明出处: http://www.cnblogs.com/wade-xu/p/4298819.html 这里向大家介 ...
随机推荐
- python安装(windows)
1.python安装(windows) 1.1 下载安装包 https://www.python.org/downloads/ 1.2 安装 python2.7默认安装路径:C:\python27 注 ...
- SQL SERVER:开窗函数 SUM() OVER() 数据统计中一例使用
由于前一段时间胃痛,导致博客园博客都停更了一个月左右.近几天,胃病终于稍微有所好转,决定重新写博文. 前几天,有个朋友刚好问到本人有关 SQL 语句,大致是原表有两列,分别为月份.月份销售额,而需要一 ...
- C#完成超酷的图像效果 (附demo)
如果您觉得C#制作的艺术字比较好玩, 但是还觉得没看够,不过瘾,那么我今天就让您一饱眼福, 看看C#如何制作的效果超酷的图像. (注: 我之前曾写过类似的文章, 但没有原理说明, 代码注释不够详细, ...
- STM32的TAMPER-RTC管脚作为Tamper使用 - 防拆机
当 TAMPER引脚上的信号从 0变成1或者从 1变成 0(取决于备份控制寄存器BKP_CR的 TPAL位),会产生一个侵入检测事件.侵入检测事件将所有数据备份寄存器内容清除. 然而为了避免丢失侵入 ...
- 获取 CPU 序列号
function GetCpuID: string; var _eax, _ebx, _ecx, _edx: Longword; s, s1, s2: string; begin asm push e ...
- Codeforces Round #342 (Div. 2) A - Guest From the Past 数学
A. Guest From the Past 题目连接: http://www.codeforces.com/contest/625/problem/A Description Kolya Geras ...
- (高精度运算4.7.26)POJ 1220 NUMBER BASE CONVERSION(高精度数的任意进制的转换——方法:ba1----->10进制----->ba2)
package com.njupt.acm; import java.math.BigInteger; import java.util.Scanner; public class POJ_1220_ ...
- asp.net 获取url
string url = Request.Url.ToString(); this.ImageLogo.ImageUrl = "http://" + Request.Url.Aut ...
- 使用贝赛尔曲线画扇形、圆形、弧线、多边形,实现App下载时的动画效果demo
// // MyView.swift // TestUIBezierPath // // Created by iCodeWoods on 16/5/8. // Copyright © 2016年 i ...
- Linux 下配置网卡的别名即网卡子IP的配置 转
what 什么是ip别名?用windows的话说,就是为一个网卡配置多个ip.when 什么场合增加ip别名能派上用场?布网需要.多ip访问测试.特定软件对多ip的需要...and so on. ho ...