【问题标题】:soap web service parsing肥皂网络服务解析
【发布时间】:2011-03-28 08:09:12
【问题描述】:

我正在尝试解析soap Web服务以进行身份​​验证,以下是代码

currentElement = [[NSString alloc] init];
NSString* email=[NSString stringWithFormat:@"sbhushan@gmail.com"];
NSString* password=[NSString stringWithFormat:@"5Pb&Q?4t"];
NSString* soapMesasge=[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:Body>"
                       "<Authentication xmlns=\"http://tempuri.org/\">"
                       "<userId>%@</userId>"
                       "<password>%@</password>"
                       "</Authentication>"
                       "</soap:Body>"
                       "</soap:Envelope>",email,password];


NSURL* url=[NSURL URLWithString:@"http://codeexsolutions.com/HosService/ServiceHOSProvider.asmx"];
NSMutableURLRequest* theRequest=[NSMutableURLRequest requestWithURL:url];
NSString* msgLength=[NSString stringWithFormat:@"%d",[soapMesasge length]];

[theRequest addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:@"http://tempuri.org/Authentication" forHTTPHeaderField:@"SOAPAction"];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[soapMesasge dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection)
{
    webData =[[NSMutableData alloc]retain];
}
else
{
    // Inform the user that the connection failed.
}   

并实现了所有解析的委托方法,但没有被调用

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [网络数据追加数据:数据]; }

或者没有得到任何数据请帮忙

【问题讨论】:

    标签: iphone


    【解决方案1】:

    你好朋友 你的方法看起来不错不知道为什么不工作,你在 consol 上看到任何数据?试试这个或看看网络服务可能不是来自那里的数据

    NSString *soapMessage = [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:Body><GetClientData xmlns=\"http://tempuri.org/\"><pSearch>%@</pSearch></GetClientData></soap:Body></soap:Envelope>\n", nameInput.text];
    NSURL *url = [NSURL URLWithString:@"http://192.168.1.162/iphone/service.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:  @"http://tempuri.org/GetClientData" forHTTPHeaderField:@"SOAPAction"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
    
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    
    if( theConnection )
    {
        webData = [[NSMutableData data] retain];
    }
    else
    {
        NSLog(@"theConnection is NULL");
    }
    

    【讨论】:

    • 我在网络数据上设置了断点,如果条件返回 0
    • 那么你交朋友的问题在哪里?你的网络服务格式正确吗??
    • 你实现- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse*)response 这个方法了吗??
    • 在尝试接收数据之前,请先确认您的连接是否有响应。
    • @shrey yaa 我已经实现了 connectiondidreciveresponse 方法
    猜你喜欢
    • 1970-01-01
    • 2021-07-29
    • 2017-01-16
    • 2017-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-11
    • 1970-01-01
    相关资源
    最近更新 更多