2013-05-08 61 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源代碼。您只需進行一次方法調用即可檢索結果。