wp7中NTLM身份验证实现错误

本文关键字:实现 错误 身份验证 NTLM wp7 | 更新日期: 2023-09-27 18:14:41

当我试图在wp7中使用NTLM与服务器进行身份验证时,它给了我一个错误"远程服务器返回一个错误:NotFound "。

private void callWebservice(object sender, RoutedEventArgs e)
{
    NetworkCredential credentials = new NetworkCredential(userName, Password, domain);
    HttpWebRequest request = CreateWebRequest(url, credentials);
    XDocument soapEnvelope = CreateSoapEnvelope(soapEnvelope );
    InsertSoapEnvelopeIntoWebRequest(soapEnvelope, request);
}
private static HttpWebRequest CreateWebRequest(string url, NetworkCredential credentials)
        {
            string action = link;// my action link
            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
            req.Credentials = credentials;
            req.Headers["SOAPAction"] = action;
            req.ContentType = "text/xml;charset='"utf-8'"";
            req.Accept = "text/xml";
            req.Method = "POST";
            return req;
        }
    private static XDocument CreateSoapEnvelope(string content)
    {
        XDocument soapEnvelopeXml = XDocument.Parse(content);
        return soapEnvelopeXml;
    }
    private static void InsertSoapEnvelopeIntoWebRequest(XDocument soapEnvelopeXml,                          HttpWebRequest webRequest)
    {
        webRequest.BeginGetRequestStream((IAsyncResult asynchronousResult) =>
        {
            HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
            Stream postStream = request.EndGetRequestStream(asynchronousResult);
            soapEnvelopeXml.Save(postStream);
            postStream.Close();
            request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
        }, webRequest);
    }
    private static void GetResponseCallback(IAsyncResult asynchronousResult)
    {
                    HttpWebRequest request =                      (HttpWebRequest)asynchronousResult.AsyncState; 
                    HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
                    Stream streamResponse = response.GetResponseStream();
                    StreamReader streamRead = new StreamReader(streamResponse);
                    string responseString = streamRead.ReadToEnd();
                    //do whatever with the response 
                    MessageBox.Show(responseString);
                    streamResponse.Close();
                    streamRead.Close();
                    response.Close(); 

    }

wp7中NTLM身份验证实现错误

在wp7上不支持使用NTLM与服务器进行身份验证,wp8上支持同样的代码在wp8上它给出了结果