如何发送请求以及如何从xcode,iphone中的sap soap wsdl服务获取响应

时间:2012-02-18 05:10:36

标签: iphone soap wsdl request sap

我安装了wsdl2objc并解析了wsdl并在解析url时生成了类。我通过创建另一个名为webservices的文件夹将该类导入xcode中的项目,并将文件添加到该webservices组。我更改了项目设置中的设置,我更改了搜索标题路径中的设置,我写了/ usr / include / libxml2 /我在链接其他文件中更改了-lxml2而且我得到.dylib文件到项目,我添加将要用于开发项目的框架。现在这里有一个问题,我感到困惑/被打击。如何发送请求以及如何从sap soap web服务获得响应。请帮助我摆脱这个问题。请帮助我详细的方式。从sap soap webservice wsdl请求和获得响应时要遵循的步骤?

1 个答案:

答案 0 :(得分:1)

首先,你的对象应该实现wsdl2objc为你生成的协议,例如:

@interface Envoyer : UIViewController <WSAppliMobileStockageSOAPBindingResponseDelegate>

要发送您的答案,您可能会采取以下行动:

- (IBAction)sendResults:(id)sender
{
    NSString *str = [self makeXML]; // my content is an xml file but can be any thing you like...
    WSAppliMobileStockageSOAPBinding *ws = [WSAppliMobileStockage WSAppliMobileStockageSOAPBinding];
    ws.logXMLInOut = YES; // to see the output
    WSAppliMobileStockage_tTransfertReponses *tr = [[WSAppliMobileStockage_tTransfertReponses new] autorelease]; // an instance of the object generated by wsdl2objc
    tr.sBuffer = [str dataUsingEncoding:NSUTF8StringEncoding];
    [ws TransfertReponsesAsyncUsingParameters:tr delegate:self];
}

最后定义回调函数:

- (void) operation:(WSAppliMobileStockageSOAPBindingOperation *)operation completedWithResponse:(WSAppliMobileStockageSOAPBindingResponse *)response
{
    for(id bodyPart in response.bodyParts)
    {
        if ([bodyPart isKindOfClass:[SOAPFault class]]) // most likely a connection error
        {
            NSLog(@"soap error: %@", ((SOAPFault *)bodyPart).simpleFaultString);
            UIAlertView *someError = [[UIAlertView alloc] 
                                      initWithTitle:nil 
                                      message: @"Oops! An error happend, please try again"
                                      delegate:nil 
                                      cancelButtonTitle: @"Ok" 
                                      otherButtonTitles: nil];

            [someError show];
            [someError release];
            return;
        }

        if([bodyPart isKindOfClass:[WSAppliMobileStockage_tTransfertReponsesResponse class]]) //the class generated for you
        {
            WSAppliMobileStockage_tTransfertReponsesResponse *body = 
                (WSAppliMobileStockage_tTransfertReponsesResponse*)bodyPart;
            if (![body.TransfertReponsesResult isEqualToString:@"OK"]) // the result code of the backend function, yours maybe different...
            {
                NSLog(@"error response: \"%@\"", body.TransfertReponsesResult);
                UIAlertView *someError = [[UIAlertView alloc] 
                                          initWithTitle:nil 
                                          message: @"Oops! An error happend, please try again!"
                                          delegate:nil 
                                          cancelButtonTitle: @"Ok" 
                                          otherButtonTitles: nil];

                [someError show];
                [someError release];
            }
            else
            {
                UIAlertView *someError = [[UIAlertView alloc] 
                                          initWithTitle:nil 
                                          message: @"Congrats..."
                                          delegate:nil 
                                          cancelButtonTitle: @"Ok" 
                                          otherButtonTitles: nil];

                [someError show];
                [someError release];
            }
            continue;
        }        
    }

}

希望这会有所帮助;)