在VS2003非托管代码中调用WebService的方法比较简单,通过在项目中添加Web引用,输入WebService的网址,向导就会自动生成一个WebService类,该类包含所引用WebService的接口,并且从CSoapSocketClientT<>继承。下面是在我的项目内生成的类:
template
<
typename TClient
=
CSoapSocketClientT
<>
>
class CGPSServicesT :
public TClient,
public CSoapRootHandler
... {
//...............
} ;
class CGPSServicesT :
public TClient,
public CSoapRootHandler
... {
//...............
} ;
基类CSoapSocketClientT<> 包含了一些soap操作的方法,如设置WebService地址,设置超时时间的方法等。下面这个函数可以设置WebService调用的超时时间:
CSoapSocketClientT::SetTimeout
Call this method to set the timeout for connecting, sending, and receiving.
void SetTimeout( DWORD dwTimeout );
Parameters
-
dwTimeout
-
The timeout in milliseconds.