2013-05-20 85 views
0

我是iPhone編程的新手。使用下面的代碼我發送一個請求到服務器,但我沒有得到輸出。有人可以告訴我這段代碼有什麼錯誤嗎?沒有從iPhone上的服務器得到響應

NSString *soapMessage=[NSString stringWithFormat: 
          @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
          "<soap:Envelope \n" 
          "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n" 
          "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" 
          "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope\">\n" 
          "<soap:Body>\n" 
          "<OnlineStatus xmlns=\"http://tempuri.org\">\n" 
          "<CafeName>CyberCafeName</CafeName>\n" 
          "<FromDate>9/4/2012</FromDate>\n" 
          "<ToDate> 5/5/2013</ToDate>\n" 
          "</OnlineStatus>\n" 
          "</soap:Body>\n" 
          "</soap:Envelope>"]; 
    NSLog(@"%@",soapMessage); 
    NSURL *url = [NSURL URLWithString:@"http://www.ebidmanagerdemo.com/gjHouseOnline/xml/XMLDataService.asmx"]; 
    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; 
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; 
    [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
    [theRequest addValue: @"http://tempuri.org/OnlineStatus" forHTTPHeaderField:@"Soapaction"]; 
    [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
    [theRequest setHTTPMethod:@"POST"]; 
    [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

    if(theConnection) { 
     webData = [NSMutableData data]; 
    } 
    else { 
     NSLog(@"theConnection is NULL"); 

    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; 
    NSLog(@"%@",msgLength); 

我在控制檯收到此輸出錯誤信息:

2013-05-20 17:28:26.447 NewC Newcafezee[1166:11303] <?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"> 
<soap:Body> 
<OnlineStatus xmlns="http://tempuri.org"> 
<CafeName>CyberCafeName</CafeName> 
<FromDate>9/4/2012</FromDate> 
<ToDate> 5/5/2013</ToDate> 
</OnlineStatus> 
</soap:Body> 
</soap:Envelope> 
2013-05-20 17:28:28.355 NewC Newcafezee[1166:11303] <?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:Header><soap12:Upgrade xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"><soap12:SupportedEnvelope qname="soap:Envelope" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" /><soap12:SupportedEnvelope qname="soap12:Envelope" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" /></soap12:Upgrade></soap:Header><soap:Body><soap:Fault><faultcode>soap:VersionMismatch</faultcode><faultstring>System.Web.Services.Protocols.SoapException: Possible SOAP version mismatch: Envelope namespace http://schemas.xmlsoap.org/soap/envelope was unexpected. Expecting http://schemas.xmlsoap.org/soap/envelope/. 
    at System.Web.Services.Protocols.SoapServerProtocol.CheckHelperVersion() 
    at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters() 
    at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()</faultstring><detail /></soap:Fault></soap:Body></soap:Envelope> 
2013-05-20 17:28:28.357 NewC Newcafezee[1166:11303] fsdfsd 

這種原始的SOAP請求

POST /gjHouseOnline/xml/XMLDataService.asmx HTTP/1.1 
Host: www.ebidmanagerdemo.com 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "http://tempuri.org/OnlineStatus" 

<?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/"> 
    <soap:Body> 
    <OnlineStatus xmlns="http://tempuri.org/"> 
     <CafeName>string</CafeName> 
     <FromDate>dateTime</FromDate> 
     <ToDate>dateTime</ToDate> 
    </OnlineStatus> 
    </soap:Body> 
</soap:Envelope> 
+0

你可以請你發佈你原來的SOAP結構嗎? –

+0

你有沒有實現NSURLConnectionDelegate方法? – CRDave

+0

請在'http'的地方添加'/'在http://schemas.xmlsoap.org/soap/envelope \' – Yogi

回答

1

我剛剛更新線

"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope\">\n" 

"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" 

及其給我響應

<?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><OnlineStatusResponse xmlns="http://tempuri.org/"><OnlineStatusResult /></OnlineStatusResponse></soap:Body></soap:Envelope> 

我接受了空,但至少它不是錯誤。數據可能不適用於指定的參數。