在ios中调用本地主机中的SOAP Web服务

时间:2014-05-05 12:29:42

标签: ios

我在本地托管了soap webservice!我打电话给别人打电话; android,窗口,但我无法从ios调用它?任何的想法。我已经成功从ios调用在线soap webservice。为了在ios中调用soap本地Web服务,我必须做些什么改变。这是我的代码注意:(我正在开发它作为phonegap插件在线webservice成功调用)

    //
//  Hello.m
//  helloi
//
//  Created by procit on 4/25/14.
//
//


#import "Hello.h"
#import <Cordova/CDV.h>
@implementation Hello
- (void)echo:(CDVInvokedUrlCommand*)command
{
    CDVPluginResult* pluginResult = nil;
     NSString *echo = [command.arguments objectAtIndex:0]; // args value assign in echo here
    // NSLog(@"%@", echo);


    NSString *soapMsg = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
                         "<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/\">\n"
                         "<soap:Body>\n"
                         "<PingResponse xmlns=\"http://Smartflowtest.88degrees.nl/mobilewebservice/\">\n"
                         "<compressed>%@</compressed>\n"
                         "</Ping>\n"
                         "</soap:Body>\n"
                         "</soap:Envelope>", echo];


    NSURL *url = [NSURL URLWithString:@"http://192.168.100.2/mobilewebservice_ganesh/services.asmx"];
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];
   // NSLog(@"%@", msgLength); // shows the length of soap msg

    [theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type" ] ;
    [theRequest addValue:@"http://Smartflowtest.88degrees.nl/mobilewebservice/Ping" forHTTPHeaderField:@"SOAPAction"];
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
    [theRequest setHTTPMethod:@"POST"];
    [theRequest addValue:@"192.168.100.2" forHTTPHeaderField:@"HOST"];
    [theRequest setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]];

    theconnection = [[NSURLConnection alloc] initWithRequest: theRequest delegate:self];



    NSError *errorReturned = nil;
    NSURLResponse *theResponse =[[NSURLResponse alloc]init];
    NSData *data = [NSURLConnection sendSynchronousRequest:theRequest
                                         returningResponse:&theResponse
                                                     error:&errorReturned];
    //NSLog(data);
    if (errorReturned)
    {
        //...handle the error
        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
    }
    else
    {
        NSString *retVal = [[NSString alloc] initWithData:data
                                                 encoding:NSUTF8StringEncoding ];

        NSLog(@"%@", retVal);

        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:retVal];


    }

   [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}



@end

0 个答案:

没有答案