none
[E2010] [EWS Java API 1.1][JAVA] - Getting 405 error code when accessing EWS RRS feed

  • Question

  • Hi All,

     

    I am using jdk 1.6.0_20 and EWS to communicate to Exchange Server 2010 SP1. I am using the following code to access the server.

     

    public class GetFolder {
      public static void main(String[] args) throws Exception {
        setSSLConfig();
        ExchangeService service = new ExchangeService();
        service.setUrl(new URI("https://10.192.17.124"));
    
        ExchangeCredentials credentials = new WebCredentials("userId",
            "password", "domain");
        service.setCredentials(credentials);
    
        Folder folder = Folder.bind(service, WellKnownFolderName.Inbox);
        System.out.println(folder);
      }
    
      // The trust all certs.
      private static TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
    
        @Override
        public void checkClientTrusted(X509Certificate[] arg0, String arg1)
            throws CertificateException {
          // TODO Auto-generated method stub
    
        }
    
        @Override
        public void checkServerTrusted(X509Certificate[] arg0, String arg1)
            throws CertificateException {
          // TODO Auto-generated method stub
    
        }
    
        @Override
        public X509Certificate[] getAcceptedIssuers() {
          // TODO Auto-generated method stub
          return null;
        }
      } };
    
      // Java Secure Socket Connection
      private static HostnameVerifier hv = new HostnameVerifier() {
        @Override
        public boolean verify(String urlHostName, SSLSession session) {
          return true;
        }
    
      };
    
      // Sets the ssl config.
      private static void setSSLConfig() throws Exception {
        SSLContext context = SSLContext.getInstance("SSL");
        context.init(null, trustAllCerts, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(context
            .getSocketFactory());
        HttpsURLConnection.setDefaultHostnameVerifier(hv);
      }
    
    }

    But when I run the test, the line "Folder folder = Folder.bind(service, WellKnownFolderName.Inbox); " is throwing IOException.

     

    java.io.IOException server returned http response code 405 for url : https://10.192.17.124

    And the 405 HTTP status code means

    405 - Method Not Allowed
    A 405 status code is returned when the client has tried to use a request method that the server does not allow. Request methods that are allowed should be sent with the response (common request methods are POST and GET).

     

    Do I need to do any additional setting in the exchange server or IIS for solving this problem?

     

    Thanks in advance,

    Paul

    Wednesday, December 22, 2010 1:29 PM

All replies

  • I would check your IIS logs to make sure that the requests are actually reaching the server.  They may only be getting as far as your router/firewall.
    Outlook Web Access For PDA , OWA For WAP
    www.owa-pda.com
    email a@t leederbyshire d.0.t c.0.m
    Wednesday, December 22, 2010 2:35 PM
  • Oops - you're using a private IP address.  So you're doing all this from the LAN and the router shouldn't get involved.  I would still check the IIS logs to find the 405 response, though.
    Outlook Web Access For PDA , OWA For WAP
    www.owa-pda.com
    email a@t leederbyshire d.0.t c.0.m
    Wednesday, December 22, 2010 2:36 PM
  • If I change the URL provided ("https://10.192.17.124") to "https://10.192.17.124/ews/Exchange.asmx", then the program would work just fine.

    I think the problem is "wsdl" extension does not support some HTTP methods. But "asmx" extension supports all these HTTP methods and Exchange.asmx is just redirecting to "ews/Services.wsdl".

    Please correct me if I am wrong.

     

    Thanks,

    Paul

    Thursday, December 23, 2010 11:44 AM
  • Looking at the handler mapping in IIS reveals that the .asmx file supports only POST (and I can't imagine what else you would send to it).  I can't find a specific handler for .wsdl, so I expect it will accept any verb that IIS will accept.  It would be good to find the 405 entry in the IIS log, and see which verb was sent to which resource.

    It looks like pointing the binding at the .asmx file is the correct thing to do:

    http://msdn.microsoft.com/en-us/library/dd633692(EXCHG.80).aspx


    Outlook Web Access For PDA , OWA For WAP
    www.owa-pda.com
    email a@t leederbyshire d.0.t c.0.m
    Thursday, December 23, 2010 1:52 PM