I have developed a开发者_开发技巧n 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:
- Is the Web Service's - Context.Sessiondata preserved between consecutive requests made from a- SoapClientobject retrieved by- get_soap_client()?
- Is the Web Service's - Context.Sessiondata preserved between consecutive requests made from different- SoapClientobjects retrieved on the fly as I need them?
- 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?
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
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论