2013-02-16 31 views
1

I referred this link &發現它非常有用,但是當我開始嘗試所有可能的方法時,我無法獲得所需的輸出。SVC webservice - objective-c

NSString *soapMessage = [NSString stringWithFormat: 
         @"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
         "<SOAP:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" 
         "<SOAP:Body>\n" 
         "<BindCategory xmlns=\"http://tempuri.org/\">\n" 
         "</SOAP:Body>\n" 
         "</SOAP:Envelope>\n" 
         ]; 

NSLog(@"soapMessage: \n%@",soapMessage); 

NSURL *url = [NSURL URLWithString:@"http://assetwebservice.sudesi.in/Service/"]; 

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/IService/BindCategory" forHTTPHeaderField:@"SOAPAction"]; 
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
[theRequest setHTTPMethod:@"POST"]; 
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 

我想我一定會犯一些小錯誤。我得到以下輸出。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>404 (Page Not Found) Error - Ever feel like you're in the wrong place?</title> 
<link href="http://p3nlhclust404.shr.prod.phx3.secureserver.net/SharedContent/404-etc-styles.css" rel="stylesheet" type="text/css" media="screen" /> 
</head> 
<body> 
    <div class="body-404"> 
     <h1> 
      <span>Ever feel you're in the wrong place</span> 
     </h1> 
     <div class="info-container"> 
      <div class="inner-border clear-fix"> 
       <h2 class="info-top"> 
        404 (Page Not Found) Error 
       </h2> 
       <div class="site-owner-404"> 
        <h3>If you're the <strong>site owner,</strong> one of two things happened:</h3> 
        <ol> 
         <li> 
          1) You entered an incorrect URL into your browser's address bar, or 
         </li> 
         <li> 
          2) You haven't uploaded content. 
         </li> 
        </ol> 
       </div>  
       <div class="site-visitor-404"> 
        <h3>If you're a <strong>visitor</strong> and not sure what happened:</h3> 
        <ol> 
         <li> 
          1) You entered or copied the URL incorrectly or 
         </li> 
         <li> 
          2) The link you used to get here is faulty. 
         </li> 
         <li class="last"> 
          (It's an excellent idea to let the link owner know.) 
         </li> 
        </ol> 
       </div> 
      </div> 
     </div> 
    </div> 
</body> 
</html> 

有人能幫助理解我在做什麼錯嗎? 任何幫助非常感謝?

回答

3

嘿傢伙們發現瞭解決方案。 soap消息中的第二行已更正。

"<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" 

此外在URL字符串.svc擴展名缺失。我用聲明糾正了它。 http://assetwebservice.sudesi.in/service.svc 查看service.svc中的s是小寫,而在soapaction參數中是大寫。

下面是帶有http頭參數的整個soap消息。

NSString *soapMessage = [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" 
         "<BindCategory xmlns=\"http://tempuri.org/\">\n" 
         "</BindCategory>\n" 
         "</soap:Body>\n" 
         "</soap:Envelope>\n" 
         ]; 
NSLog(@"soapMessage: \n%@",soapMessage); 

NSURL *url = [NSURL URLWithString:@"http://assetwebservice.sudesi.in/service.svc"];  
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/IService/BindCategory" forHTTPHeaderField:@"soapaction"]; 
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; 
[theRequest setHTTPMethod:@"POST"]; 
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; 

,還有一件事讓我困惑的是,即使是一個GET請求,它拋出我的「錯誤連接」 NSLog &當我將其更改爲POST

+1

感謝後成功。你的代碼工作+ 1 – Pramesh 2014-01-08 15:10:58

+0

@Pramesh嘿,謝謝你的朋友 – 2014-01-09 06:06:14