0

私はメソッドの説明を持つwsdlを持っているiPhoneプロジェクトに取り組んでおり、これらのメソッドにはxmlが含まれています。SOAP を使用して xml を取得し、解析するには、wsdl にあるこれらのメソッドを呼び出す必要があります。非常に多くのリンクとチュートリアルを読みましたが、wsdl でメソッドを呼び出すことができませんでした。リンクや提案を教えていただければ幸いです。

4

2 に答える 2

0

このコードを試してください。それは私のために働いた。

[注:GetDictionaryは、Webサービスに表示される私のメソッド名です。URLには、Webサービスに表示されるURLを以下の部分に記入してください。コーディングで記​​述したURLと一致している必要があります。一致していないと、出力が得られません(Webサービスからコピーすることをお勧めします)]

-(IBAction)loadData
{

NSString *soapMessage = [NSString stringWithFormat:
                         @"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
                         "<SOAP-ENV:Body>\n"
                         "<GetDictionary></GetDictionary>\n"
                         "</SOAP-ENV:Body>\n"
                         "</SOAP-ENV:Envelope>"];

NSURL *url = [NSURL URLWithString:@"http://c70.narolainfotech.local/WCFTest/RestServiceImpl.svc/basic"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"urn:RestServiceImpl/GetDictionary" forHTTPHeaderField:@"soapAction"];
// [theRequest addValue: @"urn:RestServiceImpl/getDataBY_ID" 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] retain];
   }
   else
   {
      NSLog(@"theConnection is NULL");
    }
}

connectionDidFinishLoadingで、次のコードを記述します。

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);


NSString *strData = [[NSString alloc]initWithData:webData encoding:NSUTF8StringEncoding];
NSLog(@"result : %@",strData);

NSString *result=nil;
NSString *str;

NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
theXML = [theXML stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
theXML = [theXML stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
theXML = [theXML stringByReplacingOccurrencesOfString:@"&amp;" withString:@"&"];
//NSLog(@"XML from Web-Service ======= \n\n %@",theXML);

NSArray *array=[theXML componentsSeparatedByString:@"<GetDictionaryResult>"];
for(int i=1;i<[array count];i++)
{
    str=[array objectAtIndex:i];

    NSRange ranfrom=[str rangeOfString:@"</GetDictionaryResult>"];
    result =[str substringToIndex:ranfrom.location];
}
NSLog(@"result ::: %@",result);
}

それがあなたのために働くことを願っています。:)

于 2013-01-22T06:42:29.050 に答える
0

http://sudzc.com/を使用できます。これにより、準備が整った WSDL が提供されます。

これは、XSLT を使用して SOAP ベースの Web サービス定義 WSDL ファイルを完全なコード パッケージに変換する .NET Web サイト ソリューションです。生成されたコードは読みやすく、更新も簡単です。

SudzC は複数のプラットフォームをサポートしていますが、iPhone 開発用の Objective-C ライブラリのコード生成に焦点を当てています。

参照http://code.google.com/p/sudzc/

于 2013-01-22T06:12:46.353 に答える