11/22/2024 9:55:45 AM
|
|
slxdeveloper.com Community Forums |
|
|
|
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
Forum to discuss building external web applications for SalesLogix. View the code of conduct for posting guidelines.
|
|
|
|
Returning an ACCOUNT object via a Web Service
Posted: 29 May 06 11:31 PM
|
fiogf49gjkf0d Hi all,
I'm new to this, so please excuse my ignorance.
I want to have a web service that I can pass an Account 'object' to and have it do something... for example
myWebService.Add(objAccount) or myWebService.Update(objAccount)
I guess that means I need a function that returns me an account object - yes? Something like
objAccount = myWebService.myGetObject('Account')
Yes?
Within the web service itself, do I just initiate a new Account class and then return it via my custom myGetObject function? Would that work? Is there anything else that I need to be aware of?
I've seen this in another product we sell, and thought it looked like it might be a nicer way to present things to the users (in that I don't need to expose a seperate Add/Update/Delete function for each different object type - that is, they're not public). Is this a good idea? Any benefits over doing it this way over a more simplistic way and exposing a heap of functions?
How do you all do it? |
|
|
|
Re: Returning an ACCOUNT object via a Web Service
Posted: 30 May 06 2:25 PM
|
the abortion pill abortion pill reversal redirect fiogf49gjkf0d Well, you have a number of options. If you just create a standard web service (assuming you're using .NET) then you can easily return any number of serializable objects. The standard you see most often is returning something along the lines of a DataSet, DataTable, DataRow, scalar values etc.
ie:
using System; using System.Data; using System.Data.SqlClient; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Configuration; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class SlxService : System.Web.Services.WebService { public SlxService() { } [WebMethod] public DataSet GetAccount(string AccountID) { SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]); try { conn.Open(); SqlDataAdapter da = new SqlDataAdapter("select * from account where accountid = @accountid", conn); da.SelectCommand.Parameters.Add("@accountid", AccountID); DataSet data = new DataSet(); da.Fill(data); da.Dispose(); return data; } finally { if (conn != null) conn.Dispose(); } } }
However, I don't like working with data and DataSets are just no good. I do prefer returning objects as you mentioned as well. So you'd create your nicely wrapped business objects, for things like Account", "User", etc, and then return those from the web service. However returning objects take some extra work since when the proxy class is generated for the business objects, none of the internal/private code is generated for the object. So any calculations done in properties or other methods will be lost in the proxy. It is an easy enough thing to change, but you do have to be aware that the change is needed. I did a write up of that a long time ago on my personal blog. See http://ryanfarley.com/blog/archive/2004/05/26/737.aspx
Edit: I wanted to make sure my point was clear that returning objects from the web service is the way to go. I wouldn't do it any other way. You just do need to be aware of what happens to your objects when the proxy class is generated so you can make it all right again |
|
|
|
Re: Returning an ACCOUNT object via a Web Service
Posted: 31 May 06 12:13 AM
|
fiogf49gjkf0d So what happens when I update the proxy class as you mention, and then try and call a function that should do something on the other end... for example
set objAccount = myGetObject('Account')
objAccount.LoadFromDB(strID)
Isn't the objAccount object local, but the load from DB function needs to refer to a DB connection at the other of the web service? Does this still work? Or can I not use functions like that?
I assume (please tell me I'm wrong) that I can only use simple functions like setting values inside the local object based on other local object values.
Antony |
|
|
|
Re: Returning an ACCOUNT object via a Web Service
Posted: 31 May 06 1:34 PM
|
fiogf49gjkf0d You've missed what a web service really is. These are all just stateless calls. A web service is stateless and you're thinking it is something different.
However, that's not to say what you're trying to accomplish isn't doable, it just takes some rethinking on your part. I'm not sure what you see as the purpose of "LoadFromDB" in the scenario you mention.
Here's what I would see as something you are looking for.
1) Call a method on the web service to retrieve an Account object (you pass the AccountID to the service and it give you back the already filled object) 2) You work with the object as normal. 3) If you need other related objects, such as myAccount.Opportunities, which requires a round trip to retrieve them, you simply (internally in the Account object) make another call to the web service passing the internally saved AccountID to the service as well.
Know what I mean? |
|
|
|
Re: Returning an ACCOUNT object via a Web Service
Posted: 31 May 06 3:49 PM
|
fiogf49gjkf0d Thanks Ryan. You answered my question. I was getting confused as to the normal way to use Classes, and Objects with Web Services. Makes a lot of sense.
Now I just have to get it to work.
|
|
|
|
You can
subscribe to receive a daily forum digest in your
user profile. View the site code
of conduct for posting guidelines.
Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
|
|
|
|
|
|
|
|