StrataFrame Forum

Webservice with a business object

http://forum.strataframe.net/Topic32346.aspx

By Ross L Rooker, Sr.(1) - 1/1/2014

Does someone have a sample of using a business object in a webservice?
By Tony Charpentier - 1/3/2014

Hello

I can help you in the webservice ,

what kind of sample , are you waiting ?   a dataset serialize or a simple value  ?

ps : i prefer a json service rest instead of webservice, cause json is more light than xml format, in large data case.
By Trent L. Taylor - 1/3/2014

Ross:

It isn't going to be any different using the BO in a web service.  The only difference is that you will want to setup your data sources in the global.asax

  1. Make sure that you have a global.asax in your web service project, if not, you can just add one through the "Add New Item"

    http://forum.strataframe.net/Uploads/Images/70d5d71e-4d25-4a6f-9836-972a.png
  2. Next, you will want to define your data sources when the application starts up.  The global.asax will have a method called "Application_Start", add your data sources there:

    http://forum.strataframe.net/Uploads/Images/1a8bd454-8c9e-4429-8055-b17c.png
  3. Now you are ready to use your BOs in your project.  First, make sure that you have a reference to the assembly that houses your business objects.  You can do this in a Web Service project or JSON, either one.  If this is your first go around, you may want to use a web service to get your feet wet.  If this isn't going to be really high traffic, then the web service will be fine.  JSON is lighter weight, but there is also more wiring required.

    Note: You can also just create a web handler which can be even lighter weight than JSON.  I have used web handlers for things like activation servers and really high traffic servers.  I create my own EDI format and then serialize it back and forth between the client and server, and you can't get any lighter since I am 100% in control of every byte being transmitted.


  4. Create a new web service (MyWebservice.asmx).  Then create a web method and use your BO:



    [WebMethod]
    public string MyTestWebMethod()
    {
      using(MyBO bo = new MyBO())
      {
         bo.FillWithWhatever();

         //-- Do whatever you need to do

         //-- Return the results
         return bo.MyFullName;
      }
    }


By Ross L Rooker, Sr.(1) - 1/6/2014

Thanks Trent. Worked like a charm.