2013-05-08 93 views
3

我一直在试图编写一个客观的C应用程序的iPad发送/接收肥皂Web服务。我写了一段代码,但它给出了一个错误。该web服务正在联机工作。如何发送/接收肥皂对象与目标C为ipad

这里是我的代码,

-(IBAction)invokeService 
{ 

    [txt1 resignFirstResponder]; 

    NSString *soapFormat = [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" 
        "<GetUserList xmlns=\"http://tempuri.org/\" />\n" 
        "</soap:Body>\n" 
        "</soap:Envelope>\n"]; 


    NSLog(@"The request format is %@",soapFormat); 

    NSURL *locationOfWebService = [NSURL URLWithString:@"http://servicing2.rotanet.com/service1.asmx"]; 

    NSLog(@"web url = %@",locationOfWebService); 

    NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc]initWithURL:locationOfWebService]; 

    NSString *msgLength = [NSString stringWithFormat:@"%d",[soapFormat length]]; 

    [theRequest addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"]; 
    [theRequest addValue:@"GetUserList" forHTTPHeaderField:@"SOAPAction"]; 
    [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"]; 
    [theRequest setHTTPMethod:@"POST"]; 
    //the below encoding is used to send data over the net 
    [theRequest setHTTPBody:[soapFormat dataUsingEncoding:NSUTF8StringEncoding]]; 


    NSURLConnection *connect = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self]; 

    if (connect) { 
     webData = [[NSMutableData alloc]init]; 
     startActivityIndicator; 
    } 
    else { 
     NSLog(@"No Connection established"); 
    } 
} 

我收到此错误信息

<?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:Body><soap:Fault> <faultcode>soap:Client</faultcode><faultstring>System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: GetUserList. 
at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest() 
at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message) 
at System.Web.Services.Protocols.SoapServerProtocol.Initialize() 
at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response) 
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean&amp; abortProcessing) </faultstring><detail /></soap:Fault></soap:Body></soap:Envelope> 

我究竟做错了什么?

回答

0

声明:我是WSClient ++的作者,它是一个商业产品。

http://wsclient.neurospeech.com

创建简单的SOAP请求是容易的,但是,当你有对象的复杂的图形,用词典和原始XML处理可能是耗时的,WSClient ++生成用于与每个复杂类型SOAP代理目标C源代码。您只需进行一次方法调用即可检索结果。