dongrong7267 2011-01-11 14:15
浏览 49
已采纳

使用PHP的SoapClient保留请求之间的会话数据

I have developed an ASP.NET Web Service that performs queries to a database. Now I am developing a PHP Web site that consumes the Web Service for anything that requires access to the database. I have written the following function which creates a new SoapClient to consume the Web Service:

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);
}

I have already tested this function as means to get a client to a stateless Web Service, and it does work. For example, this is my Web site's login function (whose control flow is not affected by state):

function try_login($user, $pass)
{
    $client = get_soap_client();

    // ASP.NET Web Services encapsulate all inputs in a single object.
    $param = new stdClass();
    $param->user = $user;
    $param->pass = $pass;

    // Execute the WebMethod TryLogin and return its result.
    // ASP.NET Web Services encapsulate all outputs in a single object.
    return $client->TryLogin($param)->TryLoginResult;
}

Which in turn calls the following 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;
}

However, I don't know whether the Web Service's Context.Session data is preserved between consecutive requests made from SoapClient objects retrieved by get_soap_client(). So I have the following questions:

  1. Is the Web Service's Context.Session data preserved between consecutive requests made from a SoapClient object retrieved by get_soap_client()?

  2. Is the Web Service's Context.Session data preserved between consecutive requests made from different SoapClient objects retrieved on the fly as I need them?

  3. If the answer to the previous question is "no", is there any way to serialize the SoapClient's session data into a PHP state variable?

  • 写回答

1条回答 默认 最新

  • douyazi1129 2011-01-11 14:46
    关注

    Ah, you mean is it sending the SESSION ID. I imagine you'll need to call __setCookie manually to set a cookie with the SESSION ID to your web service.

    http://php.net/manual/en/soapclient.setcookie.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记