Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c SudzC展会';有效';soap响应,但在iOS';s侧_Objective C_Ios_Web Services_Soap - Fatal编程技术网

Objective c SudzC展会';有效';soap响应,但在iOS';s侧

Objective c SudzC展会';有效';soap响应,但在iOS';s侧,objective-c,ios,web-services,soap,Objective C,Ios,Web Services,Soap,我对SOAP和iOS还比较陌生,所以请容忍我。 我正在尝试使用生成的源SudzC使用SOAP WS 从输出来看,一切似乎都在运转。我可以看到我需要的数据,因此数据似乎在移动: 2012-03-30 17:26:14.131 EZSystem[892:707] Loading: http://xx.xx.xx.xxx:xxxx/service 2012-03-30 17:26:14.137 EZSystem[892:707] <?xml version="1.0" encoding="u

我对SOAP和iOS还比较陌生,所以请容忍我。 我正在尝试使用生成的源SudzC使用SOAP WS

从输出来看,一切似乎都在运转。我可以看到我需要的数据,因此数据似乎在移动:

2012-03-30 17:26:14.131 EZSystem[892:707] 
Loading: http://xx.xx.xx.xxx:xxxx/service

2012-03-30 17:26:14.137 EZSystem[892:707]
<?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/" 
    xmlns="http://database.usah.com/">
<soap:Body>
    <getQB2012CustomerDictionaryXML></getQB2012CustomerDictionaryXML>
</soap:Body>
</soap:Envelope>

2012-03-30 17:26:14.485 EZSystem[892:707] 
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getQB2012CustomerDictionaryXMLResponse
    xmlns:ns2="http://xxxxxx/">
    <return>
        &lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;&lt;!-- 
        &lt;[Quickbooks tag]&gt;Database Column Name&lt;/[Quickbooks tag]&gt;
        --&gt;&lt;CustomerRet database_root_tag="Customers" id="id_customers" 
        ...
        ...
        ...
    </return>
</ns2:getQB2012CustomerDictionaryXMLResponse>
</S:Body>
</S:Envelope>
该值为空

在这个过程中,它在哪里发生故障?似乎我正在接收所需的数据,但将其发送到OBJ-C字符串失败

任何帮助都将不胜感激


SudzC生成的SoapRequest.m中的Dane

- (void) connectionDidFinishLoading:(NSURLConnection *) connection {
    ...
    if(self.logging == YES){
       NSString* response = [[NSString alloc] initWithData: self.receivedData 
        encoding: NSUTF8StringEncoding];
       NSLog(@"%@", response);
    }    
    ...
}
响应是原始SOAP响应,它包含预期的数据

用同样的方法,

CXMLNode* element = [[Soap getNode: [doc rootElement] withName: @"Body"] 
    childAtIndex:0];
此行从SOAP响应获取返回值。经过一番摸索,发现问题出在“身体”上:

SOAP响应具有“S:Body”,因此将withName更改为正确的标记名可以修复所有问题

这让我很困扰,因为我不知道我的WS是错还是错,但我现在就接受它

此外,Soap.m可能需要修改,因为它使用了“Soap”,而不是,比如说“soapenv”。这些值是硬编码的,但更改相当容易

此外,命名空间保留为空:

[s appendFormat:@"=\"http://schemas.xmlsoap.org/soap/envelope/\" 
xmlns=\"%@\">", ns]; 
这可能必须是xmlns:[名称空间]=\“%@”。。。 其中namespace是剥离的名称空间

即:

http://namespace/ => namespace
此外,您不能接收字符串结果并在示例中使用它,至少在我这方面是这样。 例如:

NSString* result = (NSString*) value;
应该生成null。然而,这似乎是可行的:

NSDictionary* result = (NSDictionary*)value;
NSString* finalResult = [[result allValues] objectAtIndex:0];
如果有人感兴趣,这里是对Soap.m的修改

// Soap.m

NSString* const SOAP_PREFIX = @"soapenv";
NSString* const HTTP_PREFIX = @"http://";
NSUInteger const FORWARD_FLASH_CHARACTER_VALUE = 47;

// Creates the XML request for the SOAP envelope with optional SOAP headers.
+ (NSString*) createEnvelope: (NSString*) method forNamespace: (NSString*) ns         
    forParameters: (NSString*) params withHeaders: (NSDictionary*) headers
    {
        NSMutableString* s = [NSMutableString string];

    [s appendString: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
        [s appendString: @"<"];
        [s appendString: SOAP_PREFIX];
        [s appendString:@":Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-
            instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""];
        [s appendString:@" xmlns:"];
        [s appendString: SOAP_PREFIX];

        NSString* rawNamespace = [Soap getRawNamespace:ns];
        [s appendFormat:@"=\"http://schemas.xmlsoap.org/soap/envelope/\" 
            xmlns:%@=\"%@\">", rawNamespace, ns];

        if(headers != nil && headers.count > 0) {
            [s appendString: @"<"];
            [s appendString: SOAP_PREFIX];
            [s appendString:@":Header>"];

            for(id key in [headers allKeys]) {
        if([[headers objectForKey: key] isMemberOfClass: [SoapNil class]])     
                {
                [s appendFormat: @"<%@ xsi:nil=\"true\"/>", key];
        } else {
                [s appendString:[Soap serializeHeader:headers forKey:key]];
        }
        }  
            [s appendString: @"</"];
            [s appendString: SOAP_PREFIX];
            [s appendString:@":Header>"];
    }

    [s appendString: @"<"];
        [s appendString: SOAP_PREFIX];
        [s appendString:@":Body>"];

        NSMutableString* fullMethodName = [NSMutableString string];
        [fullMethodName appendString:rawNamespace];
        [fullMethodName appendString:@":"];
        [fullMethodName appendString:method];

    [s appendFormat: @"<%@>%@</%@>", fullMethodName,[params 
            stringByReplacingOccurrencesOfString:@"&" withString:@"&amp;"], 
            fullMethodName];


        [s appendString: @"</"];
        [s appendString: SOAP_PREFIX];
        [s appendString:@":Body>"];
        [s appendString: @"</"];
        [s appendString: SOAP_PREFIX];
        [s appendString:@":Envelope>"];
    return s;
}


+(NSString*)getRawNamespace:(NSString *)value{
    if([value hasPrefix:HTTP_PREFIX]){
        NSString* rawNamespace = [value substringFromIndex:([HTTP_PREFIX length])];

        if([rawNamespace length] == 0){
            return @"";
        }
        // strip out a trailing slash
        if([rawNamespace characterAtIndex:([rawNamespace length]- 1)] ==             
            FORWARD_FLASH_CHARACTER_VALUE){
            NSRange range = NSMakeRange (0, [rawNamespace length] - 1);
            rawNamespace = [rawNamespace substringWithRange:(range)];
        }
        return rawNamespace;           
    }
    else{
        return value;
    }
}    
//Soap.m
NSString*const SOAP_前缀=@“soapenv”;
NSString*常量HTTP_前缀=@“HTTP://”;
NSU整数常量前向\u闪烁\u字符\u值=47;
//使用可选的SOAP头为SOAP信封创建XML请求。
+(NSString*)createEnvelope:(NSString*)命名空间的方法:(NSString*)ns
forParameters:(NSString*)带标头的参数:(NSDictionary*)标头
{
NSMutableString*s=[NSMutableString];
[s appendString:@”“;
[s appendString:@“”,名称空间,ns];
if(headers!=nil&&headers.count>0){
[s appendString:@”“;
for(在[headers allKeys]中输入id键){
if([[headers objectForKey:key]isMemberOfClass:[SoapNil class]])
{
[附件格式:@“,键];
}否则{
[s appendString:[Soap serializeHeader:headers-forKey:key]];
}
}  
[s appendString:@”“;
}
[s appendString:@”“;
NSMutableString*fullMethodName=[NSMutableString];
[fullMethodName appendString:rawNamespace];
[fullMethodName appendString:@”:“];
[fullMethodName appendString:method];
[s appendFormat:@“%@”,fullMethodName,[params]
StringByReplacingOfString:@“&withString:@”&;]的发生率,
全名];
[s appendString:@”“;
[s appendString:@”“;
返回s;
}
+(NSString*)getRawNamespace:(NSString*)值{
if([value hasPrefix:HTTP\u PREFIX]){
NSString*rawNamespace=[value substringFromIndex:([HTTP_前缀长度]]);
如果([rawNamespace length]==0){
返回@”;
}
//去掉后面的斜线
如果([rawNamespace characterAtIndex:([rawNamespace length]-1)]==
正向\u闪烁\u字符\u值){
NSRange range=NSMakeRange(0,[rawNamespace length]-1);
rawNamespace=[rawNamespace substringWithRange:(range)];
}
返回名称空间;
}
否则{
返回值;
}
}    

在SudzC生成的SoapRequest.m中:

- (void) connectionDidFinishLoading:(NSURLConnection *) connection {
    ...
    if(self.logging == YES){
       NSString* response = [[NSString alloc] initWithData: self.receivedData 
        encoding: NSUTF8StringEncoding];
       NSLog(@"%@", response);
    }    
    ...
}
响应是原始SOAP响应,它包含预期的数据

用同样的方法,

CXMLNode* element = [[Soap getNode: [doc rootElement] withName: @"Body"] 
    childAtIndex:0];
此行从SOAP响应获取返回值。经过一番摸索,发现问题出在“身体”上:

SOAP响应具有“S:Body”,因此将withName更改为正确的标记名可以修复所有问题

这让我很困扰,因为我不知道我的WS是错还是错,但我现在就接受它

此外,Soap.m可能需要修改,因为它使用了“Soap”,而不是,比如说“soapenv”。这些值是硬编码的,但更改相当容易

此外,命名空间保留为空:

[s appendFormat:@"=\"http://schemas.xmlsoap.org/soap/envelope/\" 
xmlns=\"%@\">", ns]; 
这可能必须是xmlns:[名称空间]=\“%@”。。。 其中namespace是剥离的名称空间

即:

http://namespace/ => namespace
此外,您不能接收字符串结果并在示例中使用它,至少在我这方面是这样。 例如:

NSString* result = (NSString*) value;
应该生成null。然而,这似乎是可行的:

NSDictionary* result = (NSDictionary*)value;
NSString* finalResult = [[result allValues] objectAtIndex:0];
如果有人感兴趣,这里是对Soap.m的修改

// Soap.m

NSString* const SOAP_PREFIX = @"soapenv";
NSString* const HTTP_PREFIX = @"http://";
NSUInteger const FORWARD_FLASH_CHARACTER_VALUE = 47;

// Creates the XML request for the SOAP envelope with optional SOAP headers.
+ (NSString*) createEnvelope: (NSString*) method forNamespace: (NSString*) ns         
    forParameters: (NSString*) params withHeaders: (NSDictionary*) headers
    {
        NSMutableString* s = [NSMutableString string];

    [s appendString: @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
        [s appendString: @"<"];
        [s appendString: SOAP_PREFIX];
        [s appendString:@":Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-
            instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""];
        [s appendString:@" xmlns:"];
        [s appendString: SOAP_PREFIX];

        NSString* rawNamespace = [Soap getRawNamespace:ns];
        [s appendFormat:@"=\"http://schemas.xmlsoap.org/soap/envelope/\" 
            xmlns:%@=\"%@\">", rawNamespace, ns];

        if(headers != nil && headers.count > 0) {
            [s appendString: @"<"];
            [s appendString: SOAP_PREFIX];
            [s appendString:@":Header>"];

            for(id key in [headers allKeys]) {
        if([[headers objectForKey: key] isMemberOfClass: [SoapNil class]])     
                {
                [s appendFormat: @"<%@ xsi:nil=\"true\"/>", key];
        } else {
                [s appendString:[Soap serializeHeader:headers forKey:key]];
        }
        }  
            [s appendString: @"</"];
            [s appendString: SOAP_PREFIX];
            [s appendString:@":Header>"];
    }

    [s appendString: @"<"];
        [s appendString: SOAP_PREFIX];
        [s appendString:@":Body>"];

        NSMutableString* fullMethodName = [NSMutableString string];
        [fullMethodName appendString:rawNamespace];
        [fullMethodName appendString:@":"];
        [fullMethodName appendString:method];

    [s appendFormat: @"<%@>%@</%@>", fullMethodName,[params 
            stringByReplacingOccurrencesOfString:@"&" withString:@"&amp;"], 
            fullMethodName];


        [s appendString: @"</"];
        [s appendString: SOAP_PREFIX];
        [s appendString:@":Body>"];
        [s appendString: @"</"];
        [s appendString: SOAP_PREFIX];
        [s appendString:@":Envelope>"];
    return s;
}


+(NSString*)getRawNamespace:(NSString *)value{
    if([value hasPrefix:HTTP_PREFIX]){
        NSString* rawNamespace = [value substringFromIndex:([HTTP_PREFIX length])];

        if([rawNamespace length] == 0){
            return @"";
        }
        // strip out a trailing slash
        if([rawNamespace characterAtIndex:([rawNamespace length]- 1)] ==             
            FORWARD_FLASH_CHARACTER_VALUE){
            NSRange range = NSMakeRange (0, [rawNamespace length] - 1);
            rawNamespace = [rawNamespace substringWithRange:(range)];
        }
        return rawNamespace;           
    }
    else{
        return value;
    }
}    
//Soap.m
NSString*const SOAP_前缀=@“soapenv”;
NSString*常量HTTP_前缀=@“HTTP://”;
NSU整数常量前向\u闪烁\u字符\u值=47;
//使用可选的SOAP头为SOAP信封创建XML请求。
+(NSString*)createEnvelope:(NSString*)命名空间的方法:(NSString*)ns
forParameters:(NSString*)带标头的参数:(NSDictionary*)标头
{
NSMutableString*s=[NSMutableString];
[s appendString:@”“;
[s appendString:@“”,名称空间,ns];
if(headers!=nil&&headers.count>0){
[s appendString:@”“;
for(在[headers allKeys]中输入id键){
if([[headers objectForKey:key]isMemberOfClass:[SoapNil class]])
{
[附件格式:@“,键];
}否则{
[s appendString:[Soap serializeHeader:headers-forKey:key]];
}
}  
[s appendString:@”“;
}
[s appendString:@”“;
NSMutableString*fullMethodName=[NSMutableString];
[fullMethodName appendString:rawNamespace];
[fullMethodName appendString:@”:“];
[fullMethodName appendString:meth