RE: WebServices Question (plus some additional details)
RE: WebServices Question (plus some additional details)
- Subject: RE: WebServices Question (plus some additional details)
- From: "Mark" <email@hidden>
- Date: Sat, 24 Jan 2004 10:48:43 -0700
I finally got around to trying out the multiple records and it pretty much
worked right out of the box. I didn't have to follow up on my previous lead
regarding kWSRecordType.
I simply created a Web Service method that returned an array of objects (I
created a customer class with name, address and phone). Then I pointed the
WSMakeStub tool at the webservice WSDL, fixed the SOAPAction bug mentioned
previously and viola! I received an array of customer records (an NSArray
with NSDictionary objects). The key for me was casting the result of my call
to an NSArray object then accessing each one of those items as Dictionary
objects where I could use the "field name" to access the values.
I've included some code snippets here for posterity:
============= On the MAC side ================
// This is a call to the static method generated by the WSMakeStub
utility
// This is where I'm casting as an NSArray
NSArray *customerList = [[Service1Service GetCustomerList] retain];
unsigned count = [customerList count];
unsigned i;
for(i=0;i<count;i++)
{
NSDictionary *customerRecord = [customerList
objectAtIndex:i];
NSString *recordString = [NSString stringWithFormat:@"%@ %@
%@",
[customerRecord objectForKey:@"name"],
[customerRecord objectForKey:@"address"],
[customerRecord objectForKey:@"phone"]];
//display this in my textView control
[displayText insertText:recordString];
[displayText insertNewline:self];
}
[customerList release];
===============================================
======== On the .NET WebService side ==========
namespace foobar
{
// Note the attribute that made WSMakeStub work fine,
// otherwise I wasn't getting results properly
[SoapRpcService(RoutingStyle=SoapServiceRoutingStyle.SoapAction)]
public class Service1 : System.Web.Services.WebService
{
//... Constructor omitted
[WebMethod]
public customer[] GetCustomerList()
{
ArrayList list = new ArrayList();
list.Add(new customer("mark","12345
AnyStreet","801-547-1250"));
list.Add(new customer("chrystal","1015 E. 1500
N.","801-123-44567"));
list.Add(new
customer("jon","sdfasdfasfd","12341241243"));
return (customer[])list.ToArray(typeof(customer));
}
}
[Serializable]
public class customer
{
// Default constructor required to serialize object
public customer()
{
name = string.Empty;
address = string.Empty;
phone = string.Empty;
}
public customer(string _name, string _address, string
_phone)
{
name = _name;
address = _address;
phone = _phone;
}
public string name;
public string address;
public string phone;
}
}
===============================================
I know this wasn't the complex dataset-type mechanism you mentioned
originally but it's certainly enough for me since I really only need the
equivilent of a recordset and not a complex dataset structure.
Now I'm off to find my fortune making MAC and PC work hand-in-hand to solve
the World's problems, at least until my next roadblock.
-mark
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.