6 Replies - 6310 Views - Last Post: 20 August 2010 - 07:19 AM Rate Topic: -----

#1 danny_kay1710  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 28
  • View blog
  • Posts: 358
  • Joined: 27-April 08

Consume a ASP.NET webservice in PHP

Posted 20 August 2010 - 04:10 AM

I am trying to use the functionality of an ASP.NET web application which uses some native .NET libraries in PHP however I am curious to know how PHP handles sessions.

$client = new SoapClient ($wsdl);
$client->CheckUser(array("username"=>"admin", "password"=>"pass");
echo "Success!";



Now in .NET I would use:

CookieContainer c = new CookieContainer();

Authentication auth = new Authentication() // The web service object
auth.CookieContainer = c;

auth.CheckUser("admin", "pass");




The CookieContainer takes care of persisting the session - how would I achieve this same thing in PHP?

Any help would be greatly appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Consume a ASP.NET webservice in PHP

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3492
  • View blog
  • Posts: 10,072
  • Joined: 08-June 10

Re: Consume a ASP.NET webservice in PHP

Posted 20 August 2010 - 04:16 AM

check out the manual entries about sessions

to make it short. PHP uses a SuperGlobal ($_SESSION) to save data, which is available after starting the session (calling session_start(), please refer to the manual for further details)
Was This Post Helpful? 1
  • +
  • -

#3 danny_kay1710  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 28
  • View blog
  • Posts: 358
  • Joined: 27-April 08

Re: Consume a ASP.NET webservice in PHP

Posted 20 August 2010 - 05:56 AM

I know how to use the $_SESSION[''] variable however how not it in this context.

I am using this function to login to the web service. In .NET without the CookieContainer I could log in and then on the next line call another function but I would no longer be logged in because the session would have been discarded.

How do I store the session information from a SoapClient and ensure that it is used in future calls?

Does this make sense?

[EDIT]
Just to clarify I am wanting to keep and store the session info about the ASP.NET web service within the PHP script (similar to what you have to do in .NET) - this isn't about storing session data between PHP and the client.

This post has been edited by danny_kay1710: 20 August 2010 - 05:59 AM

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,440
  • Joined: 23-August 08

Re: Consume a ASP.NET webservice in PHP

Posted 20 August 2010 - 06:01 AM

I can only tell you how we do it in our app. The session ID is saved in the cookie sent to the browser on login, and this is passed to each and every SOAP call that's made. However, that's communicating with a non-Windows/.NET system, so I don't know how viable it is.
Was This Post Helpful? 0
  • +
  • -

#5 danny_kay1710  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 28
  • View blog
  • Posts: 358
  • Joined: 27-April 08

Re: Consume a ASP.NET webservice in PHP

Posted 20 August 2010 - 06:20 AM

The bigger problem really is that I am not entirely sure how the CookieContainer works.

I could implement my own form of database based session handling between PHP and ASP.NET.

In theory if amended both the web service and PHP script to pass a Session ID which is stored in the database alongside anything else it needs to store which then in turn allowed all the info to be looked up I could achieve session like behaviour but that's not really what I want to do.
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,440
  • Joined: 23-August 08

Re: Consume a ASP.NET webservice in PHP

Posted 20 August 2010 - 06:35 AM

C#/ASP.NET hides the implementation details from you...that's one of the downsides obviously. The cookie container may be re-presenting the username/password on each request, which the server maps to a session. You could run client requests on Windows through Fiddler2 and see what's being passed I suppose.
Was This Post Helpful? 1
  • +
  • -

#7 danny_kay1710  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 28
  • View blog
  • Posts: 358
  • Joined: 27-April 08

Re: Consume a ASP.NET webservice in PHP

Posted 20 August 2010 - 07:19 AM

I didn't know about Fiddler2 thanks!!

I found that an instance System.Web.SessionState.SessionIDManager of exposed a GetSessionID function which in theory would work but I would expect this to be pre-initalised somewhere but I just don't know where along with a CreateSessionID which could be useful.

Also this is a custom SessionIDManager (http://msdn.microsoft.com/en-us/library/system.web.sessionstate.isessionidmanager.aspx) which you would configure your app to use via Web.Config but the question still remains as to where the instance of this object is in the framework.

Still not quite sure how I am going to attack this one, I am also wondering if it is possible now to use a .NET dll in php directly save me having to deal with an intermediary web service and make it more secure.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1