0
votes

Metadata contains a reference that cannot be resolved: 'http://192.168.1.86:8080/spectrum/restful/models'. The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm="spectrum"'. The remote server returned an error: (401) Unauthorized. If the service is defined in the current solution, try building the solution and adding the service reference again.

This is the AUnthencation PopUp enter image description here Error That is comming while adding the reference in the windows solution

Any help please !!

1
The service is available only for authenticated users. Thus, you have to supply credentials to get the metadata, otherwise, you can't connect to this service in any way.Jacob
Yes Jacob, I have supplied the credentials but still I am not able to connect. But if I consume the service using soap-UI by passing the Credentials in that case I am getting the final result.AnCh

1 Answers

0
votes

string res = string.Empty;

        string url = "http://192.168.1.86:8080/spectrum/restful/models";
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Credentials = CredentialCache.DefaultCredentials;
        string authInfo = userName + ":" + password;
        authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
        request.Headers["Authorization"] = "Basic " + authInfo;
        HttpWebResponse response = null;
        try
        {
            response = (HttpWebResponse)request.GetResponse();
            Stream dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            string responseFromServer = reader.ReadToEnd();
            HttpStatusCode errorCode = response.StatusCode;
            reader.Close();
            dataStream.Close();
            response.Close();
            res = responseFromServer;
        }
        catch (Exception ex)
        {
            if (response == null && ex.Message.Contains("400"))
                res = "NoSuchUser";
            else
                res = ex.Message;
        }