title: Sending a cookie through a web service call in .NET
body: <p>I am having issue setting a cookie to a web-service call in .NET. Before using any of the calls of the wsdl provided, i must provide a cookie that is obtained upon logging in to the clients website. I have a method to login and retrieve the cookie, where I then pass it to my makeSearch method (shown below). As you can see, i'm setting the cookie in the cookieContainer for the wsdl Object; however, when i check the request made by my AdvancedSearch method, i'm noticing in fiddler that no cookie is being sent. The client provided the solution in Java, but am having issue transferring that to .NET. </p>
  
  <p>The following is the solution in Java code: (port is the wsdl object passed in)</p>
  
  <pre><code>private static void setupClient(Object port, final String cookie) throws Exception {
      Client client = ClientProxy.getClient(port); 
      HTTPConduit http = (HTTPConduit) client.getConduit();
      HTTPClientPolicy policy = http.getClient();
      if (policy == null) {
          policy = new HTTPClientPolicy();
          http.setClient(policy);
      }
      policy.setCookie(cookie);
      policy.setAutoRedirect(true);
  }
  </code></pre>
  
  <p>My code is the following:</p>
  
  <pre><code>public AdvancedSearchResult makeSearch(String cookie) {
      System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
      AdvancedSearchResult searchResults = new AdvancedSearchResult();
      Cookie cook= new Cookie("NAME", HttpUtility.UrlEncode(cookie));
      searches.CookieContainer = new CookieContainer();
      searches.CookieContainer.Add(newUri(www.test.com),cook);
      searchResults = searches.AdvancedSearch("search params");
      return searchResults;
  }
  </code></pre>
  
  <p>Can anyone list any ideas or solutions?</p>