2013-05-22 52 views
0

當我嘗試使用wp7中的NTLM向服務器進行身份驗證時,它給了我一個錯誤「遠程服務器返回了一個錯誤:NotFound。」wp7中的NTLM身份驗證實施錯誤

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(); 


    } 

回答

0

使用支持WP7 insn't NTLM服務器進行身份驗證,它支持WP8 相同的代碼上WP8它給出的結果