Last post Jun 22, 2011 07:02 PM by AJ123
Jul 20, 2010 02:29 PM|qijaz|LINK
I am trying to call a webservice that requires me to authenticate and then pass the session id returned from the authenticate method to subsequent web service calls. The session id has to be passed as HTTP request header. So I tried using the following code
to add the session id to a HTTP request header:
System.Collections.Specialized.NameValueCollection headers =
Type t = headers.GetType();
//get the property
System.Reflection.PropertyInfo p = t.GetProperty("IsReadOnly",System.Reflection.BindingFlags.Instance
| System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.NonPublic
//add a header
"SID=" + sessionId );
The header is supposed to be called "Cookie" and the SID contains the session id. The problem is the last line in the code above gives an exception saying "Operation is not supported on this platform". I am running this code on my dev machine with with Windows
XP Professional Service Pack 3 and IIS 5.1. I haven't been able to find any solution to this problem after days of searching. I also tried to deploy my web app on IIS directly but had the same error. Has anyone encountered this issue? I will appreciate any
help you can provide.
Jul 20, 2010 10:11 PM|ravikatha|LINK
Your code does not seem to implement the idea you stated. How is writing a cookie to HttpContext.Current.Request affect the calls made to an external webservice?
The HttpContext.Current.Request represents the rquest issued to your web page from the client's browser. It is basically read-only. Even if you set the rea-only flag to false using reflection, it is not going to be used anywhere and somewhere below the IIS
request processing layers, it detects that you have changed non changable data and throws exception.
If your purpose is to call a webservice method and store the returned authentication cookie for future calls, you can use CookieContainer class. Create a global instance of System.Net.CookieContainer clas and store it in your Application state or Session
Whenever you call the web service method, use the same cookie container. Thus when you authenticate in your first call, the cookie container will store the cookie. The next time onwards, whenever you call the webservice methods, the cookie will be sent to
the server automatically.
There is a detailed documentation about this at
Jul 21, 2010 03:54 PM|qijaz|LINK
Thanks for your reply Ravi! I tried the cookie container approach as well, it didn't work. I got this error:
"Session ID cookie value cannot be null or empty string - It is required that the high level Web service client program participate in the session initialized by the server."
Also the documentation for the webservice that I am calling says:
"The initial request sent to the WOKMWSAuthenticate service by your Web services client submits authentication credentials. If your authentication credentials are validated, a
session identifier, also called an authentication identifier, is returned in the service response. Otherwise, a SOAP fault is returned.
All subsequent requests to Web of Knowledge Web Services do not require (re)authentication as long as the session ID has not expired
and is included in each service request.
By default, your Web services client will not send the session identifier with subsequent service requests. You must configure, or modify, your Web services client to send the session identifier. The session ID must be sent in the transport header rather
than in the SOAP message. Once authenticated, all service requests are routed to the authenticating server. This routing is done using the session identifier located in the HTTP request header.
All subsequent requests must supply the session ID as an HTTP cookie header. This means that the HTTP post request must contain the following HTTP cookie header:
Header name: Cookie
Header value: [SID="the session identifier"]"
I have read a couple of posts where people modified the HTTP request header using an HTTP Handler. Next I am going to try that approach. If you have any ideas please let me know.
Jun 22, 2011 07:02 PM|AJ123|LINK
It is kind of very old thread of yours, but I hope you could help me out. I am also trying to create client for this same web service as you did of Thomsom Reuters Web of Knowledge. I am quite new to webservices and just read some tutorials before starting
this work. I am using vb.net for implementing the client. I was wondering if you ever able to set up client and could help me in starting this project. I am stuck on very first step of authentication and not able to pass the credentials properly. Could you
please send me some code that how you implemented it. I really appreciate your help.
Please see code below for how I am sending authorization credentials.
Dim authorizationservice As com.isiknowledge.search.WOKMWSAuthenticateService = New com.isiknowledge.search.WOKMWSAuthenticateService()
Dim netCred As System.Net.NetworkCredential = New System.Net.NetworkCredential("username", "password")
Dim uri As Uri = New Uri("http://auth.cxf.wokmws.thomsonreuters.com")
Dim credentials As Net.ICredentials = netCred.GetCredential(uri, "Basic")
authorizationservice.Credentials = credentials
authorizationservice.PreAuthenticate = True
session_identifier = authorizationservice.authenticate()