Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP'在请求之间保存会话数据;SOAPS客户端_Php_Web Services_Session - Fatal编程技术网

使用PHP'在请求之间保存会话数据;SOAPS客户端

使用PHP'在请求之间保存会话数据;SOAPS客户端,php,web-services,session,Php,Web Services,Session,我开发了一个ASP.NET Web服务,可以对数据库执行查询。现在,我正在开发一个PHP网站,它使用Web服务来访问任何需要访问数据库的内容。我编写了以下函数,用于创建新的SoapClient以使用Web服务: function get_soap_client() { if (!file_exists('wsdl_path.txt') return NULL; if (!$file = fopen('wsdl_path.txt', 'r')) r

我开发了一个ASP.NET Web服务,可以对数据库执行查询。现在,我正在开发一个PHP网站,它使用Web服务来访问任何需要访问数据库的内容。我编写了以下函数,用于创建新的SoapClient以使用Web服务:

function get_soap_client()
{
    if (!file_exists('wsdl_path.txt')
        return NULL;

    if (!$file = fopen('wsdl_path.txt', 'r'))
        return NULL;

    $path = fgets($file);
    fclose($file);

    return new SoapClient($path);
}
我已经测试了这个函数,将其作为将客户机连接到无状态Web服务的方法,它确实可以工作。例如,这是我的网站的登录功能(其控制流不受状态影响):

依次调用以下WebMethod:

[WebMethod(EnableSession = true)]
public bool TryLogin(string user, string pass)
{
    SqlParameter[] pars = new SqlParameter[2];
    pars[0] = new SqlParameter("@User", SqlDbType.VarChar, 20);
    pars[0].Value = user;
    pars[1] = new SqlParameter("@Pass", SqlDbType.VarChar, 20);
    pars[1].Value = pass;

    // The Stored Procedure returns a row if the user and password are OK.
    // Otherwise, it returns an empty recordset.
    DataTable dt = Utilities.RetrieveFromStoredProcedure('[dbo].[sp_TryLogin]', pars);
    if (dt.Rows.Count == 0) // Wrong user and/or password
    {
        Context.Session.Abandon();
        return false;
    }
    else
        return true;
}
但是,我不知道Web服务的
Context.Session
数据是否在
SoapClient
对象通过
get\u soap\u client()。因此,我有以下问题:

  • Web服务的
    Context.Session
    数据是否在
    SoapClient
    对象发出的连续请求之间被
    get\u soap\u client()检索

  • Web服务的
    Context.Session
    数据是否在从不同
    SoapClient
    对象发出的连续请求之间保留,并根据需要动态检索

  • 如果上一个问题的答案是“否”,那么有没有办法将
    SoapClient
    的会话数据序列化为PHP状态变量


  • 啊,你的意思是它正在发送会话ID。我想你需要手动调用_setCookie,将会话ID为的cookie设置到你的web服务


    啊,你的意思是它正在发送会话ID。我想你需要手动调用u setCookie,将带有会话ID的cookie设置到你的web服务


    所说的“状态信息”是指当前的$\u会话数据吗?不是。我实际上指的是Web服务的
    上下文。会话
    数据。我希望在PHP的
    $\u会话
    数组中保留尽可能少的数据。所说的“状态信息”是指当前的$\u会话数据吗?不是。我实际上指的是Web服务的
    上下文.SESSION
    数据。我希望在PHP的
    $\u会话
    数组中保留尽可能少的数据。
    [WebMethod(EnableSession = true)]
    public bool TryLogin(string user, string pass)
    {
        SqlParameter[] pars = new SqlParameter[2];
        pars[0] = new SqlParameter("@User", SqlDbType.VarChar, 20);
        pars[0].Value = user;
        pars[1] = new SqlParameter("@Pass", SqlDbType.VarChar, 20);
        pars[1].Value = pass;
    
        // The Stored Procedure returns a row if the user and password are OK.
        // Otherwise, it returns an empty recordset.
        DataTable dt = Utilities.RetrieveFromStoredProcedure('[dbo].[sp_TryLogin]', pars);
        if (dt.Rows.Count == 0) // Wrong user and/or password
        {
            Context.Session.Abandon();
            return false;
        }
        else
            return true;
    }