C# web method can't see cookies?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dad107@underflap.com

    C# web method can't see cookies?

    Hi everyone.

    My web application wants to take advantage of an encrypted
    authentication cookie that's provided by another application on the
    same server. The cookie is visible on the client side, but when I
    invoke a method on my web service no cookies are visible.

    For example, here is the relevant code in an example Javascript
    client:

    var o = new ActiveXObject(" MSXML2.XMLHTTP" );
    o.open("POST"," http://localhost/Example/Service1.asmx", false);
    o.setRequestHea der("Content-Type", "text/xml");
    o.setRequestHea der("SOAPAction ", "http://tempuri.org/HelloWorld");
    o.setRequestHea der("Cookie", "foo=bar; baz=quux");
    o.setRequestHea der("Cookie", "foo=bar; baz=quux");
    o.setRequestHea der("FOO", "BAR");
    var msg = "<soap:Enve lope xmlns:xsi='http ://www.w3.org/2001/XMLSchema-
    instance' xmlns:xsd='http ://www.w3.org/2001/XMLSchema'
    xmlns:soap='htt p://schemas.xmlsoap .org/soap/
    envelope/'><soap:Body><H elloWorld xmlns='http://tempuri.org'></
    HelloWorld></soap:Body></soap:Envelope>" ;
    o.send(msg);
    alert (o.responseXML. xml);

    And here is the relevant code in the C# method it calls:

    [WebMethod]
    public string HelloWorld()
    {
    return "Hello World! There are " +
    Context.Request .Cookies.Count. ToString() + " cookies! Your FOO header
    is " + Context.Request .Headers["FOO"] + " but your Cookies header is "
    + Context.Request .Headers["COOKIES"];
    }

    What I get back in the alert message indicates zero cookies and a
    completely empty Cookies header, but the FOO header comes through with
    the "BAR" content. So it seems that something is stripping the Cookies
    header from my request.

    My multipart question: Is there some feature of the .NET Framework
    that prevents cookies from coming through? Or is it the XMLHTTP client-
    side object? Or am I missing the point entirely?

    Please post solutions, commiseration, war stories, and pointers to
    documentation. Thanks in advance.


    Mark W. Schumann
    Some Guy on Bridge Avenue
  • Spam Catcher

    #2
    Re: C# web method can't see cookies?

    dad107@underfla p.com wrote in news:2001dd32-a9af-472f-a1c2-
    345389d87e3a@a2 3g2000hsc.googl egroups.com:
    My web application wants to take advantage of an encrypted
    authentication cookie that's provided by another application on the
    same server. The cookie is visible on the client side, but when I
    invoke a method on my web service no cookies are visible.
    >
    Have you looked at building RESTful Web services instead? Seems like
    you're trying to connect to the web service using a lgnague that does
    not natively support web services... in which case RESTful style
    webservices would be better.

    But in anycase, I think for cookies to work in webservices, you need to
    enable session statefulness. Not good if you're planning for
    scalability.

    Instead - use SOAP headers to transfer this sort of information (instead
    of cookies).

    --
    spamhoneypot@ro gers.com (Do not e-mail)

    Comment

    • dad107@underflap.com

      #3
      Re: C# web method can't see cookies?

      On Apr 19, 8:20 pm, Spam Catcher <spamhoney...@r ogers.comwrote:
      dad...@underfla p.com wrote in news:2001dd32-a9af-472f-a1c2-
      Have you looked at building RESTful Web services instead? Seems like
      you're trying to connect to the web service using a lgnague that does
      not natively support web services... in which case RESTful style
      webservices would be better.
      The problem is that I'm being given an authentication cookie. That's
      what
      the environment supports.

      But in anycase, I think for cookies to work in webservices, you need to
      enable session statefulness. Not good if you're planning for
      scalability.
      But I don't need my service to manage a session--it just needs to see
      a
      cookie that I know is in the request headers.

      Instead - use SOAP headers to transfer this sort of information (instead
      of cookies).
      That's the crazy thing. Other headers (such as the fake "Foo" header
      in
      my posted example) come through fine. It's just "Cookie" that gets
      eaten
      along the way. If I call it "Foo" or "CookieX" or whatever, that
      works.

      My point is that it looks as though something in the .NET Framework
      removes "Cookie" headers, and only "Cookie" headers, from incoming
      requests to a Web Service. I'm trying to figure out why this is
      happening.

      Thanks.

      Comment

      Working...