请问如何在客户端调用应用服务器接口?大侠请进,help
在应用服务器上定义了一个接口,但怎么在客户端调用应用服务器地接口呢?在帮助上是这样说的:“当扩展应用程序服务器接口时,需要一种使用由连接组件创建的连接来调用所有的扩展的方法,这可以使用连接组件的AppServer属性来完成。AppServer是表示应用程序服务器接口的变量。要调用这个接口,必须从该变量中得到一个分派的接口,这个分派的接口与在创建远程数据模块时创建的接口具有相同的名字,但在后面加上字符串‘Disp’”(这个分派的接口在通过类库编辑器产生的_TLB.h文件中声明)
下面是客户端提交时的代码:
OleVariant CustVar;
ClientDataSet1->CheckBrowseMode();
if(ClientDataSet1->ChangeCount>0)
CustVar=ClientDataSet1->Delta;
else
CustVar.ChangeType(VT_NULL);
try
{
IFinalKingDisp srvr;//远程数据模块FinalKing
srvr.Bind(LPDISPATCH(SocketConnection1->AppServer));
srvr.ApplyUpdates(reinterpret_cast<VARIANTOBJ*>(&CustVar));
ShowMessage("已经正确地录入数据库中!");
}
catch(Exception & exception)
{
Application->ShowException( & exception) ;
}
编译时报错:Undefined ymbol 'IFinalKingDisp'
‘使用连接组件的AppServer属性来完成’这话怎么理解?从出错信息看,好像AppServer没起作用,客户端根本找不到应用程序服务器上的相关定义,可是
不使用扩展接口时,程序运行正常。
下面是E文help:
Applications do not need to call the IAppServer interface directly because the appropriate calls are made automatically when you use the properties and methods of the client dataset. However, while it is not necessary to work directly with the IAppServer interface, if you are not using SOAP you may have added your own extensions to the application server抯 interface. When you extend the application server抯 interface, you need a way to call those extensions using the connection created by your connection component. You can do this using the AppServer property of the connection component. AppServer is a Variant that represents the application server抯 interface. To call this interface, you must obtain a dispatch interface from this Variant. The dispatch interface has the same name as the interface that was created when youcreated the remote data module, but with the string 揇isp?appended. Thus, if your remote data module is called MyAppServer, you can use AppServer to call its interface as follows:
IDispatch* disp = (IDispatch*)(MyConnection->AppServer)
IMyAppServerDisp TempInterface( (IMyAppServer*)disp);
TempInterface.SpecialMethod(x,y);
Note: The dispatch interface is declared in the _TLB.h file generated by the Type Library editor.
If you are using SOAP, you can抰 use the AppServer property. Instead, you must use a remote interfaced object (THTTPRio) and make early-bound calls. As with all early-bound calls, the client application must know the application server抯 interface declaration at compile time. You can add this to your client application by referencing a WSDL document that describes the interface you want to call. Note that for SOAP servers, this interface is entirely separate from the SOAP data module抯 interface. For information on importing a WSDL document that describes the interface, see Importing WSDL documents.
Note: The unit that declares the server interface must also register it with the invocation registry. For details on how to register invokable interfaces, see Understanding invokable interfaces.
Once you have imported a WSDL document to generate a unit declaring and registering the interface, create an instance of THTTPRio for the desired interface:
THTTPRio *X = new THTTPRio(NULL);
Next, assign the URL that your connection component uses to the remote interfaced object, appending the name of the interface you want to call:
X->URL = SoapConnection1.URL + "IMyInterface";
Now, you can use the QueryInterface method to obtain an interface to call the server抯 methods:
InterfaceVariable = X->QueryInterface(IMyInterfaceIntf);
if (InterfaceVariable)
{
InterfaceVariable->SpecialMethod(a,b);
}
Note that the call to QueryInterface takes as an argument the DelphiInterface wrapper for the invokable interface rather than the invokable interface itself.