*本人第一次用com是参照这个代码学习的,由于非常赞同楼主的观点,所以多说了几句。
*本没没用过asp.net,不过给你的例子应该够用了。
*ox=CREATEOBJECT("myTest.FoxService")
*xml= ox.comExecute('select * from custom') &&此处 已获得 xml (此xml的格式 由生成它的CURSORTOXML()参数决定)
**********************************************************************
*Creating a Simple Visual FoxPro COM Server
*You create a PRG file, which will be called MYCLASS.PRG, with the following code:
*This entirely self-contained program will build a COM server
* called "myserver.myclass"
* It will unregister a prior instance, if any
IF PROGRAM() != "MYCLASS"
?"this file MUST BE NAMED 'myclass.prg'"
return
ENDIF
IF FILE("myclass.dll")
DECLARE integer DllUnregisterServer IN myclass.dll
DllUnregisterServer()
CLEAR DLLS
ENDIF
BUILD PROJECT myserver FROM myclass
BUILD DLL myserver from myserver recomp
*now test this COM server:
ox = CreateObject("myserver.myclass") && create the server object
ox.mydocmd("USE home(1)+'samples\data\customer'") && use a table
?ox.myeval("RECCOUNT()") && get the record count
DEFINE CLASS myclass AS session OLEPUBLIC
PROCEDURE MyDoCmd(cCmd as String) as Variant ;
helpstring "Execute a VFP cmd"
&cCmd && just execute parm as if it were a fox command
FUNCTION MyEval(cExpr as String) ;
helpstring "Evaluate a VFP expression"
RETURN &cExpr && evaluate parm as if it were a fox expr
FUNCTION Error(nError, cMethod, nLine)
COMreturnerror(cMethod+' err#='+str(nError,5)+;
' line='+str(nline,6)+' '+message(),_VFP.ServerName)
&& this line is never executed
ENDDEFINE
FUNCTION comExecute(cmdStr AS STRING ) &&,retType as String)
LOCAL earr[1]
LOCAL cXML
IF SQLEXEC(THIS.lnConnHandle, m.cmdStr,[rusltCursot])>0
CURSORTOXML("rusltCursot","cXML",3,32,0,"1") && CURSORTOXML() 有很多的参数,根据你的需要选用
USE IN rusltCursot
RETURN cXML
ELSE
AERROR(earr)
CREATE CURSOR errTB (err_no i,err_mess c(200))
INSERT INTO errTB (err_no,err_mess) VALUES (earr[1],earr[2])
CURSORTOXML("errTB","cXML",3,32,0,"1")
USE IN errTB
RETURN cXML
ENDIF
ENDFUNC
ENDDEFINE
#define CL CHR(13)+CHR(10)
DEFINE CLASS FoxBaseClass AS SESSION
sysvarDir=''
* connstring=[DRIVER=SQL Server;SERVER=server;uid=userId;pwd=password;Trusted_Connection=Yes;database=databaseName]
connstring=''
DATASESSION=2
lnConnHandle = 0
PROCEDURE INIT()
SET DATE ANSI
SET CENTURY on
SET HOURS TO 24
SET SAFETY OFF
LOCAL cText AS STRING, tmpStr as string
tmpStr = SYS(16)
this.sysvarDir=SUBSTR(tmpStr,AT('\',tmpStr)-2,RAT('\',tmpStr)-AT('\',tmpStr)+2)
SET PATH TO (this.sysvarDir) && 重要
PROCEDURE DESTROY
SQLDISCONNECT(this.lnConnHandle)
LOCAL cText AS STRING
cText="关闭时间"+TRANSFORM(DATETIME())+CL+CL
STRTOFILE(cText,this.sysvarDir+'\FoxService.txt',.T.)
ENDPROC
PROCEDURE ERROR(nError AS INTEGER,cMethod AS STRING, nLine AS INTEGER)
LOCAL cText AS STRING
cText=;
'出错时间:'+TRANSFORM(DATETIME())+CL+;
'错误代码:'+STR(nError,4)+CL+;
'错误提示:'+MESSAGE()+CL+;
'错误方法:'+cMethod+CL+;
'错误行号:'+TRANSFORM(nLine)+CL+CL
STRTOFILE(cText,this.sysvarDir+'\FoxService.txt',.T.)
COMRETURNERROR("Fox Web Service",cText)
ENDPROC
1.本人认为用COM组件是很有好处的,业务逻辑写在COM组件中,客户端只负责调用组件的相应功能对象及界面布局,这更符合OOP思想.
2.虽然,ASP.net+SQL server 可以B/S, 但此方式对服务器资源消耗严重,也非常依赖后台SQL server存储过程.
而ASP.net+VFP com+SQL Server 三层架构可以充分发挥VFP在数据处理方面的优势(cursor)以及资源整合(分布式),以提高系统的整体性能.(老外这方面做得比较好,他们更强调的是各语言之间的整合,发挥各自所长.)