CookieContainer Cann't work on WinCE

Hi, everyone, I am developing a program about Yahoo mail
web service.Yahoo provided a sample code in C# as below.
It can work on the desktop without any problems, but when
I ported the code to C# on WinCE, I found the CookieContainer
class is not present on the .NET Compact Framework. So I
try to use HttpWebRequset.Headers.Add() function to do the
same work. But I can not get the right result.

Can you help me? thanks first.


using System;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Web;
using System.Web.Services.Protocols;
using System.Xml;
using System.Xml.XPath;
using YMWS_Sample.com.yahooapis.mail;

namespace YMWS_Sample
// In order to run this sample you must do the following:
// 1) Import the WSDL. Go the the "Project" menu and select "Add Web Reference...". In the
// dialog box, type http://mail.yahooapis.com/ws/mail/v1.1/wsdl in the URL field. Press
// the "Go" button and the WSDL will be imported. When that has completed, press the
// "Add Reference" button.
// 2) Import the Yahoo.Authentication reference. The DLL is available from the .NET
// Developer Center on the Yahoo! Developer Network (http://developer.yahoo.com/dotnet/).
// 3) You will need to supply this code with the application ID and shared secret that were
// supplied during the Browser Based Authentication setup. In addition, you will need
// to obtain a valid user token. For more details, see the Yahoo! Developer Network
// section on Browser Based Authentication (http://developer.yahoo.com/auth/).
// This code was tested in Microsoft Visual C# .NET.
class YmwsSample {
static void Main(string[] args) {
// Enter your application ID here.
String appid = "xxxxxxxxxxxxxx";

// Enter your shared secret here.
String secret = "xxxxxxxxxxxxxxxx";

// Enter the user token here.
String token = "xxxxxxxxxxxxxxxxx";

// Get the auth credentials. Create the Yahoo.Authentication object with the
// application ID and secret from the BBAuth signup process.
Yahoo.Authentication auth = new Yahoo.Authentication(appid, secret);

// Set the user token.
auth.Token = token;

// Update the credentials. This will fetch a new WSSID and a "Y" cookie for
// the user.

// Instantiate the SOAP proxy. The proxy was generated when the Web Reference
// was created.
ymws ymwsInstance = new ymws();

// Set up the URL endpoint and add the authentication cookies. The URL must
// include the Web Service Session ID (WSSID) and the application ID.
ymwsInstance.Url = "http://mail.yahooapis.com/ws/mail/v1.1/soap?appid=" +
appid + "&wssid=" + auth.WssId;

#region work normally on desktop without any problems, but can't work normally on WinCE
// Set up the cookie container for the SOAP proxy. Add the "Y" cookie.
ymwsInstance.CookieContainer = new System.Net.CookieContainer();
ymwsInstance.CookieContainer.Add(new Uri("http://mail.yahooapis.com/"),
new Cookie("Y", auth.Cookies.Trim().Substring(2)));
#endregion work normally on desktop without any problems, but can't work normally on WinCE

#region try to resolve the question one WinCE, but hav no result
//HttpWebRequest request = HttpWebRequest.Create("http://mail.yahooapis.com/") as HttpWebRequest;
//request.Headers.Add("Y", auth.Cookies.Trim().Substring(2)); //request.Headers.Add("COOKIE", auth.Cookies);
//request.AllowWriteStreamBuffering = true;
//request.AllowAutoRedirect = false;
//HttpWebResponse response = request.GetResponse() as HttpWebResponse;
//bool bb = request.HaveResponse;
#endregion try to resolve the question one WinCE, but hav no result

try {
// GetUserData, pulls user preferences and account settings.
GetUserDataResponse userData = ymwsInstance.GetUserData(new GetUserData());
Console.WriteLine("Loaded user data for {0}.", userData.data.userSendPref.defaultFromName);

// ListFolders, gets a list of the folders present in the mailbox
// and the message counts for each folder.
ListFoldersResponse folderList = ymwsInstance.ListFolders(new ListFolders());
Console.WriteLine("{0} folders present.", folderList.folder.Length);
foreach(FolderData folder in folderList.folder) {
Console.WriteLine(" {0} - {1}({2})", folder.folderInfo.name, folder.total,
catch(SoapException se) {
// Caught a SOAP fault, report it.
Console.WriteLine("Exception caught!");
Console.WriteLine("Code = " + se.Code.Name);
Console.WriteLine("Message = " + se.Message);

1 Reply
  • #region try to solve the question on WinCE, but have no result

    HttpWebRequest request = HttpWebRequest.Create("http://mail.yahooapis.com/") as HttpWebRequest;
    request.Headers.Add("Y", auth.Cookies.Trim().Substring(2)); //request.Headers.Add("COOKIE", auth.Cookies);
    request.AllowWriteStreamBuffering = true;
    request.AllowAutoRedirect = false;
    HttpWebResponse response = request.GetResponse() as HttpWebResponse; //500 ERROR
    bool bb = request.HaveResponse;
    #endregion try to solve the question on WinCE, but have no result

    Additional information: The remote server returned an error: (500) Internal Server Error.

Recent Posts

in General Discussion at YDN