2011-09-28 12 views
0

我試圖訪問http://services-staging.cmtnyc.com/payment/payment.asmx Web服務和目標c:web服務,如何講述具體的方法來訪問

AuthorizeCreditTrip我查了.NET應用此WebService和它工作正常,但在Objective-C它不會以相同的數據作出響應。

Web服務公開5種方法,我想訪問4th。但我認爲這段代碼並沒有指定訪問的方式。 forHTTPHeaderField:@"SOAPAction"告訴我,但我不認爲它的正確鏈接放在這裏。

不響應意味着它沒有發送任何迴應。

我認爲我無法設置有效的SOAPAction

-(IBAction)sendData 
{ 
    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:Header>" 
         "<AuthenticationHeader xmlns=\"http://services.cmtnyc.com/payment\">" 
         "<Username>validusername</Username>" 
         "<Password>validpass</Password>" 
         "<DataSource>validsource</DataSource>" 
         "</AuthenticationHeader>" 
         "</soap:Header>" 
         "​​​​​​<soap:Body>" 
         "<AuthorizeCreditTrip xmlns=\"http://services.cmtnyc.com/payment\">" 
         "<requestId>%d</requestId>" 
         "<deviceId>abcd</deviceId>" 
         "<userId>3003</userId>" 
         "<jobId>000047</jobId>" 
         "<paymentAmt>1</paymentAmt>" 
         "<fareAmt>0</fareAmt>" 
         "<tipAmt>0</tipAmt>" 
         "<tollAmt>0</tollAmt>" 
         "<surchargeAmt>0</surchargeAmt>" 
         "<taxAmt>0</taxAmt>" 
         "<convenienceFeeAmt>0</convenienceFeeAmt>" 
         "<swipeData></swipeData>" 
         "<accountNumber>validaccount</accountNumber>" 
         "<expiryDate>validdate</expiryDate>" 
         "<zipCode>73000</zipCode>" 
         "<cvv2>227</cvv2>" 
         "<cardReaderMethod>0</cardReaderMethod>" 
         "<encryptionKeyVersion>0</encryptionKeyVersion>" 
         "<encryptedToken></encryptedToken>" 
         "<encryptionAlgorithm>0</encryptionAlgorithm>" 
         "<pickupDate>2011-09-12</pickupDate>" 
         "<pickupLatitude>0</pickupLatitude>" 
         "<pickupLongitude>0</pickupLongitude>" 
         "<dropoffDate>2011-09-16</dropoffDate>" 
         "<dropoffLatitude>0</dropoffLatitude>" 
         "<dropoffLongitude>0</dropoffLongitude>" 
         "<passengerCount>0</passengerCount>" 
         "<tripDistance>124</tripDistance>" 
         "<tripDuration>0</tripDuration>" 
         "<readyToSettle>false</readyToSettle>" 
         "</AuthorizeCreditTrip>" 
         "</soap:Body>" 
         "</soap:Envelope>",55258]; 

    NSURL *url = [NSURL URLWithString: @"http://services-staging.cmtnyc.com/payment/payment.asmx"]; 
    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; 

    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]]; 
    [req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
    [req addValue:@"http://services.cmtnyc.com/payment/AuthorizeCreditTrip" forHTTPHeaderField:@"SOAPAction"]; 
    [req addValue:msgLength forHTTPHeaderField:@"Content-Length"]; //---set the HTTP method and body--- 
    [req setHTTPMethod:@"POST"]; 
    [req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]]; 

    NSLog(@"%@", soapMsg); 

    conn = [[NSURLConnection alloc] initWithRequest:req delegate:self]; 
    if (conn) 
    { 
     webData = [[NSMutableData data] retain]; 
    } 

} 

-(void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *) response { 
    [webData setLength: 0]; 
} 

-(void) connection:(NSURLConnection *) connection didReceiveData:(NSData *) data 
{ 
    [webData appendData:data]; 
} 

-(void) connection:(NSURLConnection *) connection didFailWithError:(NSError *) error { 
    [webData release]; 
    [connection release]; 
} 

-(void) connectionDidFinishLoading:(NSURLConnection *) connection 
{ 
    NSLog(@"..DONE. Received Bytes: %d", [webData length]); 
    NSString *theXML = [[NSString alloc] //---shows the XML--- 
         initWithBytes:[webData mutableBytes] length:[webData length] 
         encoding:NSUTF8StringEncoding]; 
    NSLog(@"....%@",theXML); 
    [theXML release];                      

    // [activityIndicator stopAnimating];                                   
    [connection release];                                  
    [webData release]; 
} 
+0

,我建議你剛剛檢查參數是否一切正確與否,因爲烏爾代碼看起來不錯.. – sicKo

+0

其實這個Web服務暴露5種方法和此代碼應訪問AuthorizeCreditTrip方法,但這些代碼不會告訴哪個函數訪問。 。我認爲這是問題.... – Azhar

+0

@Azhar:你找到解決方案嗎?我遇到了同樣的問題。你能證明這個問題的解決方案嗎? – SKK

回答

0

我用下面的代碼,並致力於對我罰款:

NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url]; 

    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]]; 
    [req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
    [req addValue:@"http://tempuri.org/SearchCustomer" forHTTPHeaderField:@"SOAPAction"]; 
    [req addValue:msgLength forHTTPHeaderField:@"Content-Length"]; 

    [req setHTTPMethod:@"POST"]; 
    [req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]]; 

其中網址我的網址,soapMsg是我的SOAP消息,@「HTTP ://tempuri.org/Method「是肥皂行動。

+0

同樣的問題.....不知道問題出在哪裏??? – Azhar

0

這裏是我有工作:

NSURL *urlWS = [NSURL URLWithString:kUrlServer]; 
NSMutableURLRequest *theRequest; 
theRequest = [NSMutableURLRequest requestWithURL:urlWS]; 

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]]; 
[theRequest addValue: @"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; 
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
[theRequest setHTTPMethod:@"POST"]; 
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 

也許你缺少application/soap+xml

乾杯

+0

SoapAction怎麼樣?是好的 – Azhar