EWS API error - The response received from the service didn't contain valid XML.
-
lunes, 16 de abril de 2012 13:53
Hi, I'm trying to send mail via the EWS API.
I'm getting the above error.
Visual studio - 2010
I'm actually doesn't know what exchange version i'm using. but I tried:
2007-SP1
2010
2010-SP1
They all give me the same error.
this is my code:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010); service.Credentials = new WebCredentials("shaul", "SSS8i8i8i"); service.TraceEnabled = true; System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true); service.Url = new Uri("https://81.218.142.215:9992/EWS/Exchange.asmx"); EmailMessage mail = new EmailMessage(service); mail.From = new EmailAddress("shaul@internety.biz"); mail.ToRecipients.Add("shaul.noal@gmail.com"); mail.Subject = "Email Subject"; mail.Body = "Email Body"; mail.Send();Thanks in advance
Shaul
Todas las respuestas
-
martes, 17 de abril de 2012 5:41
The default port of of EWS is 443 for EWS to be binding on port 9992 would have required reconfiguration of IIS on the Exchange server or some sort of port forwarding.
What do the traces look like (eg are you getting a SOAP response for the server? this will also tell you what version of Exchange the server is running).
I would suggest you try to test whether EWS works first using the EWS Editor http://archive.msdn.microsoft.com/ewseditor with the credentials you using try using the users UPN.
On a normal Exchange Server you should also be able to use https://www.testexchangeconnectivity.com/ and run the EWS tests.
Cheers
Glen -
martes, 17 de abril de 2012 16:09
Thaks for your help. I have used the EWS Editor. I could not establish connection. I used the same Credentials as isued in my code.
I get the next Error:
Exception details: Message: The request failed. The underlying connection was closed: An unexpected error occurred on a receive. Type: Microsoft.Exchange.WebServices.Data.ServiceRequestException Source: Microsoft.Exchange.WebServices Stack Trace: at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(HttpWebRequest& request) at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute() at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute() at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalConvertIds(IEnumerable`1 ids, IdFormat destinationFormat, ServiceErrorHandling errorHandling) at EWSEditor.Common.Extensions.ExchangeServiceExtensions.TestExchangeService(ExchangeService service) in C:\Users\mstehle\Documents\codeplex\ewseditor\Common\Extensions\ExchangeServiceExtensions.cs:line 171 at EWSEditor.Forms.ServiceDialog.BtnOK_Click(Object sender, EventArgs e) in C:\Users\mstehle\Documents\codeplex\ewseditor\Forms\Dialogs\ServiceDialog.cs:line 116 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) Exception details: Message: The underlying connection was closed: An unexpected error occurred on a receive. Type: System.Net.WebException Source: System Stack Trace: at System.Net.HttpWebRequest.GetResponse() at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.Emit(HttpWebRequest& request) at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(HttpWebRequest& request) Exception details: Message: Type provided must be an Enum. Parameter name: enumType Type: System.ArgumentException Source: mscorlib Stack Trace: at System.Enum.GetName(Type enumType, Object value) at EWSEditor.Common.ValidationCallbackHelper.CertificateValidationCallBack(Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) in C:\Users\mstehle\Documents\codeplex\ewseditor\Common\ValidationCallbackHelper.cs:line 32 at System.Net.ServerCertValidationCallback.Callback(Object state) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Net.ServerCertValidationCallback.Invoke(Object request, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) at System.Net.Security.SecureChannel.VerifyRemoteCertificate(RemoteCertValidationCallback remoteCertValidationCallback) at System.Net.Security.SslState.CompleteHandshake() at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) at System.Net.ConnectStream.WriteHeaders(Boolean async)
(Also i have tried to change the port number to 443.)
Another issue (maybe). I don't knoe if it helps. In oreder to access throw the web to the mailbox I use a different user name: YYYYY\XXXXX and in my program i'm using only the XXXXX. What should I use? the YYYY\XXXX Or the XXXXX or the XXXXX@GGGGGG.biz? maybe this is the problem?
Shaul
- Editado Shaul Zuarets martes, 17 de abril de 2012 16:50
-
miércoles, 18 de abril de 2012 4:37
The errors your getting indicate your not hitting the EWS endpoint eg if this was an authentication error you would be getting 401 unauthorized etc.
Check your server and firewall configuration (you might need to check your client firewall config as well)
You shouldn't need to put a port in at all unless you doing something strange with the server/firewall config.
Can you use OWA on this server ? eg does https://81.218.142.215/owa work ? if its does try https://81.218.142.215/ews/exchange.asmx you should also be able to browse to the WSDL file eg https://81.218.142.215/ews/services.wsdl
are you sure your pointing at the CAS Server ?
Cheers
Glen -
miércoles, 18 de abril de 2012 9:55
Thanks Glen,
I turned off the firewall.
The OWA works judt fine.
Trying to access to the https://81.218.142.215/ews/exchange.asmx and the https://81.218.142.215/ews/services.wsdland
is good, and I can see the full XML file in the web browser.
The web access is just fine. only when I try to access it with the C# app and the EWS editor it' fail.
What is CAS server?
Thanks a lot,
Shaul
-
miércoles, 18 de abril de 2012 10:22
Glen, I tried the microsoft test tool (the link you post). This is the result:
"
Exchange Web Services service account access verification ExRCA failed to complete all tests with the service account. 
Test Steps 
Ensuring that the test mailbox folder is empty and accessible. ExRCA couldn't confirm that the folder is accessible and empty. 
Additional Details Exception details:
Message: The response received from the service didn't contain valid XML.
Type: Microsoft.Exchange.WebServices.Data.ServiceRequestException
Stack trace:
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadXmlDeclaration(EwsServiceXmlReader reader)
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadSoapFault(EwsServiceXmlReader reader)
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ProcessWebException(WebException webException)
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request)
at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
at Microsoft.Exchange.WebServices.Data.ExchangeService.BindToFolder[TFolder](FolderId folderId, PropertySet propertySet)
at Microsoft.Exchange.Tools.ExRca.Tests.EnsureEmptyFolderTest.PerformTestReally()
Exception details:
Message: Root element is missing.
Type: System.Xml.XmlException
Stack trace:
at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res)
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlCharCheckingReader.Read()
at Microsoft.Exchange.WebServices.Data.EwsXmlReader.Read(XmlNodeType nodeType)
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadXmlDeclaration(EwsServiceXmlReader reader)"
-
miércoles, 18 de abril de 2012 10:56
What are the patch levels like on the servers there was a know problem caused by .net 3.5 sp1 where there is hotfix to fix
http://support.microsoft.com/kb/958934 this is an old issue from 2010 but if you aren't running the latest Exchange Service packs and rollups probably the cause.Cheers
Glen -
miércoles, 18 de abril de 2012 12:31
Hi glen, The problem is probably in the exchange server. Do you have any ideas how to solve the problem in the exchange?
Shaul
- Editado Shaul Zuarets miércoles, 18 de abril de 2012 13:56
- Editado Shaul Zuarets miércoles, 18 de abril de 2012 20:14
-
jueves, 19 de abril de 2012 2:24
I would suggest applying the Hotfix http://support.microsoft.com/kb/958934 and also upgrade to the latest Service Pack and rollup for the version of Exchange your using which should fix the problems with EWS.
Cheers
Glen

