自从过去3天以来,我一直在尝试从Windows Phone 8.1连接EWS。但是我无法与EWS联系。
如上所述,如果我们将在Windows Phone 8.1中实现该代码,他们所做的代码,代码给我们例外"方法不受支持"。
如果我们尝试使用Windows Phone 8.1中的 HttpClient 连接EWS的edmx网址。它会给我们带来未经授权的错误。
我已经检查了连接EWS的iphone和android代码。工作正常。
任何人都能帮助我吗?
Hi Jason,
I tried using HTTPWebRequest, in a sample command line project and it works fine. Below is the code -
public bool Request(string URL, string RequestXML, NetworkCredential UserCredentials)
{
HttpWebRequest SoapRequest = (HttpWebRequest)WebRequest.Create(URL);
StreamWriter RequestWriter=null;
Stream ResponseStream=null;
HttpWebResponse SoapResponse=null;
try
{
SoapRequest.AllowAutoRedirect = false;
SoapRequest.Credentials = UserCredentials;
SoapRequest.Method = "POST";
SoapRequest.ContentType = "text/xml";
RequestWriter = new StreamWriter(SoapRequest.GetRequestStream());
RequestWriter.Write(RequestXML);
RequestWriter.Close();
SoapResponse = (HttpWebResponse)SoapRequest.GetResponse();
if (SoapResponse.StatusCode == HttpStatusCode.OK)
{
ResponseStream = SoapResponse.GetResponseStream();
ResponseEnvelop = XElement.Load(ResponseStream);
return true;
}
else
{
return false;
}
}
catch(Exception ex)
{
ResponseEnvelop = null;
return false;
throw ex;
}
finally
{
SoapRequest = null;
RequestWriter.Dispose();
RequestWriter = null;
ResponseStream.Dispose();
ResponseStream = null;
SoapResponse.Dispose();
SoapResponse = null;
}
}
-------------
However some methods are not available in Windows App, so tried below code. There are no compile errors but I receive error "Method not supported". I am trying from weeks but no luck, wondering is some help is available
public async Task<bool> Request(string URL, string RequestXML, NetworkCredential UserCredentials)
{
HttpWebRequest SoapRequest = (HttpWebRequest)WebRequest.Create(URL);
StreamWriter RequestWriter = null;
Stream ResponseStream = null;
WebResponse SoapResponse = null;
try
{
SoapRequest.Credentials = UserCredentials;
SoapRequest.Method = "POST";
SoapRequest.ContentType = "text/xml";
RequestWriter = new StreamWriter(await System.Threading.Tasks.Task<Stream>.Run(() => SoapRequest.GetRequestStreamAsync()));
RequestWriter.AutoFlush = true;
RequestWriter.Write(RequestXML);
SoapResponse = await System.Threading.Tasks.Task<Stream>.Run(() => SoapRequest.GetResponseAsync());
ResponseStream = SoapResponse.GetResponseStream();
ResponseEnvelop = XElement.Load(ResponseStream);
return true;
}
Appreciate some quick help
Thanks,
Nasir