2012-02-15 14 views
0

私はSOAPにはとても慣れていないので、私の愚かさは気になりません。 私はUPCコードで送信しretriveしたい ...これは私が取得するためにやっているものですiOS上のSOAPが動作しない

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 

xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:intf="HTTP://207.7.208.250" targetNamespace="HTTP://207.7.208.250"> 
<wsdl:types> 
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:intf="HTTP://207.7.208.250" elementFormDefault="qualified" targetNamespace="HTTP://207.7.208.250"> 
<element name="ProductInquiryResponse"> 
<complexType> 
<sequence> 
<element name="EclipsePN" type="string"/> 
<element name="Description" type="string"/> 
<element name="AlternateDescription" type="string"/> 
<element name="UPC" type="string"/> 
<element name="Catalog" type="string"/> 
<element name="PartNumber" type="string"/> 
<element name="AvailQty" type="string"/> 
<element name="AvailDate" type="string"/> 
<element name="AvailUOM" type="string"/> 
<element name="Price" type="string"/> 
<element name="PriceUOM" type="string"/> 
<element name="ImageURL" type="string"/> 
<element name="SpecSheetURL" type="string"/> 
<element name="ErrorDescription" type="string"/> 
</sequence> 
</complexType> 
</element> 
<element name="ProductInquiry"> 
<complexType> 
<sequence> 
<element name="Login" type="string"/> 
<element name="Password" type="string"/> 
<element name="EclipsePN" type="string"/> 
<element name="UPC" type="string"/> 
<element name="HomeBranch" type="string"/> 
</sequence> 
</complexType> 
</element> 
<element name="CALL_SSI_MOBILE_PROD_INQ"> 
<complexType> 
<sequence> 
<element ref="intf:ProductInquiry"/> 
</sequence> 
</complexType> 
</element> 
<element name="CALL_SSI_MOBILE_PROD_INQResponse"> 
<complexType> 
<sequence> 
<element ref="intf:ProductInquiryResponse"/> 
</sequence> 
</complexType> 
</element> 
</schema> 
</wsdl:types> 
<wsdl:message name="CALL_SSI_MOBILE_PROD_INQResponse"> 
<wsdl:part name="parameters" element="intf:CALL_SSI_MOBILE_PROD_INQResponse"></wsdl:part> 
</wsdl:message> 
<wsdl:message name="CALL_SSI_MOBILE_PROD_INQRequest"> 
<wsdl:part name="parameters" element="intf:CALL_SSI_MOBILE_PROD_INQ"></wsdl:part> 
</wsdl:message> 
<wsdl:portType name="SSI_MOBILE_PROD_INQ"> 
<wsdl:operation name="CALL_SSI_MOBILE_PROD_INQ"> 
<wsdl:input name="CALL_SSI_MOBILE_PROD_INQRequest" message="intf:CALL_SSI_MOBILE_PROD_INQRequest"></wsdl:input> 
<wsdl:output name="CALL_SSI_MOBILE_PROD_INQResponse" message="intf:CALL_SSI_MOBILE_PROD_INQResponse"></wsdl:output> 
</wsdl:operation> 
</wsdl:portType> 
<wsdl:binding name="SSI_MOBILE_PROD_INQSOAPBinding" type="intf:SSI_MOBILE_PROD_INQ"> 
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
<wsdl:operation name="CALL_SSI_MOBILE_PROD_INQ"> 
<wsdlsoap:operation soapAction=""/> 
<wsdl:input name="CALL_SSI_MOBILE_PROD_INQRequest"> 
<wsdlsoap:body use="literal"/> 
</wsdl:input> 
<wsdl:output name="CALL_SSI_MOBILE_PROD_INQResponse"> 
<wsdlsoap:body use="literal"/> 
</wsdl:output> 
</wsdl:operation> 
</wsdl:binding> 
<wsdl:service name="SSI_MOBILE_PROD_INQ"> 
<wsdl:port name="SSI_MOBILE_PROD_INQ" binding="intf:SSI_MOBILE_PROD_INQSOAPBinding"> 
<wsdlsoap:address location="HTTP://207.7.208.250:31361/SSI_MOBILE_PROD_INQ"/> 
</wsdl:port> 
</wsdl:service> 
</wsdl:definitions> 

次のようにhttp://207.7.208.250:31361/SSI_MOBILE_PROD_INQ

WSDLに位置SOAP Webサービスがある持っています結果として得られるXMLを解析し、データを取得します。

NSMutableString *sRequest = [[NSMutableString alloc] init]; 
     [sRequest appendString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"]; 
     [sRequest appendString:@"<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/\">"]; 
    [sRequest appendString:@"<soap:Body>"]; 
    [sRequest appendString:@"<SSI_MOBILE_PROD_INQ xmlns=\"http://207.7.208.250:31361/SSI_MOBILE_PROD_INQ/\">"]; 
    [sRequest appendString:@"<CALL_SSI_MOBILE_PROD_INQ>"]; 
    [sRequest appendString:@"<UPC>"]; 
    [sRequest appendString:@"78285630648"]; 
    [sRequest appendString:@"</UPC>"]; 
    [sRequest appendString:@"</CALL_SSI_MOBILE_PROD_INQ>"]; 
    [sRequest appendString:@"</SSI_MOBILE_PROD_INQ>"]; 
    [sRequest appendString:@"</soap:Body>"]; 
    [sRequest appendString:@"</soap:Envelope>"]; 

    NSURL *weatherServiceURL = [NSURL URLWithString:@"http://207.7.208.250:31361/SSI_MOBILE_PROD_INQ"]; 
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:weatherServiceURL]; 

    [request addValue:@"text/xml; charset:UTF-8" forHTTPHeaderField:@"Content-Type"]; 
    [request addValue:@"http://207.7.208.250:31361/SSI_MOBILE_PROD_INQ" forHTTPHeaderField:@"SOAPAction"]; 

    [request setHTTPMethod:@"POST"]; 

    [request setHTTPBody:[sRequest dataUsingEncoding:NSUTF8StringEncoding]]; 

    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 

    if (conn) { 
     myMutableData = [NSMutableData data]; 
     NSLog(@"Conn is true"); 
    } 
    [NSURLConnection connectionWithRequest:request delegate:self]; 

    NSError *WSerror; 
    NSURLResponse *WSresponse; 

    NSData *returnData = (NSMutableData*)[NSURLConnection sendSynchronousRequest:request 
              returningResponse:&WSresponse error:&WSerror]; 
if(WSerror){ 
    NSLog(@"%@", [WSerror localizedDescription]); 
} 
if (returnData) { 

    NSString *content = [NSString stringWithUTF8String:[myMutableData bytes]]; 
    DebugLog(@"yeah %@", content); 
} 

コンテンツ文字列からの出力はありません。 私はSOAPメソッドを正しく呼び出さないと思います.... あなたの考えは?

+2

をあなたはここにこれを試してみましたか? http://sudzc.com/ – HeikoG

+0

はい、私が試した最初のことでした それは私のためにコンパイル可能なコードを生成しませんでした.... –

+0

sudzcは私にとって非常に効率的であることを証明しています、あなたは問題のいくつかの詳細を提供できますか? sudzcのコードで。あなたのサービスがパスワードと同じ名前になっていることはめったにあり得ない問題があることに注意してください。ファイルの上にもう一方のファイルを上書きして、SDKを解除する –

答えて

0

は、私はあなたのコードでいくつかの問題を参照してください。

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 
[NSURLConnection connectionWithRequest:request delegate:self]; 
NSData *returnData = (NSMutableData*)[NSURLConnection sendSynchronousRequest:request 
              returningResponse:&WSresponse error:&WSerror]; 

connectionWithRequest:デリゲートを: が作成し、初期化されたURLに接続を返し、URL要求のためのデータをロードするために開始します。

initWithRequest:デリゲート: が初期化されたURLに接続を返し、URL要求のためのデータをロードするために開始します。

sendSynchronousRequest:returningResponse:エラー: 指定されたURL要求の同期ロードを実行します。

は参照してください:NSURLConnection Class Reference

なぜあなたは同じ方法で、3つすべてをやっていますか? 2つの非同期URL接続と1つの同期接続。

sendSynchronousRequestは、メインスレッドで使用することを強くお勧めします。

URLリクエストの非同期ロードを送信するには、URL接続オブジェクトが1つ必要です。後に残りの部分をコメントアウトします。

if (conn) { 
     myMutableData = [NSMutableData data]; 
     NSLog(@"Conn is true"); 
    } 

変更myMutableData = [NSMutableData data]; to myMutableData = [[NSMutableData alloc] init];

および非同期のコールバックを受け取るためにNSURLConnectionDelegateメソッドを実装:

-(NSCachedURLResponse *)connection:(NSURLConnection *)connection 
       willCacheResponse:(NSCachedURLResponse *)cachedResponse 
{ 
    return nil; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; 
    NSInteger statusCode = [httpResponse statusCode]; 
    NSLog(@"Http Status Code: %i",statusCode); 
    if ([response respondsToSelector:@selector(statusCode)]) 
{ 
    int statusCode = [((NSHTTPURLResponse *)response) statusCode]; 
    if (statusCode >= 400) 
    { 
    [connection cancel]; // stop connecting; no more delegate messages 
    NSDictionary *errorInfo 
     = [NSDictionary dictionaryWithObject:[NSString stringWithFormat: 
      NSLocalizedString(@"Server returned status code %d",@""), 
      statusCode] 
            forKey:NSLocalizedDescriptionKey]; 
    NSError *statusError 
     = [NSError errorWithDomain:@"HTTP Error" 
          code:statusCode 
         userInfo:errorInfo]; 
    [self connection:connection didFailWithError:statusError]; 
    } 
} 
    [myMutableData setLength:0]; 
} 

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

- (void)connection:(NSURLConnection *)connection 
    didFailWithError:(NSError *)error 
{ 
    NSLog(@"Connection failed! Error - %@ %@", 
      [error localizedDescription], 
      [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]); 
    connection = nil; 
    [myMutableData release],myMutableData = nil; 
} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{ 
    NSString *result =[[NSString alloc]initWithData:myMutableData encoding:NSUTF8StringEncoding]; 
    NSLog(@"downloaded output %@",result); 

    [result release]; 
    [myMutableData release],myMutableData = nil;  
} 
関連する問題