ios有wsdl调用webservicee wsdl数据怎么处理

iOS --调用webservice接口 - 简书
iOS --调用webservice接口
其实小兵今天写这个东西,主要是为了以后的小伙伴遇到调用WebService接口,主要介绍了如何用IOS调用WebService(SOAP接口),需要的朋友可以参考下,在一次项目开发过程中,用到IOS调用WebService接口,所以抽个空把这方面的内容给大家整理出来,分享给大家。
Web Service基本概念
Web Service也叫XML Web Service WebService,是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的独立的通讯技术。是:通过SOAP在Web上提供的软件服务,使用WSDL文件进行说明,并通过UDDI进行注册。
Soap:(Simple Object Access Protocol)简单对象存取协议。是XML Web Service 的通信协议。当用户通过UDDI找到你的WSDL描述文档后,他通过可以SOAP调用你建立的Web服务中的一个或多个操作。SOAP是XML文档形式的调用方法的规范,它可以支持不同的底层接口,像HTTP(S)或者SMTP。
XML Web Service的特点
Web Service的主要目标是跨平台的可互操作性。为了实现这一目标,Web Service 完全基于XML(可扩展标记语言)、XSD(XML Schema)等独立于平台、独立于软件供应商的标准,是创建可互操作的、分布式应用程序的新平台。因此使用Web Service有许多优点:1、跨防火墙的通信2、应用程序集成3、B2B的集成4、软件和数据重用
Firefox浏览器中输入webService接口地址结构截图.png
主要代码:
增加企业信息注册号、企业名称、企业类型、法人、资本总额、注册日期、住所、
期限自、期限止、营业范围、登记机关、核准日期、状态
@param sender
- (IBAction)Addnewbusinessinfo:(id)sender {
NSString *webServiceBodyStr = [NSString stringWithFormat:
@"&Addnewbusinessinfo xmlns=\"http://tempuri.org/\"&"
"&registerNum&%@&/registerNum&"
"&Enterprisename&%@&/Enterprisename&"
"&Typeofenterprise&%@&/Typeofenterprise&"
"&Legalrepresentative&%@&/Legalrepresentative&"
"&capital&%f&/capital&"
"&dateofestablishment&%@&/dateofestablishment&"
"&domicile&%@&/domicile&"
"&DateB&%@&/DateB&"
"&DateE&%@&/DateE&"
"&Businessscope&%@&/Businessscope&"
"&registrationauthority&%@&/registrationauthority&"
"&Approveddate&%@&/Approveddate&"
"&state&%d&/state&"
"&/Addnewbusinessinfo&",
@"1111",@"****",@"民营",@"张三",1234.1,
@"T23:21:20",@"亦庄",
@"T23:21:20",@"T23:21:20",
@"建筑",@"北京 亦庄 张三",@"T23:21:20",true];//这里是参数
NSString *webServiceStr = [NSString stringWithFormat:
@"&?xml version=\"1.0\" encoding=\"utf-8\"?&\n"
"&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/\"&\n"
"&soap:Body&\n"
"&/soap:Body&\n"
"&/soap:Envelope&",
webServiceBodyStr];//webService头
NSString *path = @"http://168.168.5.120:8888/seal.asmx?op=Addnewbusinessinfo";
NSURL *url = [NSURL URLWithString:path];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%ld", webServiceStr.length];
[theRequest addValue:@"text/ charset=utf-8" forHTTPHeaderField:@"Content-type"];
[theRequest addValue:SOAPActionStr forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[webServiceStr dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionTask *task = [session dataTaskWithURL:theRequest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSURLSessionTask *task = [session dataTaskWithRequest:theRequest completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSLog(@"%@-",response);
NSLog(@"%@---askl",error);
NSLog(@"%@ -- data",data);
//系统自带的
NSXMLParser *par = [[NSXMLParser alloc] initWithData:data];
[par setDelegate:self];//设置NSXMLParser对象的解析方法代理
[par parse];//调用代理解析NSXMLParser对象,看解析是否成功
[task resume];
.net后台webservice接收参数的问题
//datetime 参数,参数值拼接@“T”
"&time&%@&/time&"
@"T23:21:20"
//blob 参数
"&state&%@&/state&"
//base64Encoded 参数,(传入图片,NSData类型)
"&img&%@&/img&"
[self base64EncodedPathForResource:@"a4"];
@param aPathForResource &#aPathForResource description#&
@return &#return value description#&
// Create NSData object
NSData *nsdata = [@"123456"
dataUsingEncoding:NSUTF8StringEncoding];
// Get NSString from NSData object in Base64
NSString *base64Encoded = [nsdata base64EncodedStringWithOptions:0];
// Print the Base64 encoded string
NSLog(@"Encoded: %@", base64Encoded);
// Let's go the other way...
// NSData from the Base64 encoded str
NSData *nsdataFromBase64String = [[NSData alloc]
initWithBase64EncodedString:base64Encoded options:0];
// Decoded NSString from the NSData
NSString *base64Decoded = [[NSString alloc]
initWithData:nsdataFromBase64String encoding:NSUTF8StringEncoding];
NSLog(@"Decoded: %@", base64Decoded);
- (NSString *)base64EncodedPathForResource:(NSString *)aPathForResource
NSString *imgPath = [[NSBundle mainBundle] pathForResource:aPathForResource ofType:@"jpg"];
NSData *data = [NSData dataWithContentsOfFile:imgPath];
NSString *base64Encoded = [data base64EncodedStringWithOptions:0];
return base64E
随手点个喜欢吧~
QQ--iOS 交流群:主题 : ios调用webservice wsdl数据怎么处理呢?
级别: 禁止发言
UID: 488965
可可豆: 21 CB
威望: 16 点
在线时间: 2(时)
发自: Web Page
用户被禁言,该主题自动屏蔽!
级别: 侠客
UID: 157406
可可豆: 918 CB
威望: 721 点
在线时间: 726(时)
发自: Web Page
&&&&NSString *soapMsg = [NSString stringWithFormat:@&&?xml version=\&1.0\& encoding=\&utf-8\&?&\n&&&&&&&&&&&&&&&&&&&&& &&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/\& xmlns:m=\&/bizrelay\&&\n&&&&&&&&&&&&&&&&&&&&& &&soap:Body&\n&&&&&&&&&&&&&&&&&&&&& &&m:getXXX&\n&&&&&&&&&&&&&&&&&&&&& &&参数1的key&%@&/参数1的key&\n&&&&&&&&&&&&&&&&&&&&& &&参数2的key&%@&/参数2的key&\n&&&&&&&&&&&&&&&&&&&&& &&/m:getXXX&\n&&&&&&&&&&&&&&&&&&&&& &&/soap:Body&\n&&&&&&&&&&&&&&&&&&&&& &&/soap:Envelope&&,@&参数1的value&,@&参数2的value&&&&&&&&&&&&&&&&&&&&& ];试试吧,希望能帮到你,至于上传图片信息,可将图片转化成base64格式的数据流
不积跬步,无以至千里
级别: 禁止发言
UID: 488965
可可豆: 21 CB
威望: 16 点
在线时间: 2(时)
发自: Web Page
用户被禁言,该主题自动屏蔽!
级别: 侠客
UID: 157406
可可豆: 918 CB
威望: 721 点
在线时间: 726(时)
发自: Web Page
回 2楼(xiaoyuren) 的帖子
谁开发的这个webservice,你可以问他,传什么参数
不积跬步,无以至千里
级别: 禁止发言
UID: 488965
可可豆: 21 CB
威望: 16 点
在线时间: 2(时)
发自: Web Page
用户被禁言,该主题自动屏蔽!
级别: 侠客
UID: 157406
可可豆: 918 CB
威望: 721 点
在线时间: 726(时)
发自: Web Page
回 4楼(xiaoyuren) 的帖子
&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/\& xmlns:m=\&/bizrelay\&&\n这里面的xmlns:m=\后面的要换成你自己的namespace的,我忘记提醒你了
不积跬步,无以至千里
关注本帖(如果有新回复会站内信通知您)
苹果公司现任CEO是谁?2字 正确答案:库克
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版君,已阅读到文档的结尾了呢~~
loadrunner12.0使用帮助
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
loadrunner12.0使用帮助
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口注:1、结合Web Service笔记(二):利用CXF开发Web Service
一、WSDL语言:(web service definition language - web service定义语言)
(一)简介:
1、wsdl 是全完基于xml 的,特别是xml schema。详见:&XML学习笔记(三):XML规范:Schema详解。
2、wsdl 文档描述了 ws 主要的3个方面:
1)WHATA:该 ws 包含”什么“操作,即有几个方法。
2)HOW:该 ws 的操作应该”怎样“调用?
3)WHERE:该 ws 的服务地址。
3、详细的 wsdl 文件如下,给予Web Service笔记(二):利用CXF开发Web Service&的服务和客户端。
1)实现类的 wsdl 地址为:http://localhost:8080/helloWorld?wsdl&。内容如下:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
&wsdl:definitions xmlns:xsd=&http://www.w3.org/2001/XMLSchema& xmlns:wsdl=&http://schemas.xmlsoap.org/wsdl/& xmlns:tns=&/& xmlns:soap=&http://schemas.xmlsoap.org/wsdl/soap/& xmlns:ns2=&http://schemas.xmlsoap.org/soap/http& xmlns:ns1=&http://ws.com/& name=&HelloSAM& targetNamespace=&/&&
&wsdl:import location=&http://localhost:8080/helloWorld?wsdl=HelloWorld.wsdl& namespace=&http://ws.com/&&&/wsdl:import&
&wsdl:binding name=&HelloSAMSoapBinding& type=&ns1:HelloWorld&&
&soap:binding style=&document& transport=&http://schemas.xmlsoap.org/soap/http&/&
&wsdl:operation name=&sayHi&&
&soap:operation soapAction=&& style=&document&/&
&wsdl:input name=&sayHi&&
&soap:body use=&literal&/&
&/wsdl:input&
&wsdl:output name=&sayHiResponse&&
&soap:body use=&literal&/&
&/wsdl:output&
&/wsdl:operation&
&wsdl:operation name=&getCatsByUser&&
&soap:operation soapAction=&& style=&document&/&
&wsdl:input name=&getCatsByUser&&
&soap:body use=&literal&/&
&/wsdl:input&
&wsdl:output name=&getCatsByUserResponse&&
&soap:body use=&literal&/&
&/wsdl:output&
&/wsdl:operation&
&/wsdl:binding&
&wsdl:service name=&HelloSAM&&
&wsdl:port binding=&tns:HelloSAMSoapBinding& name=&HelloWorldImplPort&&
&soap:address location=&http://localhost:8080/helloWorld&/&
&/wsdl:port&
&/wsdl:service&
&/wsdl:definitions&
& 2)接口的 wsdl 地址为: http://localhost:8080/helloWorld?wsdl=HelloWorld.wsdl & 。内容如下:&
This XML file does not appear to have any style information associated with it. The document tree is shown below.
&wsdl:definitions xmlns:xsd=&http://www.w3.org/2001/XMLSchema& xmlns:wsdl=&http://schemas.xmlsoap.org/wsdl/& xmlns:ns1=&http://ws.com/& name=&HelloWorld& targetNamespace=&http://ws.com/&&
&wsdl:types&
&xs:schema xmlns:xs=&http://www.w3.org/2001/XMLSchema& xmlns:tns=&http://ws.com/& elementFormDefault=&unqualified& targetNamespace=&http://ws.com/& version=&1.0&&
&xs:element name=&getCatsByUser& type=&tns:getCatsByUser&/&
&xs:element name=&getCatsByUserResponse& type=&tns:getCatsByUserResponse&/&
&xs:element name=&sayHi& type=&tns:sayHi&/&
&xs:element name=&sayHiResponse& type=&tns:sayHiResponse&/&
&xs:complexType name=&sayHi&&
&xs:sequence&
&xs:element minOccurs=&0& name=&arg0& type=&xs:string&/&
&/xs:sequence&
&/xs:complexType&
&xs:complexType name=&sayHiResponse&&
&xs:sequence&
&xs:element minOccurs=&0& name=&return& type=&xs:string&/&
&/xs:sequence&
&/xs:complexType&
&xs:complexType name=&getCatsByUser&&
&xs:sequence&
&xs:element minOccurs=&0& name=&arg0& type=&tns:user&/&
&/xs:sequence&
&/xs:complexType&
&xs:complexType name=&user&&
&xs:sequence&
&xs:element minOccurs=&0& name=&address& type=&xs:string&/&
&xs:element minOccurs=&0& name=&id& type=&xs:int&/&
&xs:element minOccurs=&0& name=&name& type=&xs:string&/&
&xs:element minOccurs=&0& name=&pass& type=&xs:string&/&
&/xs:sequence&
&/xs:complexType&
&xs:complexType name=&getCatsByUserResponse&&
&xs:sequence&
&xs:element maxOccurs=&unbounded& minOccurs=&0& name=&return& type=&tns:cat&/&
&/xs:sequence&
&/xs:complexType&
&xs:complexType name=&cat&&
&xs:sequence&
&xs:element minOccurs=&0& name=&color& type=&xs:string&/&
&xs:element minOccurs=&0& name=&id& type=&xs:int&/&
&xs:element minOccurs=&0& name=&name& type=&xs:string&/&
&/xs:sequence&
&/xs:complexType&
&/xs:schema&
&/wsdl:types&
&wsdl:message name=&getCatsByUserResponse&&
&wsdl:part element=&ns1:getCatsByUserResponse& name=&parameters&&&/wsdl:part&
&/wsdl:message&
&wsdl:message name=&sayHiResponse&&
&wsdl:part element=&ns1:sayHiResponse& name=&parameters&&&/wsdl:part&
&/wsdl:message&
&wsdl:message name=&getCatsByUser&&
&wsdl:part element=&ns1:getCatsByUser& name=&parameters&&&/wsdl:part&
&/wsdl:message&
&wsdl:message name=&sayHi&&
&wsdl:part element=&ns1:sayHi& name=&parameters&&&/wsdl:part&
&/wsdl:message&
&wsdl:portType name=&HelloWorld&&
&wsdl:operation name=&sayHi&&
&wsdl:input message=&ns1:sayHi& name=&sayHi&&&/wsdl:input&
&wsdl:output message=&ns1:sayHiResponse& name=&sayHiResponse&&&/wsdl:output&
&/wsdl:operation&
&wsdl:operation name=&getCatsByUser&&
&wsdl:input message=&ns1:getCatsByUser& name=&getCatsByUser&&&/wsdl:input&
&wsdl:output message=&ns1:getCatsByUserResponse& name=&getCatsByUserResponse&&&/wsdl:output&
&/wsdl:operation&
&/wsdl:portType&
&/wsdl:definitions&
(二)语法详解:
1、根元素:definitions&
1)targetNamespace :相当于java的&package 。
如 服务端实现类与 wsdl 文件的&targetNamespace&为 如下,应该是一致的。
package com.ws.//实现类的包
targetNamespace=&/&//wsdl的targetNamespace
2)xmlns :遵守的命名空间的schema 文件,相当于java的&import 。即本文档引进了这个schema规范,需要遵守它的语法。可以有别名,用来区分引进不同的schema规范。
xmlns:xsd=&http://www.w3.org/2001/XMLSchema&//xsd为别名
3)import :导入的接口文件。通过 namespase的路径也可以看出。
&wsdl:import location=&http://localhost:8080/helloWorld?wsdl=HelloWorld.wsdl& namespace=&http://ws.com/&&&/wsdl:import&
2、WS接口的wsdl语法。wsdl 显示的服务端内容都在此。
1)types元素 :该元素内容是标准的xml Schema文档 。
&wsdl:types&
&xs:schema xmlns:xs=&http://www.w3.org/2001/XMLSchema& xmlns:tns=&http://ws.com/& elementFormDefault=&unqualified& targetNamespace=&http://ws.com/& version=&1.0&&
&xs:element name=&getCatsByUser& type=&tns:getCatsByUser&/&
&xs:element name=&getCatsByUserResponse& type=&tns:getCatsByUserResponse&/&
&xs:element name=&sayHi& type=&tns:sayHi&/&
&xs:element name=&sayHiResponse& type=&tns:sayHiResponse&/&
&xs:complexType name=&sayHi&&
&xs:sequence&
&xs:element minOccurs=&0& name=&arg0& type=&xs:string&/&
&/xs:sequence&
&/xs:complexType&
&xs:complexType name=&sayHiResponse&&
&xs:sequence&
&xs:element minOccurs=&0& name=&return& type=&xs:string&/&
&/xs:sequence&
&/xs:complexType&
&xs:complexType name=&getCatsByUser&&
&xs:sequence&
&xs:element minOccurs=&0& name=&arg0& type=&tns:user&/&
&/xs:sequence&
&/xs:complexType&
&xs:complexType name=&user&&
&xs:sequence&
&xs:element minOccurs=&0& name=&address& type=&xs:string&/&
&xs:element minOccurs=&0& name=&id& type=&xs:int&/&
&xs:element minOccurs=&0& name=&name& type=&xs:string&/&
&xs:element minOccurs=&0& name=&pass& type=&xs:string&/&
&/xs:sequence&
&/xs:complexType&
&xs:complexType name=&getCatsByUserResponse&&
&xs:sequence&
&xs:element maxOccurs=&unbounded& minOccurs=&0& name=&return& type=&tns:cat&/&
&/xs:sequence&
&/xs:complexType&
&xs:complexType name=&cat&&
&xs:sequence&
&xs:element minOccurs=&0& name=&color& type=&xs:string&/&
&xs:element minOccurs=&0& name=&id& type=&xs:int&/&
&xs:element minOccurs=&0& name=&name& type=&xs:string&/&
&/xs:sequence&
&/xs:complexType&
&/xs:schema&
&/wsdl:types&
2)message元素:有2N个message元素,需要有传入传出消息。如服务端方法public String sayHi(String name){}方法:
&wsdl:message name=&getCatsByUserResponse&&
&wsdl:part element=&ns1:getCatsByUserResponse& name=&parameters&&&/wsdl:part&
&/wsdl:message&
&wsdl:message name=&sayHiResponse&&
&wsdl:part element=&ns1:sayHiResponse& name=&parameters&&&/wsdl:part&
&/wsdl:message&
&wsdl:message name=&getCatsByUser&&
&wsdl:part element=&ns1:getCatsByUser& name=&parameters&&&/wsdl:part&
&/wsdl:message&
&span style=&color:#ff0000;&&&wsdl:message name=&sayHi&&
&wsdl:part element=&ns1:sayHi& name=&parameters&&&/wsdl:part&
&/wsdl:message&&/span&
①、message 元素中有name等于&sayHi 的属性。可以理解为 一个&sayHi 的消息。
②、子元素 part中有element属性为&sayHi 。理解为&sayHi的消息需要一个&sayHi 的元素(element)。这个元素在上面的 type 中会有定义。
3)portType元素: N个operation子元素,每个operation代表一个ws操作(即方法),包含请求与回复2次。
&wsdl:portType name=&HelloWorld&&
&wsdl:operation name=&sayHi&&
&wsdl:input message=&ns1:sayHi& name=&sayHi&&&/wsdl:input&
&wsdl:output message=&ns1:sayHiResponse& name=&sayHiResponse&&&/wsdl:output&
&/wsdl:operation&
&wsdl:operation name=&getCatsByUser&&
&wsdl:input message=&ns1:getCatsByUser& name=&getCatsByUser&&&/wsdl:input&
&wsdl:output message=&ns1:getCatsByUserResponse& name=&getCatsByUserResponse&&&/wsdl:output&
&/wsdl:operation&
&/wsdl:portType&
①、服务端有两个操作的方法&sayHi() 和&getCatsByUser() ,在&portType 元素中就会有 2个&operation ,分别为&sayHi 和&getCatsByUser 。
②、每个&operation元素中有input 和 output 子元素,定义了这次操作需要的 message元素信息,在上面定义。
4)显而易见,这边有一定的依赖关系存在:一个 WS 服务端实现类,定义了多个方法(operation元素),方法的调用需要明确传入传出参数,被定义在message元素中,称为消息。每个定义的消息有依赖于element元素,定义在 types 中,是一份标准的 schema。
5)整个接口的&wsdl 由于上述依赖的关系,可以倒过来分析:如方法public List&Cat& getCatsByUser(User user) {},其实其本质规定了调用该方法传入参数的类型与规范。
①、一个接口,定义方法为&getCatsByUser。wsdl 定义为:一个&portType 为&HelloWorld 的接口,有名为&getCatsByUser&的&operation,即有这个方法可调用。这个方法需要name为&getCatsByUser& 和 getCatsByUserResponse&的 message 元素(input 和 output ),代表了这个方法的传入与传出消息(即方法的参数)。
②、方法的传入传出参数。message 元素中规定这个&getCatsByUser& 的传入消息实际内容在名为&getCatsByUser&的element元素中,element元素定义在types元素中。
③、element元素中规定&getCatsByUser& 遵守名字为getCatsByUser& 的schema语法定义,使用type关键字实现sechema语法的复用。
④、名字为&getCatsByUser& 的&schema定义为:complex为复杂类型,0-1个,sequesce指要有顺序,type指向名字为 user 的schema定义。
⑤、名字为&user&的&schema定义为: 有顺利的四个元素,分别为address、id、name、pass,出现0-1次。
4、本质:一个ws,其实并不是方法的调用,而是发送soap消息(即xml文档片段)
1)客户端把调用的方法参数,转换生成xml文档片段(soap消息)??必须符合wsdl规定的格式
2)客户端通过网络,把xml文档片段传给服务器。
3)服务器接收到xml文档片段。
4)服务器解析xml文档片段,提取其中的数据。返回xml文档。
如getCatsByUser(User user) 方法,传入传出的是这样的xml片段:
&!--传入的参数--&
&getCatsByUser&
&address&&/address&
&name&&/name&
&pass&&/pass&
&/getCatsByUser&
&!--返回的参数--&
&getCatsByUserResponse&
&color&&/color&
&name&&/name&
&color&&/color&
&name&&/name&
&/getCatsByUserResponse&
3、WS实现类:
1)、binding:指定ws的函数风格,并详细的定义了接口中的操作即&operation&。函数风格,现在一般为 document 文档风格。
&wsdl:binding name=&HelloSAMSoapBinding& type=&ns1:HelloWorld&&
&soap:binding &span style=&color:#ff0000;&&style=&document& &/span&transport=&http://schemas.xmlsoap.org/soap/http&/&
&&span style=&color:#ff0000;&&wsdl:operation &/span&name=&sayHi&&
&soap:operation soapAction=&& style=&document&/&
&wsdl:input name=&sayHi&&
&soap:body use=&literal&/&
&/wsdl:input&
&wsdl:output name=&sayHiResponse&&
&soap:body use=&literal&/&
&/wsdl:output&
&/wsdl:operation&
&wsdl:operation name=&getCatsByUser&&
&soap:operation soapAction=&& style=&document&/&
&wsdl:input name=&getCatsByUser&&
&soap:body use=&literal&/&
&/wsdl:input&
&wsdl:output name=&getCatsByUserResponse&&
&soap:body use=&literal&/&
&/wsdl:output&
&/wsdl:operation&
&/wsdl:binding&
2)、service:name-定义了ws的名称,即代码中使用&serviceName 指定的名称,port【address】-定义ws绑定的地址。
&wsdl:service name=&HelloSAM&&
&wsdl:port binding=&tns:HelloSAMSoapBinding& name=&HelloWorldImplPort&&
&soap:address location=&http://localhost:8080/helloWorld&/&
&/wsdl:port&
&/wsdl:service&
二、SOAP语言(简单访问对象协议)
(一)通过使用CXF的日志拦截器,我们可以在控制台输出拦截器的soap消息。服务端拦截如下:
1、sayHi()操作的soap消息:
{Accept=[text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2],
connection=[keep-alive],
Content-Length=[186],
content-type=[text/ charset=UTF-8],
Host=[localhost:8080],
SOAPAction=[&&],
User-Agent=[Java/1.6.0_10-rc2]}
&?xml version=&1.0& ?&
&S:Envelope xmlns:S=&http://schemas.xmlsoap.org/soap/envelope/&&
&ns2:sayHi xmlns:ns2=&http://ws.com/&&
&arg0&SAM-SHO&/arg0&
&/ns2:sayHi&
&/S:Envelope&
Headers: {}
&soap:Envelope xmlns:soap=&http://schemas.xmlsoap.org/soap/envelope/&&
&soap:Body&
&ns2:sayHiResponse xmlns:ns2=&http://ws.com/&&
&return&SAM-SHO,您好!您现在访问的是简单的WS服务端,时间为:14-11-20 下午1:28&/return&
&/ns2:sayHiResponse&
&/soap:Body&
&/soap:Envelope&
2、getCatsByUser()操作的soap消息:与上面wsdl分析的消息应该是一致的。
&?xml version=&1.0& ?&
&S:Envelope xmlns:S=&http://schemas.xmlsoap.org/soap/envelope/&&
&ns2:getCatsByUser xmlns:ns2=&http://ws.com/&&
&address&soochow&/address&
&id&1&/id&
&name&Sam-Sho&/name&
&pass&1234&/pass&
&/ns2:getCatsByUser&
&/S:Envelope&
&soap:Envelope xmlns:soap=&http://schemas.xmlsoap.org/soap/envelope/&&
&soap:Body&
&ns2:getCatsByUserResponse xmlns:ns2=&http://ws.com/&&
&color&黄色&/color&
&id&1&/id&
&name&加菲猫&/name&
&color&蓝色&/color&
&id&2&/id&
&name&蓝胖子&/name&
&color&粉色&/color&
&id&3&/id&
&name&hello kitty&/name&
&color&黑白色&/color&
&id&4&/id&
&name&熊猫&/name&
&/ns2:getCatsByUserResponse&
&/soap:Body&
&/soap:Envelope&
(二)soap语法
&soap:Envelope xmlns:soap=&http://schemas.xmlsoap.org/soap/envelope/&&
&soap:Header&
&!--可能会有Header元素--&
&/soap:Header&
&soap:Body&
&ns2:sayHiResponse xmlns:ns2=&http://ws.com/&&
&return&SAM-SHO,您好!您现在访问的是简单的WS服务端,时间为:14-11-20 下午1:28&/return&
&/ns2:sayHiResponse&
&/soap:Body&
&/soap:Envelope&
1、根元素:Envelope。
2、Header元素::不是强制出现,由程序员控制,主要用于携带一些额外的信息,比如用户名、密码
1)调用正确,body元素内容应该遵守WSDL要求的格式。
&soap:Envelope xmlns:soap=&http://schemas.xmlsoap.org/soap/envelope/&&
&soap:Body&
&ns2:sayHiResponse xmlns:ns2=&http://ws.com/&&
&return&SAM,您好现在的时间是:Thu Jan 09 10:19:57 CST 2014&/return&
&/ns2:sayHiResponse&
&/soap:Body&
&/soap:Envelope&
2)调用错误,body元素内容显示Faulty元素。
&soap:Fault&
&faultcode&soap:Server&/faultcode&
&faultstring&
No binding operation info while invoking unknown method with params unknown.
&/faultstring&
&/soap:Fault&
&/soap:Body&
4、return:返回信息。
三、UDDI(可以省略)

我要回帖

更多关于 有wsdl调用webservice 的文章

 

随机推荐