as3调用基于soap的webservice。
参考:http://www.cnblogs.com/sevenyuan/archive/2009/12/01/1614767.html
as3没有直接实现soap,但是,soap是基于http+xml的,使用的是http协议,发送的内容通过时xml格式的,as3支持http请求和xml,还可以设置http请求的头信息,因此,as3调用基于soap的webservice应该是不难的。
本站的一个webservice,可用于测试:/study/aspnet/firstDemo/Service1.asmx
代码:
var xml:XML=<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>
<HelloWorld xmlns="/" />
</soap:Body>
</soap:Envelope>;
var uld:URLLoader = new URLLoader();
var req:URLRequest = new URLRequest("/study/aspnet/firstDemo/Service1.asmx");
req.method = URLRequestMethod.POST;
req.requestHeaders.push(new URLRequestHeader("Content-Type", "text/xml;charset=utf-8"));
req.requestHeaders.push(new URLRequestHeader("SOAPAction", "/HelloWorld"));
req.data = "<?xml version='1.0' encoding='utf-8'?>" + xml.toXMLString();
uld.addEventListener(Event.COMPLETE, onLoaded);
uld.addEventListener(IOErrorEvent.IO_ERROR, onError);
uld.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
uld.load(req);
function onError(e:Event):void
{
trace( e.toString());
}
function onLoaded(e:Event):void
{
trace(uld.data);
}如果返回securityError,可能需要配置host。
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。