2013-04-25 47 views
0
NSURL *url = [NSURL URLWithString:@"http://192.168.1.56/AMSP/AMSPWS.asmx"]; 

NSString *soapMsg=[NSString stringWithFormat:@"<?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>" 
        "<PostXMLStr xmlns=\"http://tempuri.org/\">" 
        "<cust>%@</cust>" 
        "<tran>%@</tran>" 
        "<ret>%@</ret>" 
        "<ppay>%@</ppay>" 
        "<recp>%@</recp>" 
        "<sCode>%@</sCode>" 
        "<companyShortName>%@</companyShortName>" 
        "<companyCode>%@</companyCode>" 
        "</PostXMLStr>" 
        "</soap:Body>" 
        "</soap:Envelope>",cust,trans,RETURNS,prepayment,receipt,spcode1,companyShortName,companyCode]; 


NSMutableURLRequest *requests = [NSMutableURLRequest requestWithURL:url 
                 cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData 
                timeoutInterval:5]; 
NSString *msgLength = [NSString stringWithFormat:@"%d",[soapMsg length]]; 
[requests setHTTPMethod:@"POST"]; 
[requests addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[requests addValue:msgLength forHTTPHeaderField:@"Content-Length"]; 
[requests addValue:@"http://tempuri.org/PostXMLStr" forHTTPHeaderField:@"SOAPAction"]; 

[requests setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding ]]; 

NSURLResponse *response; 
NSError *error = nil; 

NSData *data =[[NSMutableData alloc]init]; 
data = [NSURLConnection sendSynchronousRequest:requests returningResponse:&response error:&error]; 

NSString *stringSoap; 

stringSoap = [[NSString alloc] initWithData:data encoding:NSMacOSRomanStringEncoding]; 
NSDictionary *headers = [(NSHTTPURLResponse *)response allHeaderFields]; 

我是通過目標C連接WebService的新手。我不知道如何檢查XML是否連接到WebService。當我打印stringSoap時,我沒有得到任何價值。我不知道這是調用XML的正確方法。如何檢查XML是否連接到WebService。任何幫助將不勝感激。提前致謝。通過XML連接Webservice

+0

首先,你所要求不是'XML'其'SOAP' Web服務調用,所以一定要確保你做得對。無論您的webservice是讀取XML還是編碼數據? – 2013-04-25 09:47:14

+0

它編碼的數據 – user2134883 2013-04-25 09:50:59

+0

把你的服務器端腳本在這裏進行審查,如果可能的。 – 2013-04-25 09:55:29

回答