当我尝试使用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();
}
答案 0 :(得分:0)
在wp7上使用NTLM对服务器进行身份验证不受支持,在wp8上受支持 wp8上的代码相同,它给出了结果