现在有一人项目,在WebService中要调用Delphi中的Dll, 其中Delphi的Dll中有一个回调函数,在我的WebService中无法直接调用这个回调函数获得返回的结果,只有通过一个延时或其它什么处理机制,在这个回调函数中赋值给我定义的一个Session变量或静态成员变量,然后我再在WebService函数中对这个Session变量或静态成员变量进行判断. 如果条件满足,则返回正确的结果,反之. 我实在是找不出如何实现这种方式的方法. 求高人们指点.
调试欢乐多
private extern static int Socket(SocketBack srb);
delegate int SocketBack(int iMsgType,string sRecive);
private int SocketBack_callback(int iMsgType,string sRecive) //此为回调函数
{
if (iMsgType == 0) //证明成功
{
}
return 0;
}
public MyWebService()
{ //如果使用设计的组件,请取消注释以下行
SocketBack f = new SocketBack(SocketBack_callback);
Socket(f);
}
//以下是WebMethod的代码
[WebMethod]
public Collection<UserInfo> GetCard(ProductInfo productinfo, string statusCollectionString) // {
//在此处我需要确切地获取SocketBack_callback中的状态,然后返回一个Collection<UserInfo>对象给客户端}
Session["iMsgType"] = test.callback();while(time<timeout)
{
HashGetValue();
time++
}bool HashGetValue()
{
if(Session["iMsgType"]==null)
{
System.Threading.Thread.Sleep(50);
return false;
}return true;
}
-------------------------
楼主,Delphi的DLL能调用.Net中的Session和静态成员变量么?我对这个有疑问。
如果能调用,就有办法,通知.Net程序;
如果不能调用,可以用.Net监控中间变量,每隔多少毫秒去检查是否已经赋值。
第一个办法是主动通知的思路,第二个办法大体上是轮询的办法了。
private extern static int Socket(SocketBack srb);
delegate int SocketBack(int iMsgType,string sRecive); private Thread mythread; //定义一个线程对象private int SocketBack_callback(int iMsgType,string sRecive) //此为回调函数
{
if (iMsgType == 0) //证明成功
{
mythread.Resume(); //继续执行线程
}
return 0;
}
public MyWebService()
{ //如果使用设计的组件,请取消注释以下行
SocketBack f = new SocketBack(SocketBack_callback);
Socket(f);
}
//以下是WebMethod的代码
[WebMethod]
public Collection<UserInfo> GetCard(ProductInfo productinfo, string statusCollectionString) // { //在此处我需要确切地获取SocketBack_callback中的状态,然后返回一个Collection<UserInfo>对象给客户端
mythread=Thread.CurrentThread;
MyWebService();
mythread.Suspend(); //暂停线程
}