Using Basic SSL Authentication on Windows Phone 7

I know that variants of this question were asked, but I tried all the proposed solutions to no avail. We are trying to connect to the WCF service, which uses basic authentication and transport security (unfortunately, these things cannot be changed). I could not find a way to add our credentials to TRANSPORT by calling WCF; all solutions seem to be adding headers to the message.

Our latest attempt is to grab a text file from the server using HttpWebClient, which has credentials attached, and then make a WCF call; we hope that authentication will then ... I do not know, go from the HttpWebClient to the WCF client (generated using the Service Reference). And although the first call does work, we get a CommunicationException in the WCF call (and if I delve into the answer, the Status Description parameter is set to Unauthorized).

Is there a way for clients to share an authorization token that was returned from a successful attempt? Is this a crazy errand? Is there an easier way to do this so that I can also see the blind?

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("https://server/OGTE/api/WinPhone7.html"));

        request.Credentials = new NetworkCredential(_userName, _password, _domain);
        request.Method = "GET";

        request.BeginGetResponse((beginGetResponseResult) =>
        {
            try
            {
                HttpWebRequest requestWhileResponding = (HttpWebRequest)beginGetResponseResult.AsyncState;
                HttpWebResponse response = (HttpWebResponse)requestWhileResponding.EndGetResponse(beginGetResponseResult);

                try
                {
                    using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream()))
                    {

                         string info = streamReader1.ReadToEnd();

                        Dispatcher.BeginInvoke(() =>
                                                   {
                                                       textblock.Text = info;
                                                   });

                    }

                    _userDataService.GetDataCompleted += new EventHandler<GetDataCompletedEventArgs>(_userDataService_GetDataCompleted);
                    _userDataService.GetDataAsync("0C5696BB-2D15-4EA7-B198-5C12B3E23B63");

                }
                catch (Exception ex)
                {

                    Debug.WriteLine(ex.ToString());
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        },

    request);
    }
+3
2

, , , . , , : http://cisforcoder.wordpress.com/2010/12/01/how-to-implement-basic-http-authentication-in-wcf-on-windows-phone-7/. , , :

var credentials = EncodeBasicAuthenticationCredentials("username", "password");

using (OperationContextScope scope =
      new OperationContextScope(service.InnerChannel))
{
    HttpRequestMessageProperty request = new HttpRequestMessageProperty();
    request.Headers[System.Net.HttpRequestHeader.Authorization] = 
        "Basic " + credentials;

    OperationContext.Current.OutgoingMessageProperties.Add(
                                 HttpRequestMessageProperty.Name, request);

    service.DoSomethingAsync();
}

, - , , - , .

+1

, REST, RestSharp. HttpBasicAuthenticator, yo . REST. REST WCF. , RestSharp

+2

Source: https://habr.com/ru/post/1774135/


All Articles