I am sorry I marked this post as answered and now I mark it unanswered again, but I just realized I was not looking exactly what article "How to use XPO with a Web Service" describes. Let me explain. I am not looking to use a web service as a gate that will enable me to directly connect a CF client using XPO. I want to call a regular web method from a CF client that returns a simple type. But inside that web method I want to connect to a local database using XPO. I have managed to do this, but it seems the way I am creating the DataLayer inside the web method causes problems after a while with pool connections. Now I know this might be an entirely "How to connect to the database inside a web service method" subject, but I would appreciate it if anyone with web services experience sheds some light.
My Web Service solution doesn't have a Global.asax file. The code for my simple web method is this:
[WebMethod]
public string GetDescription(int oid)
{
string database = Settings.Default.Database;
XpoDefault.DataLayer = XpoDefault.GetDataLayer(MSSqlConnectionProvider.GetConnectionString(database, "Scrapyard"),
AutoCreateOption.SchemaAlreadyExists);
using (Session session = new Session())
{
Car car = session.GetObjectByKey<Car>(oid);
if (car != null)
{
return car.Description;
}
return string.Empty;
}
}
This code means that each time the web method is called, a new datalayer is created as well as a connection? The problem is that after several calls, I get an exception that no more connections can be created because the pool is full. What should I do? I have tried adding a Global.asax file and create the DataLayer in the Application_Start event, but it stopped working completely and my web methods tried to create the default connection. Where should I create the connection and in what way to comply with web services logic?
Thank you
Petros