通过IOM(“Integrated Object Model” )服务器,没有必要使SAS安装在本地系统,通过Management Console和EntERPrise Guide工具可以完美的连接到远端的SAS主机上 需要注意的是IOM服务器并不是代表一个具体的服务器,在SAS IT中,有下面4中类型的IOM服务器 Metadata 服务器 – 存储和管理元数据库,包含哪些SAS服务器、库、和存储过程可用 工作空间服务器 – 维护SAS程序环境; 存储过程服务器 – 运行 “canned” SAS程序 OLAP服务器 – 驱动CUBE数据到SAS Enterprise Guide或者其它OLAP客户端
工作空间服务器有下面3中类型 Java客户端连接到IOM服务器使用JAVA-IOM桥 WIN客户端连接到IOM服务器使用COM/DCOM技术, WIN客户端可以连接到运行在UNXI上的IOM服务器,通过使用COM-IOM桥
对于WIN应用,IOM支持ADO通过OLEDB访问SAS数据 对应JAVA,JDBC2.0访问是被支持的
工作空间服务器包含下面接口 工作空间Workspace – SAS会话 语言服务Language Service –提交SAS DATA步和过程步,接收LOG和LIST输出,运行存储过程 数据服务Data Service – 管理SAS库 文件服务File Service – 管理文件标识 实用工具Utilities – formats, options, result packages, host system information
存储过程服务器 用于存放存储过程,其结果可以被Web(Information Delivery Portal,BI WEB服务)、Office(OFFICE插件)或者Enterprise Guide 3.0使用
假设在SAS服务器上存在下面文件 C:\temp>type IOMTest.sas %let cond=; *ProcessBody; proc print data=sashelp.class; title "Test Stored Process"; where &cond; run; VB例子: 必须引用下面库 SAS: Integrated Object Model (SAS System 9.1) SASWorkspaceManager 1.1 Type Library Connecting with DCOM in Visual Basic Option Explicit ' define a global workspace Dim obSAS As SAS.Workspace Dim obWSMgr As New SASWorkspaceManager.WorkspaceManager Private Sub Form_Load() Dim XMLInfo As String ' create Workspace server Dim obServer As New SASWorkspaceManager.ServerDef obServer.MachineDNSName = "hunding" Set obSAS = obWSMgr.Workspaces.CreateWorkspaceByServer _ ("", VisibilityProcess, obServer, "", "", xmlInfo) End Sub Private Sub cmdTest1_Click() ' use LanguageService to submit code obSAS.LanguageService.Submit _ "%include 'c:\temp\IOMTest.sas'; run;" MsgBox obSAS.LanguageService.FlushLog(100000) MsgBox obSAS.LanguageService.FlushList(100000) End Sub Private Sub cmdTest2_Click() 'run the stored SAS program Dim obStoredProcessService As SAS.StoredProcessService Set obStoredProcessService = _ obSAS.LanguageService.StoredProcessService obStoredProcessService.Repository = "file:c:\temp" obStoredProcessService.Execute "IOMtest", "cond='sex eq ""M""'" MsgBox obSAS.LanguageService.FlushLog(100000) MsgBox obSAS.LanguageService.FlushList(1000000) End Sub Private Sub Form_Unload(Cancel As Integer) obWSMgr.Workspaces.RemoveWorkspaceByUUID _ obSAS.UniqueIdentifier obSAS.Close End Sub VC例子 #include <iostream> #include <stdexcept> #include <Windows.h> using namespace std; #import "C:\Program Files\SAS Institute\Shared Files\Integration Technologies\sas.tlb" #import "C:\Program Files\SAS Institute\Shared Files\Integration Technologies\SASWMan.dll" int main() { SASWorkspaceManager::IWorkspaceManager2Ptr pIWorkspaceManager; SASWorkspaceManager::IServerDef2Ptr pIServerDef = NULL; SAS::IWorkspacePtr pIWorkspace; BSTR xmlInfo; HRESULT hr = CoInitialize(NULL); hr = pIWorkspaceManager.CreateInstance( "SASWorkspaceManager.WorkspaceManager.1"); pIServerDef.CreateInstance("SASWorkspaceManager.ServerDef"); pIServerDef->PutMachineDNSName("hygelac"); pIServerDef->Protocol = SASWorkspaceManager::ProtocolBridge; pIServerDef->put_Port(8591); pIWorkspace = pIWorkspaceManager->Workspaces->CreateWorkspaceByServer( _bstr_t(""), //workspace name
SASWorkspaceManager::VisibilityProcess, pIServerDef, // server
_bstr_t("sassrv"), // login
_bstr_t("sasuser"), // password
&xmlInfo // connection log
); pIWorkspace->LanguageService->Submit( "%include '/home/sasadm/IOMTest.sas'; run;"); MessageBox(NULL, pIWorkspace->LanguageService->FlushLog(10000), "SAS Log", MB_OK ); MessageBox(NULL, pIWorkspace->LanguageService->FlushList(10000), "List Output", MB_OK ); pIWorkspace->Close(); return(0); } JAVA客户端
编译时使用下面命令 javac -classpath ".:C:/Program Files/SAS/SAS 9.1/core/sasmisc/sas.svc.connection.jar" IOMTest.java sas.svc.connection.jar文件位于 C:\Program Files\SAS\SAS 9.1\core\sasmisc 下
import com.sas.services.connection.Server; import com.sas.services.connection.BridgeServer; import com.sas.services.connection.ConnectionFactoryConfiguration; import com.sas.services.connection.ConnectionFactoryManager; import com.sas.services.connection.ConnectionFactoryInterface; import com.sas.services.connection.ConnectionFactoryException; import com.sas.services.connection.ConnectionInterface; import com.sas.services.connection.ManualConnectionFactoryConfiguration; import com.sas.iom.SAS.IWorkspace; import com.sas.iom.SAS.IWorkspaceHelper; import com.sas.iom.SAS.ILanguageService; import com.sas.iom.SAS.ILanguageServicePackage.CarriageControlSeqHolder; import com.sas.iom.SAS.ILanguageServicePackage.LineTypeSeqHolder; import com.sas.iom.SASIOMDefs.GenericError; import com.sas.iom.SASIOMDefs.StringSeqHolder; public class IOMTest { public IOMTest() throws ConnectionFactoryException, GenericError { String classID = Server.CLSID_SAS; String host = "localhost"; int port = 8591; String userName = "sasadm"; String password = "sas123?"; Server server = new BridgeServer(classID, host, port); ConnectionFactoryConfiguration cxfConfig = new ManualConnectionFactoryConfiguration( server); ConnectionFactoryManager cxfManager = new ConnectionFactoryManager(); ConnectionFactoryInterface cxf = cxfManager.getFactory(cxfConfig); ConnectionInterface cx = cxf.getConnection(userName, password); IWorkspace iWorkspace = IWorkspaceHelper.narrow(cx.getObject()); ILanguageService sasLanguage = iWorkspace.LanguageService(); sasLanguage.Submit("%include 'd:\\auto.sas'; run;"); StringSeqHolder logHldr = new StringSeqHolder(); sasLanguage.FlushLogLines(Integer.MAX_VALUE, new CarriageControlSeqHolder(), new LineTypeSeqHolder(), logHldr); String[] logLines = logHldr.value; StringSeqHolder listHldr = new StringSeqHolder(); sasLanguage.FlushListLines(Integer.MAX_VALUE, new CarriageControlSeqHolder(), new LineTypeSeqHolder(), listHldr); String[] listLines = listHldr.value; iWorkspace.Close(); cx.close(); } public static void main(String args[]) { try { new IOMTest(); System.exit(0); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } } }
|