Iphone 如何让iOS与.NET web服务对话
我在连接此Web服务时遇到问题,是否知道我做错了什么Iphone 如何让iOS与.NET web服务对话,iphone,objective-c,Iphone,Objective C,我在连接此Web服务时遇到问题,是否知道我做错了什么 - (void)startRetrievingHotels { //Create the web service URL NSURL *url = [NSURL URLWithString:@"https://www.stratexlive.com/tenants/commercialbank/_vti_bin/stratexws.asmx"]; //Create the web service reque
- (void)startRetrievingHotels
{
//Create the web service URL
NSURL *url = [NSURL URLWithString:@"https://www.stratexlive.com/tenants/commercialbank/_vti_bin/stratexws.asmx"];
//Create the web service request
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
NSString *requestString = [self buildHotelListRequest];
NSLog(@"%@", requestString );
[request setDelegate:self];
[request setUsername:@"asdfasdf@asdfasdf.com"];
[request setPassword:@"asdfasdfasdfasdf$"];
[request appendPostData:[[self buildHotelListRequest] dataUsingEncoding:NSUTF8StringEncoding]]; //Set the xml request
[request startAsynchronous];
}
- (NSString *)buildHotelListRequest
{
NSString *result = [NSString stringWithFormat: @"<?xml version=\"1.0\"?>"
@"<GetUserName xmlns=\"https://www.sdf.com/\" />"];
NSLog(@"HOTEL LIST REQUEST: %@", result);
return result;
}
-(无效)StartrevingHotels
{
//创建web服务URL
NSURL*url=[NSURL URLWithString:@”https://www.stratexlive.com/tenants/commercialbank/_vti_bin/stratexws.asmx"];
//创建web服务请求
ASIHTTPRequest*request=[AsiHttpRequestWithURL:url];
NSString*requestString=[self-buildHotelListRequest];
NSLog(@“%@”,requestString);
[请求setDelegate:self];
[请求设置用户名:@”asdfasdf@asdfasdf.com"];
[请求设置密码:@“asdfasdfasdfasdf$”;
[request appendPostData:[[self-buildHotelListRequest]dataUsingEncoding:NSUTF8StringEncoding];//设置xml请求
[请求启动同步];
}
-(NSString*)buildHotelListRequest
{
NSString*结果=[NSString stringWithFormat:@“”
@""];
NSLog(@“酒店列表请求:%@”,结果);
返回结果;
}
这是我得到的答复:
> <?xml version="1.0" encoding="utf-8"?><soap:Envelope
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><soap12:Upgrade
> xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:SupportedEnvelope
> qname="soap:Envelope"
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" />
>
> <soap12:SupportedEnvelope qname="soap12:Envelope"
> xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" />
>
> </soap12:Upgrade></soap:Header><soap:Body><soap:Fault>
>
> <faultcode>soap:VersionMismatch</faultcode><faultstring>Possible SOAP
> version mismatch: Envelope namespace https://www.stratexsystems.com/
> was unexpected. Expecting
> http://schemas.xmlsoap.org/soap/envelope/.</faultstring>
>
> <detail /></soap:Fault></soap:Body>
>
> </soap:Envelope>
>xmlns:soap=”http://schemas.xmlsoap.org/soap/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“>qname=“soap:信封”
>xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/" />
>
>xmlns:soap12=”http://www.w3.org/2003/05/soap-envelope" />
>
>
>
>soap:versionmismatchsoap
>版本不匹配:信封命名空间https://www.stratexsystems.com/
>这是出乎意料的。期望
> http://schemas.xmlsoap.org/soap/envelope/.
>
>
>
>
我读了有关soap的文章,发现您缺少了一些内容。这里有一些信息,但我不确定用户名和密码放在哪里。
希望你能弄明白
NSString *soapMessage = @"<?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>\
<GetUserName xmlns=\"https://www.stratexsystems.com/\" />\
</soap:Body>\
</soap:Envelope>";
NSURL *url = [NSURL URLWithString:@"https://www.stratexlive.com/tenants/commercialbank/_vti_bin/stratexws.asmx"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"https://www.stratexsystems.com/GetUserName" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
NSString*soapMessage=@”\
\
\
\
\
";
NSURL*url=[NSURL URLWithString:@”https://www.stratexlive.com/tenants/commercialbank/_vti_bin/stratexws.asmx"];
NSMutableURLRequest*theRequest=[NSMutableUrlRequestWithURL:url];
NSString*msgLength=[NSString stringWithFormat:@“%d”,[soapMessage length]];
[theRequest addValue:@“text/xml;charset=utf-8”用于HttpHeaderField:@“Content Type”];
[请求附加值:@”https://www.stratexsystems.com/GetUserNameforHTTPHeaderField:@“SOAPAction”];
[theRequest addValue:msgLength for HttpHeaderField:@“内容长度”];
[TheRequestSetHttpMethod:@“POST”];
[TheRequestSetHttpBody:[soapMessage数据使用编码:NSUTF8StringEncoding];
NSURLConnection*连接=[[NSURLConnection alloc]initWithRequest:theRequest委托:self];
您不能使用NSURLConnection吗?@H2CO3已更新问题。Inder-我的请求将变得更加复杂,因此我更熟悉ASIHTTREQUESTAnd,现在我厌倦了水平滚动100k XML响应。请缩进。这是一个soap web服务,我对此不太了解。。sorry@TheLearnerWeb服务似乎需要某种版本信息,但您没有将其包含在请求中。医生提到了吗?你说得对。潜在的问题是必须构造整个SOAP消息,包括信封。OP的要求只包括尸体。对于复杂的请求,我不能强调ObjC中手工构建和手工解码SOAP有多痛苦。如果切换到REST是不可能的,那么我建议使用gsoap而不是手工构建这些东西。