当前位置:首页 » 网页前端 » webserviceios
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

webserviceios

发布时间: 2022-05-16 05:25:35

❶ IOS请求webservice,webservice是C#的,如何返回JSON

webservice这个好像不直接支持json的,一个比较好的替代方法是在C#端先把返回值序列化成json字符串在返回了,
但是这可能会限制程序的易用性和伸缩性,不过要是仅仅简单的返回数据的话,应该没有任何问题,这个可能需要你定义一些简单的协议

❷ webservice,android访问没问题,ios访问报错、、、webservice服务端是用Java实现的 错误如下:

你能抓到发送到服务端的SOAP报文么?
这个异常通常都是SOAP报文内容有问题导致的
可能是报文字符串编码不对也可能是报文的格式结构不对导致的服务端无法解析

❸ IOS 开发 webservice soap的请求

1. 改成同步
2. 用代码控制当异步执行后得到结果后再执行 下面的代码

❹ ios用webservice接口传参数出现: 意外的元素

很明显了,人家需要的是 arg1 和 arg0, 你给了userName, 人家当然报错了,

是不是服务端 没有对变量 标识 @webParam(name="userName")

❺ 在ios中webseriver还在用吗

1.开启Xcode创建一个项目,项目类型选择Single View Application。
2.创建三个Group,并导入上述三个库。
JSON:将JSON\Classes目录的文件托入刚才创建的JSON GROUP。
ASIHTTPRequest:将ASIHTTPRequest\Classes目录的所有文件拖入创建的ASIHTTPRequest GROUP(注意,只要当前目录的文件,CloudFiles之类的目录不需要)
ASIHTTPRequest\External\Reachability这里的文件也要加进来
MBProgressHUD:将MBProgressHUD.m和MBProgressHUD.h拖入MBProgressHUD GROUP
以上三个操作,拖入的时候,记得勾选Copy items into destination group’s folder (if needed)选项,意思是把目录复制到你的项目中,而不是只引用。
3.导入一些必要的frameworks:点击左侧导航栏中你的项目->选中target->再选择build phases栏0->Link Binary with Libraries。点击+按钮,搜索CFNetwork.framework and SystemConfiguration.framework,MobileCoreServices.framework, and libz.1.2.3.dylib四个库。
以上三个大步骤完成后,点击编译。完成第一个阶段。

二、实现Interface
创建UI: 1.label
2.textfield
3.textview

三、与WebService交互
我们的Web Service需要三个参数:
rw_app_id: 应用的唯一标识号. If you’ve been following along with the previous tutorial, there should be only one entry so far, App ID #1.
code: The code to attempt to redeem. This should be a string that’s entered by the user.
device_id: The device ID that is attempting to redeem this code. We can get this with an easy API call
我们需要使用POST机制请求WebService。ASIHTTPRequest将使这一过程变得很便捷。
1.创建一个ASIFormDataRequest实例与URL
2.使用setPostValue方法指定各个参数
3.设置viewcontroller为request的delegate,之后调用startAsynchronous来发起异步请求
4.当请求完毕后,requestFinished或者requestFailed会被回调
5.requestFinished无论webservice相应一个错误的代码,或者正确响应,都会被调用,所以在这个函数里要检查请求成功或者失败
6.如果一切顺利,再解析收到的JSON数据

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSLog(@"Want to redeem: %@", textField.text);

// Get device unique ID
UIDevice *device = [UIDevice currentDevice];
NSString *uniqueId= [device uniqueIdentifier];

// Start request
NSString *code = textField.text;
NSURL *url = [NSURL URLWithString:@"http://www.wildfables.com/promos/"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"1" forKey:@"rw_app_id"];
[request setPostValue:code forKey:@"code"];
[request setPostValue:uniqueId forKey:@"device_id"];
[request setDelegate:self];
[request startAsynchronous];

// Hide keyword
[textField resignFirstResponder];

// Clear text field
textView.text = @"";

//状态指示器
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText = @"Redeeming code...";
return TRUE;
}

/*请求完成后回调*/
- (void)requestFinished:(ASIHTTPRequest *)request
{
[MBProgressHUD hideHUDForView:self.view animated:YES];

if (request.responseStatusCode == 400) {
textView.text = @"Invalid code";
} else if (request.responseStatusCode == 403) {
textView.text = @"Code already used";
} else if (request.responseStatusCode == 200) {
NSString *responseString = [request responseString];
NSDictionary *responseDict = [responseString JSONValue];
NSString *unlockCode = [responseDict objectForKey:@"unlock_code"];

if ([unlockCode compare:@"com.razeware.test.unlock.cake"] == NSOrderedSame) {
textView.text = @"The cake is a lie!";
} else {
textView.text = [NSString stringWithFormat:@"Received unexpected unlock code: %@", unlockCode];
}

} else {
textView.text = @"Unexpected error";
}

}
/*请求失败后回调*/
- (void)requestFailed:(ASIHTTPRequest *)request
{
[MBProgressHUD hideHUDForView:self.view animated:YES];

NSError *error = [request error];
textView.text = error.localizedDescription;
}

为了让用户感受到,在请求数据的时候,程序在运行,而不是假死,所以要添加状态指示器。
三个步骤
// Add at the top of the file#import "MBProgressHUD.h"

// Add right before return TRUE in textFieldShouldReturn
MBProgressHUD *hud =[MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText =@"Redeeming code...";

// Add at start of requestFinished AND requestFailed
[MBProgressHUD hideHUDForView:self.view animated:YES];
编译运行,大功告成。

❻ ios,webservice传过来的xml数据用自带的xmlparser解析,怎么让它成list样式

通过web服务传递的数据的序列号为字符串或字节,建议字符串,除非图片等可以考虑字节流。 传统的json或xml都可以的,直接传递list得转换下才可以。

❼ iOS请求webservice接口,参数类型是buffer流,怎么破

数据流在ios客户端向服务器端提交数据时使用的类型可以用NSData. 这需要你将客户端要提交的数据先转成NSData类型。如我们在ios客户端向服务器端上传图片时,就需要将UIImage对象转成NSData并提交到服务器端。

❽ 如何用IOS调用WebService

ava调用WebService可以直接使用Apache提供的axis.jar自己编写代码,或者利用Eclipse自动生成WebService Client代码,利用其中的Proxy类进行调用。理论上是一样的,只不过用Eclipse自动生成代码省事些。
1、编写代码方式:
package com.yun.test;
import java.rmi.RemoteException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.PrefixedQName;
import org.apache.axis.message.SOAPHeaderElement;
import com.cezanne.golden.user.Exception;
import com.cezanne.golden.user.UserManagerServiceProxy;
import javax.xml.namespace.QName;
import java.net.MalformedURLException;
import javax.xml.rpc.ServiceException;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPException;

public class testWebService {
public static String getResult() throws ServiceException, MalformedURLException, RemoteException, SOAPException
{
//标识Web Service的具体路径
String endpoint = "WebService服务地址";
// 创建 Service实例
Service service = new Service();
// 通过Service实例创建Call的实例
Call call = (Call) service.createCall();
//将Web Service的服务路径加入到call实例之中.
call.setTargetEndpointAddress( new java.net.URL(endpoint) );//为Call设置服务的位置
// 由于需要认证,故需要设置调用的SOAP头信息。
Name headerName = new PrefixedQName( new QName("发布的wsdl里的targetNamespace里的url", "string_itemName") );
org.apache.axis.message.SOAPHeaderElement header = new SOAPHeaderElement(headerName);
header.addTextNode( "blablabla" );
call.addHeader(header);

// SOAPHeaderElement soapHeaderElement = new SOAPHeaderElement("发布的wsdl里的targetNamespace里的url", "SoapHeader");
// soapHeaderElement.setNamespaceURI("发布的wsdl里的targetNamespace里的url");
// try
// {
// soapHeaderElement.addChildElement("string_itemName").setValue("blablabla");
// }
// catch (SOAPException e)
// {
// e.printStackTrace();
// }
// call.addHeader(soapHeaderElement);
//调用Web Service的方法
org.apache.axis.description.OperationDesc oper;
org.apache.axis.description.ParameterDesc param;
oper = new org.apache.axis.description.OperationDesc();
oper.setName("opName");
param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "arg0"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), java.lang.String.class, false, false);
param.setOmittable(true);
oper.addParameter(param);
param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "arg1"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), java.lang.String.class, false, false);
param.setOmittable(true);
oper.addParameter(param);
param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("", "arg2"), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"), java.lang.String.class, false, false);
param.setOmittable(true);
oper.addParameter(param);
oper.setReturnType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
oper.setReturnClass(java.lang.String.class);
oper.setReturnQName(new javax.xml.namespace.QName("", "return"));
oper.setStyle(org.apache.axis.constants.Style.WRAPPED);
oper.setUse(org.apache.axis.constants.Use.LITERAL);
oper.addFault(new org.apache.axis.description.FaultDesc(
new javax.xml.namespace.QName("发布的wsdl里的targetNamespace里的url", "Exception"),
"Exception",
new javax.xml.namespace.QName("发布的wsdl里的targetNamespace里的url", "Exception"),
true
));
call.setOperation( oper );
call.setOperationName(new javax.xml.namespace.QName("发布的wsdl里的targetNamespace里的url", "opName"));
//调用Web Service,传入参数
String res = ( String ) call.invoke( new Object[]("arg0","arg1"));
System.out.println("===============");
return res;
}
/**
* @param args
*/
public static void main(String[] args) {
try {
System.out.println(getResult());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (ServiceException e) {
e.printStackTrace();
} catch (SOAPException e) {
e.printStackTrace();
}
}
}

2、利用Eclipse自动生成WebService client代码就容易多了:(由于还不会发图片,就用语言描述了,大家酬和看吧。。。)
首先,new project,选择other,在输入框中输入Web Service Client,选中搜索后的结果,点击Next,在Service definition中输入 WebService的发布地址,点击Finish
这样,WebService Client代码已经生成好了。
接下来写一个Test类,在main函数中输入如下代码:

String endpoint = "服务器的WebService的地址";
YourWebServiceNameProxy umsp = new YourWebServiceNameProxy (endpoint);
try {
String resultStr = umsp.opMethod("arg0","arg1");
System.out.println(resultStr);
} catch (Exception e) {
System.out.println("异常");
e.printStackTrace();
} catch (RemoteException e) {
System.out.println("RemoteException异常");
e.printStackTrace();
}

❾ 后台webservice,前台是iOS,在调用借口时出错,500,有没有工具可以直接测试接口,就像是postman

soapUI,接口自动化测试工具

❿ ios请求webservice接口的时候,soap请求体怎么弄的

好了,假设现在你已经有关于soap的基础知识(没有也没关系,看了例子,再理解就更好理解了),下面我们开始做soap的例子.

第一步,建一个Hello_SOAP项目.

然后在Hello_SOAPViewController.h中添加如下代码
@interface Hello_SOAPViewController : UIViewController

{

IBOutlet UITextField *nameInput;

IBOutlet UILabel *greeting;

NSMutableData *webData;

NSMutableString *soapResults;

NSXMLParser *xmlParser;

BOOL recordResults;

}

@property(nonatomic, retain) IBOutlet UITextField *nameInput;

@property(nonatomic, retain) IBOutlet UILabel *greeting;

@property(nonatomic, retain) NSMutableData *webData;

@property(nonatomic, retain) NSMutableString *soapResults;

@property(nonatomic, retain) NSXMLParser *xmlParser;

-(IBAction)buttonClick: (id) sender;

- (void)getOffesetUTCTimeSOAP;

然后在Hello_SOAPViewController.xib中将两个输出口和一个动作连接好,这个不用手把手吧?
在Hello_SOAPViewController.m文件中加入以下方法 :

- (void)getOffesetUTCTimeSOAP

{

recordResults = NO;

//封装soap请求消息

NSString *soapMessage = [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"

"<getOffesetUTCTime
xmlns=\"http://www.Nanonull.com/TimeService/\">\n"

"<hoursOffset>%@</hoursOffset>\n"

"</getOffesetUTCTime>\n"

"</soap:Body>\n"

"</soap:Envelope>\n",nameInput.text

];

NSLog(soapMessage);

//请求发送到的路径

NSURL *url = [NSURL URLWithString:@"http://www.nanonull.com/TimeService/TimeService.asmx"];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

//以下对请求信息添加属性前四句是必有的,第五句是soap信息。

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

[theRequest addValue: @"http://www.Nanonull.com/TimeService/getOffesetUTCTime" forHTTPHeaderField:@"SOAPAction"];

[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];

[theRequest setHTTPMethod:@"POST"];

[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

//请求

NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

//如果连接已经建好,则初始化data

if( theConnection )

{

webData = [[NSMutableData data] retain];

}

else

{

NSLog(@"theConnection is NULL");

}

}

这个方法作用就是封装soap请求,并向服务器发送请求.

码有注释.不重复讲解.soap并不难,难的是没有案例告诉我们怎么把其它平台的soap移植过来,这里我给出了代码,我相信对iphone开发人员的话
应该能看懂了.我在下面会把此案例的源代码附上.如果自己做不出来再看我的代码.如果我这样讲您觉得不够细,那说明您的iphone开发还不是太深入,那
么您应该用不到soap技术.可以飘过了.
下面的代码是接收信息并解析,显示到用户界面

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response

{

[webData setLength: 0];

NSLog(@"connection: didReceiveResponse:1");

}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data

{

[webData appendData:data];

NSLog(@"connection: didReceiveData:2");

}

//如果电脑没有连接网络,则出现此信息(不是网络服务器不通)

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error

{

NSLog(@"ERROR with theConenction");

[connection release];

[webData release];

}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection

{

NSLog(@"3 DONE. Received Bytes: %d", [webData length]);

NSString
*theXML = [[NSString alloc] initWithBytes: [webData mutableBytes]
length:[webData length] encoding:NSUTF8StringEncoding];

NSLog(theXML);

[theXML release];

//重新加载xmlParser

if( xmlParser )

{

[xmlParser release];

}

xmlParser = [[NSXMLParser alloc] initWithData: webData];

[xmlParser setDelegate: self];

[xmlParser : YES];

[xmlParser parse];

[connection release];

//[webData release];

}

-(void)parser:(NSXMLParser
*)parser didStartElement:(NSString *)elementName namespaceURI:(NSString
*) namespaceURI qualifiedName:(NSString *)qName

attributes: (NSDictionary *)attributeDict

{

NSLog(@"4 parser didStarElemen: namespaceURI: attributes:");

if( [elementName isEqualToString:@"getOffesetUTCTimeResult"])

{

if(!soapResults)

{

soapResults = [[NSMutableString alloc] init];

}

recordResults = YES;

}

}

-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

{

NSLog(@"5 parser: foundCharacters:");

if( recordResults )

{

[soapResults appendString: string];

}

}

-(void)parser:(NSXMLParser
*)parser didEndElement:(NSString *)elementName namespaceURI:(NSString
*)namespaceURI qualifiedName:(NSString *)qName

{

NSLog(@"6 parser: didEndElement:");

if( [elementName isEqualToString:@"getOffesetUTCTimeResult"])

{

recordResults = FALSE;

greeting.text
= [[[NSString init]stringWithFormat:@"第%@时区的时间是: ",nameInput.text]
stringByAppendingString:soapResults];

[soapResults release];

soapResults = nil;

NSLog(@"hoursOffset result");

}

}

- (void)parserDidStartDocument:(NSXMLParser *)parser{

NSLog(@"-------------------start--------------");

}

- (void)parserDidEndDocument:(NSXMLParser *)parser{

NSLog(@"-------------------end--------------");

}

说明下:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection

这个方法是存储接收到的信息

-(void)parser:(NSXMLParser
*)parser didEndElement:(NSString *)elementName namespaceURI:(NSString
*)namespaceURI qualifiedName:(NSString *)qName