Last post Aug 11, 2014 06:30 PM by AidyF
Aug 11, 2014 03:55 PM|Rob Tanner|LINK
I've written a small C# program containing only 5 webmethods. It's primary purpose is to set or clear the HiddenFromGal flag in the Exchange server. I am using c# to actually invoke pieces PowerShell which does the actual work (I wonder if I can actually
do the whole thing in C#?)
I have one method to actually log into Exchange with Admin credentials and open a PowerShell runspace constructed using the using the WSManConnectionInfo value returned by the login function. Once I've created the runspace, I add it to the session: "Session["runspace"]
= runspace;" I am presuming that the command: "Runspace runspace = (Runspace)Session["runspace"];" in a different webmethod will return the same runspace I created in the webmethod that did the authentication, but when I try to invoke the method set sets
that value of the HiddenFromGal Exchange switch, that I will get the original runspace back?
The problem is that when I invoke the method to set the value, I get back the error: "Object reference not set to an instance of an object" Is the descrition above, or do I need to add the code itself. can you tell me what I'm doing wrong?
Aug 11, 2014 04:00 PM|AidyF|LINK
You seem to be getting a bit confused between session and authentication, they are not the same thing. If you want to pass an asp.net Session to a web service and have that web service call have access to the same session the code would have access to if
it was on an asp.net page in the same site then you have to mark the method such that session is enabled
As I said though, this is nothing to do with authentication.
Aug 11, 2014 04:21 PM|Rob Tanner|LINK
Actually I do know the difference, I'm just doing a poor job of describing the problem an my concern.
My methods all are tagged as [WebMethod(EnableSession = true)] and I would have though that would be sufficient but apparently something is needed in addition.
Aug 11, 2014 04:28 PM|AidyF|LINK
What is calling the web service though and where is it hosted? Is your code-behind calling the service?
Aug 11, 2014 04:59 PM|Rob Tanner|LINK
I use Java to pull student information nightly from our enterprise database and then I use that data to update our LDAP server as well as Exchange. So it's a Java program running on a Linux server calling the web service running on a Windows Server 2008
R2 Standard. And that java code is calling the service (if I understand your question). The first call is to a login method that logs into the Exchange server, adding the runspace variable to the session (Session["runspace"] = runspace;). The next call
is to the method that sets the HiddenFromTheGal flag using the runspace created in the previous method (Runspace runspace = (Runspace)Session["runspace"];). Unless there is an issue, those two method constitute the entire exchange between the java program
and the web service.
Aug 11, 2014 05:08 PM|AidyF|LINK
In that case the second call should be able to access the object stored in the session by the first, assuming the java call obeys http protocol and is re-sending the session id in the cookie sent with the second request.
Aug 11, 2014 06:11 PM|Rob Tanner|LINK
I have perhaps made an errant assumption. When the webmethods include EnableCookie=true in the header, my asumption is tht the WSDL document would reflect that and the resultant Java code would automatically maintain state between calls. I'm now assuming
that that's not true. You don't happen to know what I need to do on the Java to handle cookies do you.
Aug 11, 2014 06:30 PM|AidyF|LINK
indeed do this. It might be worth using something like fiddler to examine the communications to make sure the session cookie is being sent.