Using ObjC to access SOAP/WSDL server
Using ObjC to access SOAP/WSDL server
- Subject: Using ObjC to access SOAP/WSDL server
- From: email@hidden
- Date: Sun, 04 May 2008 09:37:50 -0700 (PDT)
Greetings Jeff & fellow Cocoa Developers:
I need to access a SOAP/WSDL server.
I'm trying to convert some Java code to its ObjC equivalent.
Client (Mac) <--- SOAP ----> WSDL server.
Here's where I'm coming from:
1) I need to make a POST connection.
2) Content type is SOAP (text/xml).
3) I need to set a request property as shown below.
This is a synchronous connection, waiting for a response & close the connection.
..
private String SOAP_SERVER_URL = "http://myconnect.eccron.com/soap/sync";
private final String SOAP_ACTION = "http://myconn.eccron.com/2007/02";
..
xmlstream = (StreamConnection)Connector.open(SOAP_SERVER_URL + ";deviceside=false",Connector.READ_WRITE,true);
connection = (HttpConnection)xmlstream;
connection.setRequestMethod(HttpConnection.POST);
connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
connection.setRequestProperty("SOAPAction",SOAP_ACTION);
..
4) Send the SOAP envelope:
...
// -------------------------------- Send Request -------------------------------
OutputStream out = connection.openOutputStream();
out.write(xmlreq.getBytes()); // 'xmlreq' is a concatenated XML string that is the SOAP envelope & message.
out.flush();
out.close();
5) And I need to interpret the response:
// -------------------------------- Get Response -------------------------------
// Get the connection status
status = connection.getResponseCode();
...
=============
I don't need to know any particular socket. I'm told that all I need to do is to access a given URI stated above.
I've tested the URI with a browser; and I do get a contact, albeit access was denied since I didn't supply a SOAP message with authorization.
I've read some blogs and follow some of the CocoaDev discussions.
I've learned that I should use NSFileHandle.
I believe you're onto something; and I need your (and/or other CococDev members) help.
What I've gotten so far is:
NSFileHandle *myFileHandle ;
// ... generate a file descriptor of the target URL...
// [myFileHandle initWithFileDescriptor:fileDescriptor closeOnDealloc:YES];
-(void)process:(id)notification {
NSFileHandle *fh = [notification object];
NSMutableData *data = [fh availableData];
NSString *dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
/* Process the data however you need to here */
[dataString release];
}
...
I'm hitting a brick wall here.
I know there's a way...
Can you (and/or fellow CocoaDev members) please supply some guidance here and/or point to some simple docs?
Thanks; I would truly appreciate it!
Regards,
Ric
On Apr 9, 2008, at 2:53 PM, Jeff LaMarche wrote:
I'm periodically getting this message
*** -[NSConcreteFileHandle availableData]: Invalid argument
printed to the console of an application I'm working on. I'm confused about what it means because availableData doesn't take an argument.
Here's what I'm doing: I'm using NSFileHandle to handle socket communications with a remote server. I create an old-fashioned network socket, allocate an NSFileHandle, feed it the socket using initWithFileDescriptor:, and then use readInBackgroundAndNotify after specifying to receive NSFileHandleReadCompletionNotifications. The odd thing is that despite this error getting printed in the console, my code is working as expected - I am getting data from the file handle and the data appears to be 100% correct.
My call back method looks like this:
- (void)updateStatusCallback:(id) notification
{
NSFileHandle *fh = [notification object];
NSData *data = [fh availableData]; // <----- This call generates the message in the console sometimes... but it works
NSString *theString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// code to process the response
}
In the debugger, I see no difference in fh between calls that generate the message and those that don't - it's always an NSConcreteFileHandle with a positive file descriptor. This message show up rougly about 10% of the time that the callback gets called, although it's not consistent.
Thanks in advance!
Jeff
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden