I have somne trouble using the XPO in a web service. I do not need XPO to be used outside of the web service, just want to use the XPO library within the web service code to perform some updates to an SQL database.
I have managed so far to change the default connection string that the SQL database is used instead of Access by putting the following code into my Global.asax Application_Start event:
Dim conStr As String = DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString("199.202.248.170,1437", "username", "password", "dbinstance")
DevExpress.Xpo.XpoDefault.ConnectionString = conStr
DevExpress.Xpo.Session.DefaultSession.AutoCreateOption = DevExpress.Xpo.DB.AutoCreateOption.None
DevExpress.Xpo.Session.DefaultSession.ConnectionString = conStr
I have also generated the classes for most tables in the SQL database, using the wizard for persistent Classes 7.2 which generated the following type of code into the App_Code directory, LibXPO Class:
See attachment
I am now trying to use the classes and get some data from the XPO whitin the web service code which calls a function library where I try to instantiate the following:
Dim sessionx As Session = New DevExpress.Xpo.Session()
Dim oConditions As New MPH.XPO.Conditions(sessionx)
…
Dim criterRef As CriteriaOperator = CriteriaOperator.Parse("ConditionCode ='" & CondID & "' ")
Dim cConds As XPCollection
cConds = New XPCollection(sessionx, GetType(MPH.XPO.Conditions))
cConds.Filter = criterRef
dim oCond as MPH.XPO.Conditions
For Each oCond In cCond
Return oCond.ConditionCode.Name
Next
I keep getting the following error:
An unhandled exception of type 'System.StackOverflowException' occurred in DevExpress.Xpo.v7.2.dll
What do I do wrong here? I need this to work and be put into a transaction block with roll back capability. I have looked for asp.net samples and web service samples but they seem to fit different scenarios where either an asp.net form is being used or the web service tries to return the xpo object itself which is more sophisticated than the simple use of xpo inside the web service code on the server that I am trying to use.
Thanks for any help or example.
-----------------
======== Changed On: '10/31/2007 12:57:38 AM', Changed By: 'Developer Express Support Team' ========
======== Changed On: '10/31/2007 3:23:45 AM', Changed By: 'Developer Express Support Team' ========
Hello Philippe,
Your code seems to be correct. We only advise that you explicitly initialize the XpoDefault.DataLayer property in Application_Start:
Visual BasicDevExpress.Xpo.XpoDefault.ConnectionString = conStr DevExpress.Xpo.XpoDefault.DataLayer = DevExpress.Xpo.XpoDefault.GetDataLayer(conStr, DevExpress.Xpo.DB.AutoCreateOption.None)
Could you please provide us with your test project and instructions on how to recreate your situation?
Thank you,
Nick
-----------------
======== Changed On: '11/13/2007 9:34:42 AM', Changed By: 'philippe menu' ========
Hi again,
Sorry to come back with same issue again but I have been looking all around and could not determine why this is not working.
1- have regenerated my persistent classes using the wizard in 7.2.5 from the existing SQL server 2000 database. I have attached the resulting MPHPersistentClasses.vb resulting file which by default has been put into the AppCode Folder of the asp.net application.
2-Have modified my global asax file to use threadsafe as follows
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
Dim conStr As String = DevExpress.Xpo.DB.MSSqlConnectionProvider.GetConnectionString("199.202.999.999,9999", "user", "pwd", "database")
DevExpress.Xpo.XpoDefault.DataLayer = DevExpress.Xpo.XpoDefault.GetDataLayer(conStr, DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists)
Dim dict As New DevExpress.Xpo.Metadata.ReflectionDictionary()
' Initialize the XPO dictionary.
Dim assmb As System.Reflection.Assembly = GetType(MPHxpo.Clients).Assembly
dict.GetDataStoreSchema(assmb)
Dim store As DevExpress.Xpo.DB.IDataStore = DevExpress.Xpo.XpoDefault.GetConnectionProvider(conStr, DevExpress.Xpo.DB.AutoCreateOption.SchemaAlreadyExists)
Dim layer = New DevExpress.Xpo.ThreadSafeDataLayer(dict, store)
Application.Add("XpoLayer", layer)
End Sub
I have then put a test web service which contains the following code:
Function testXPO(ByVal BusID As String, ByVal FirstName As String) As String
Dim returnstring As String = String.Empty
Dim ctx As HttpApplication = HttpContext.Current.ApplicationInstance
Dim Ly As DevExpress.Xpo.IDataLayer = ctx.Application("XpoLayer")
Dim _session As Session = New DevExpress.Xpo.Session(Ly)
Dim oCli As New MPHxpo.Clients(_session)
Dim oCliHist As New MPHxpo.ClientHistory(_session)
_session.BeginTransaction()
Try
oCli.FirstName = FirstName
oCli.CreateUser = "Pmenu"
oCli.LastName = "XPO"
oCli.Save()
oCliHist.ClientID = oCli
oCliHist.Comments = "Test de creation en commit avec XPO"
oCliHist.EventID = "WEBCLIENT"
oCliHist.DateCreated = getIntDate()
oCliHist.TimeCreated = getIntTime()
oCliHist.Save()
_session.CommitTransaction()
Catch ex As Exception
_session.RollbackTransaction()
End Try
Return oCli.ClientID
End Function
I have put a debug on both the fucntion and the global.asax code.
I get the Stack Overflow exception as soon as the code reaches the following line in global.asax
dict.GetDataStoreSchema(assmb)
I had tried it before with dict.GetDataStoreSchema(GetType(MPHxpo.Clients).Assembly) and got the same stack overflow. Then I splitted the GetType(MPHxpo.Clients).assembly into a separate assmb variable because I wanted to see if the application was getting the assembly at all. If I stop after I get assmb instanciated, I can see that the system can see the assembly.
I also tried to run the test with a single class and replace the dict.getDataStoreSchema(assmb) with dict.getDataStoreSchema(GetType(MPHxpo.Clients)) and then it initializes the global.asax OK and gets into the function, but I get a message in the function when trying to create the ClientHistory class then for which it cannot obviously find the dictionnary.
I have been looking all around in the c# and VB samples on asp.net but have found nothing to explain this behaviour.
How in hell can I make this supposedly 'make your life easier' Express Persistent Object work in my asp.net code.
Thanks for your help.