views:

46

answers:

1

I want to consume Java based web service with c#.net client.

The problem is, I couldnt authenticate to the service.

it didnt work with this:

mywebservice.Credentials = new System.Net.NetworkCredential(userid, userpass);

I tried to write base class for my client method.

public class ClientProtocols : SoapHttpClientProtocol
    {
        protected override WebRequest GetWebRequest(Uri uri)
        {
            System.Net.WebRequest request = base.GetWebRequest(uri);
            if (null != Credentials)
                request.Headers.Add("Authorization", GetAuthHeader());
            return request;
        }
        protected override WebResponse GetWebResponse(WebRequest request)
        {
            WebResponse response = base.GetWebResponse(request);
            return response;
        }
        private string GetAuthHeader()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("Basic ");
            NetworkCredential cred = Credentials.GetCredential(new Uri(Url), "Basic");
            string s = string.Format("{0}:{1}", cred.UserName, cred.Password);
            sb.Append(Convert.ToBase64String(Encoding.ASCII.GetBytes(s)));
            return sb.ToString();
        }
    }

How can I use this class and authorize to the web service? Where do I put this class in solution?

Thanks.

A: 

I have solved my problem:

http://www.xtremevbtalk.com/showthread.php?t=299559

Jack