My favorites
▼
|
Sign in
touchcode
Repository of iPhone and iPod Touch source code.
Project Home
Export to GitHub
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
58
attachment: HelloSOAPViewController.m
(6.5 KB)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//
// HelloSOAPViewController.m
// HelloSOAP
//
// Created by Raj Kondapalli on 4/25/09.
// Copyright __MyCompanyName__ 2009. All rights reserved.
//
#import "HelloSOAPViewController.h"
@implementation HelloSOAPViewController
@synthesize nameInput,greeting,webData,soapResults,xmlParser;
-(IBAction) buttonClick:(id) sender
{
recordResults = FALSE;
NSString *soapMessage = [NSString stringWithFormat:
@"<soapenv:Envelope xmlns:q0=\"http://wsexample.myeclipse.genuitec.com\"\n"
"xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n"
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"
"<soapenv:Header></soapenv:Header>\n"
"<soapenv:Body>\n"
"<q0:example><q0:in0>%@</q0:in0></q0:example>\n"
"</soapenv:Body>\n"
"</soapenv:Envelope>\n",nameInput.text
];
NSLog(soapMessage);
//NSURL *url = [NSURL URLWithString:@"http://localhost:8080/HelloWorld1/services/HelloWorldService"];
NSURL *url = [NSURL URLWithString:@"http://esbdev1:5555/invoke/GnePROP_QualityDashboard.getQualityDashboarddata.Services:getQualityDashboarddata?tablename=PCS_PROD_GROUP_STATS"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
//NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];
[theRequest addValue: @"text/html; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"" 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");
}
[nameInput resignFirstResponder];
}
- (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
{
NSLog(@"ERROR with theConenction");
[connection release];
[webData release];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
//NSString* theXML = @"<Root><Item><Text>SmallText</Text></Item><Item><Text>Small Text 2</Text></Item></Root>";
CXMLDocument *theXMLDocument = [[CXMLDocument alloc] initWithXMLString:theXML options:0 error:nil];
//NSLog(theXMLDocument);
//[theXMLDocument setShouldResolveExternalEntities:YES]
[theXML release];
//[formatedXML release];
NSArray *resultNodes = NULL;
NSMutableArray *blogEntries = [[NSMutableArray alloc] init];
resultNodes = [theXMLDocument nodesForXPath:@"//Item" error:nil];
NSLog(@"resultNodes: %@", resultNodes);
// Loop through the resultNodes to access each items actual data
for (CXMLElement *resultElement in resultNodes) {
// Create a temporary MutableDictionary to store the items fields in, which will eventually end up in blogEntries
NSMutableDictionary *blogItem = [[NSMutableDictionary alloc] init];
// Create a counter variable as type "int"
int counter;
// Loop through the children of the current node
for(counter = 0; counter < [resultElement childCount]; counter++) {
// Add each field to the blogItem Dictionary with the node name as key and node value as the value
[blogItem setObject:[[resultElement childAtIndex:counter] stringValue] forKey:[[resultElement childAtIndex:counter] name]];
}
// Add the blogItem to the global blogEntries Array so that the view can access it.
[blogEntries addObject:[blogItem copy]];
}
/*if( xmlParser )
{
[xmlParser release];
}
xmlParser = [[NSXMLParser alloc] initWithData: webData];
[xmlParser setDelegate: self];
[xmlParser setShouldResolveExternalEntities: YES];
[xmlParser parse];*/
[connection release];
[webData release];
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
attributes: (NSDictionary *)attributeDict
{
//NSLog([elementName length]);
if( [elementName isEqualToString:@"PRODUCT_GROUP"])
//if( [elementName isEqualToString:@"PRODUCT_GROUP"])
{
if(!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
recordResults = (BOOL *)TRUE;
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if( recordResults )
{
[soapResults appendString: string];
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if( [elementName isEqualToString:@"PRODUCT_GROUP"])
{
recordResults = FALSE;
greeting.text = soapResults;
[soapResults release];
soapResults = nil;
}
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
Powered by
Google Project Hosting