Iphone objective-c:Webservice,如何讲述访问的具体方法
我正在尝试访问web服务和 AuthorizeCreditTrip我在.Net应用程序上检查了此Web服务及其工作正常,但在objective-c中,它没有使用相同的数据进行响应 web服务公开了5种方法,我想访问第4种。但是我认为这段代码没有指定访问的方法Iphone objective-c:Webservice,如何讲述访问的具体方法,iphone,objective-c,ios,web-services,ipad,Iphone,Objective C,Ios,Web Services,Ipad,我正在尝试访问web服务和 AuthorizeCreditTrip我在.Net应用程序上检查了此Web服务及其工作正常,但在objective-c中,它没有使用相同的数据进行响应 web服务公开了5种方法,我想访问第4种。但是我认为这段代码没有指定访问的方法forHTTPHeaderField:@“SOAPAction”告诉我们,但我不认为它在这里的链接是正确的 不响应意味着它不发送任何响应 我认为我无法设置有效的SOAPAction -(IBAction)sendData { NSSt
forHTTPHeaderField:@“SOAPAction”
告诉我们,但我不认为它在这里的链接是正确的
不响应意味着它不发送任何响应
我认为我无法设置有效的SOAPAction
-(IBAction)sendData
{
NSString *soapMsg = [NSString stringWithFormat: @"<?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:Header>"
"<AuthenticationHeader xmlns=\"http://services.cmtnyc.com/payment\">"
"<Username>validusername</Username>"
"<Password>validpass</Password>"
"<DataSource>validsource</DataSource>"
"</AuthenticationHeader>"
"</soap:Header>"
"<soap:Body>"
"<AuthorizeCreditTrip xmlns=\"http://services.cmtnyc.com/payment\">"
"<requestId>%d</requestId>"
"<deviceId>abcd</deviceId>"
"<userId>3003</userId>"
"<jobId>000047</jobId>"
"<paymentAmt>1</paymentAmt>"
"<fareAmt>0</fareAmt>"
"<tipAmt>0</tipAmt>"
"<tollAmt>0</tollAmt>"
"<surchargeAmt>0</surchargeAmt>"
"<taxAmt>0</taxAmt>"
"<convenienceFeeAmt>0</convenienceFeeAmt>"
"<swipeData></swipeData>"
"<accountNumber>validaccount</accountNumber>"
"<expiryDate>validdate</expiryDate>"
"<zipCode>73000</zipCode>"
"<cvv2>227</cvv2>"
"<cardReaderMethod>0</cardReaderMethod>"
"<encryptionKeyVersion>0</encryptionKeyVersion>"
"<encryptedToken></encryptedToken>"
"<encryptionAlgorithm>0</encryptionAlgorithm>"
"<pickupDate>2011-09-12</pickupDate>"
"<pickupLatitude>0</pickupLatitude>"
"<pickupLongitude>0</pickupLongitude>"
"<dropoffDate>2011-09-16</dropoffDate>"
"<dropoffLatitude>0</dropoffLatitude>"
"<dropoffLongitude>0</dropoffLongitude>"
"<passengerCount>0</passengerCount>"
"<tripDistance>124</tripDistance>"
"<tripDuration>0</tripDuration>"
"<readyToSettle>false</readyToSettle>"
"</AuthorizeCreditTrip>"
"</soap:Body>"
"</soap:Envelope>",55258];
NSURL *url = [NSURL URLWithString: @"http://services-staging.cmtnyc.com/payment/payment.asmx"];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://services.cmtnyc.com/payment/AuthorizeCreditTrip" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"]; //---set the HTTP method and body---
[req setHTTPMethod:@"POST"];
[req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"%@", soapMsg);
conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn)
{
webData = [[NSMutableData data] retain];
}
}
-(void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *) response {
[webData setLength: 0];
}
-(void) connection:(NSURLConnection *) connection didReceiveData:(NSData *) data
{
[webData appendData:data];
}
-(void) connection:(NSURLConnection *) connection didFailWithError:(NSError *) error {
[webData release];
[connection release];
}
-(void) connectionDidFinishLoading:(NSURLConnection *) connection
{
NSLog(@"..DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc] //---shows the XML---
initWithBytes:[webData mutableBytes] length:[webData length]
encoding:NSUTF8StringEncoding];
NSLog(@"....%@",theXML);
[theXML release];
// [activityIndicator stopAnimating];
[connection release];
[webData release];
}
-(iAction)发送数据
{
NSString*soapMsg=[NSString stringWithFormat:@]
""
""
""
“validusername”
“有效通行证”
“validsource”
""
""
""
""
%d
“abcd”
"3003"
"000047"
"1"
"0"
"0"
"0"
"0"
"0"
"0"
""
“有效计数”
“有效期”
"73000"
"227"
"0"
"0"
""
"0"
"2011-09-12"
"0"
"0"
"2011-09-16"
"0"
"0"
"0"
"124"
"0"
“假”
""
""
"",55258];
NSURL*url=[NSURL URLWithString:@”http://services-staging.cmtnyc.com/payment/payment.asmx"];
NSMutableURLRequest*req=[NSMutableUrlRequestWithURL:url];
NSString*msgLength=[NSString stringWithFormat:@“%d”,[soapMsg长度]];
[req addValue:@“text/xml;charset=utf-8”用于httpheaderfield:@“Content Type”];
[请求添加值:@”http://services.cmtnyc.com/payment/AuthorizeCreditTripforHTTPHeaderField:@“SOAPAction”];
[req addValue:msgLength for HttpHeaderField:@“内容长度”];/---设置HTTP方法和正文--
[req setHTTPMethod:@“POST”];
[req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@“%@”,soapMsg);
conn=[[NSURLConnection alloc]initWithRequest:req委托:self];
如果(康涅狄格州)
{
webData=[[NSMutableData]保留];
}
}
-(void)连接:(NSURLConnection*)连接DidReceiverResponse:(NSURResponse*)响应{
[webData setLength:0];
}
-(void)连接:(NSURLConnection*)连接didReceiveData:(NSData*)数据
{
[webData:data];
}
-(无效)连接:(NSURLConnection*)连接失败错误:(NSError*)错误{
[网络数据发布];
[连接释放];
}
-(无效)连接IDFinishLoading:(NSURLConnection*)连接
{
NSLog(@“.DONE.Received字节:%d”,[webData长度];
NSString*XML=[[NSString alloc]/---显示XML---
initWithBytes:[webData mutableBytes]长度:[webData长度]
编码:NSUTF8StringEncoding];
NSLog(@“…%@”,XML);
[XML发布];
//[活动指示器停止设置动画];
[连接释放];
[网络数据发布];
}
以下是我如何让它工作的:
NSURL *urlWS = [NSURL URLWithString:kUrlServer];
NSMutableURLRequest *theRequest;
theRequest = [NSMutableURLRequest requestWithURL:urlWS];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
也许您缺少应用程序/soap+xml
干杯我使用了以下代码,对我来说效果很好:
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
[req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[req addValue:@"http://tempuri.org/SearchCustomer" forHTTPHeaderField:@"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[req setHTTPMethod:@"POST"];
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
其中,url是我的url,soapMsg是我的soap消息,@”http://tempuri.org/Method“是soap操作。我建议你检查你的参数是否正确,因为你的代码看起来很好。实际上,这个web服务公开了5个方法,这个代码应该访问AuthorizeCreditTrip方法,但是这个代码没有告诉你要访问哪个函数。。我想这就是问题所在……@Azhar:你找到解决办法了吗。我也遇到了同样的问题。你能提供这个问题的答案吗。