请教,如何用ActionScript3.0来调用WebService呢?(补充问题)

dingjk007 2010-12-31 11:14:16
如题:
WebService带密码验证的,
要调用远程的WebService
可以提供点参考例子么?
我的代码如下,再往下本人就不会写了~:

public class getWebXml
{
var mWebSer1:WebService;
public function getWebXml()
{
mWebSer1 = new mx.rpc.soap.WebService();
mWebSer1.wsdl = ""; //这里是WebService的地址
mWebSer1.loadWSDL(ws1.wsdl);

}
}

WebService的帮助文档是:

SOAP 1.1
以下是 SOAP 1.2 请求和响应示例。所显示的“占位符”需替换为实际值。

POST /rt/Service.asmx HTTP/1.1
Host: 116.236.252.205
Content-Type: text/xml; charset=utf-8
Content-Length: “length”
SOAPAction: "http://tempuri.org/GetTrafficData"

<?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>
<GetTrafficData xmlns="http://tempuri.org/">
<strCustomID>“string”</strCustomID>
<strPassword>“string”</strPassword>
<strResult>“string”</strResult>
</GetTrafficData>
</soap:Body>
</soap:Envelope>
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>
<GetTrafficDataResponse xmlns="http://tempuri.org/">
<GetTrafficDataResult>"string"</GetTrafficDataResult>
</GetTrafficDataResponse>
</soap:Body>
</soap:Envelope>
////////////////////////////////////////////////////

SOAP 1.2
以下是 SOAP 1.2 请求和响应示例。所显示的“占位符”需替换为实际值。

POST /rt/Service.asmx HTTP/1.1
Host: 116.236.252.205
Content-Type: application/soap+xml; charset=utf-8
Content-Length: "length"
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetTrafficData xmlns="http://tempuri.org/">
<strCustomID> "string" </strCustomID>
<strPassword> "string"</strPassword>
<strResult> “string”</strResult>
</GetTrafficData>
</soap12:Body>
</soap12:Envelope>
HTTP/1.1 200 OK
Content-Type: application/soap+xml; charset=utf-8
Content-Length: “length”
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetTrafficDataResponse xmlns="http://tempuri.org/">
<GetTrafficDataResult> “string"</GetTrafficDataResponse>
</soap12:Body>
</soap12:Envelope>
////////////////////////////////////////////////////

HTTP GET
以下是 HTTP GET 请求和响应示例。所显示的“占位符”需替换为实际值。

GET /rt/Service.asmx/GetTrafficData?strCustomID=string&strPassword=string&strResult=string HTTP/1.1
Host: 116.236.252.205

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: "length"
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/"> "string”</string>
////////////////////////////////////////////////////

HTTP POST
以下是 HTTP POST 请求和响应示例。所显示的“占位符”需替换为实际值。

POST /rt/Service.asmx/GetTrafficData HTTP/1.1
Host: 116.236.252.205
Content-Type: application/x-www-form-urlencoded
Content-Length: “length”
strCustomID= “string "&strPassword= ”string “&strResult= ”string“HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: ”length“
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/"> “string”</string>


WebService的正式定义的服务说明如下:

<?xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
- <s:element name="GetTrafficData">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="strCustomID" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="strPassword" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="strResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
- <s:element name="GetTrafficDataResponse">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetTrafficDataResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
- <s:element name="GetDataPassWord">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="strCustomID" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="strPassword" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="strResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
- <s:element name="GetDataPassWordResponse">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetDataPassWordResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
- <s:element name="GetTrafficResult">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="strCustomID" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="strPassword" type="s:string" />
</s:sequence>
</s:complexType>



能否不调用后台,直接用AS来访问WebService来获得值呢?
麻烦达人们给点参考了!谢谢
...全文
164 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
passself 2011-01-01
as直接用http请求,写好回调函数,直接请求就可以了,服务器来处理访问来的请求
回复
dingjk007 2010-12-31
比如说,后台这么写可以么?

public function webAs()
{
//初始化WebService变量,并给wsdl属性赋值。wsdl属性将告诉WebService对象到哪里去找WSDL。
service.wsdl="http://*.*.*.*/xx.asmx?WSDL";
//在调用WebService方法前必须先调用loadWSDL方法,从指定的URL加载WSDL数据。
service.loadWSDL();
//给WebService对象添加侦听器,监听WSDL加载完成。
service.addEventListener(LoadEvent.LOAD,onWSDL);
//给WebService对象添加侦听器,监听出错的情况。
service.addEventListener(FaultEvent.FAULT,onFault);
}

private function onWSDL(evt:LoadEvent):void
{
var sss:String = "1111";
//为WebService方法添加侦听器,监听调用结果返回的情况。
service.Login.addEventListener(ResultEvent.RESULT,onLogin);
//为WebService方法添加侦听器,监听出错的情况。
service.Login.addEventListener(FaultEvent.FAULT,onFault);
//调用WebService方法。
service.GetTrafficData( "用户名","密码","状况");
}

其中GetTrafficData就是上面WebService正式定义的服务说明中的
<s:element name="GetTrafficData">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="strCustomID" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="strPassword" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="strResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>

像上面那样的调用可以么?帮帮忙啊!
回复
相关推荐
发帖
Flex
创建于2007-12-13

4328

社区成员

多媒体/设计 Flex
申请成为版主
帖子事件
创建了帖子
2010-12-31 11:14
社区公告
暂无公告