title: WCF Web service returns 401 Unauthorised when accessed from JAVA web application
body: <p>We are able to access a WCF web service from a plain Java client through the main method. </p>
  
  <p>However, when we try to access the same through a Java EE application, (from the DAO layer) 
  it displays an error.</p>
  
  <p>Our code is :  </p>
  
  <hr>
  
  <pre><code>BasicHttpBinding_ISPHostedIMServiceStub stub = new BasicHttpBinding_ISPHostedIMServiceStub(
      new URL("http://mscxxxx.svc?wsdl"),
      new SPHostedIMServiceLocator());
  
  stub.setUsername(username);
  stub.setPassword(password);
  
  stub.getTask();
  </code></pre>
  
  <hr>
  
  <h2>Error -</h2>
  
  <pre><code>AxisFault
   faultCode: {http://xml.apache.org/axis/}HTTP
   faultSubcode: 
   faultString: (401)Unauthorized
   faultActor: 
   faultNode: 
   faultDetail: 
      {}:return code:  401
  401 UNAUTHORIZED
      {http://xml.apache.org/axis/}HttpErrorCode:401
  
  (401)Unauthorized
      at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:744)
      at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:144)
      at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
      at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
      at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
      at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
      at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
      at org.apache.axis.client.Call.invoke(Call.java:2767)
      at org.apache.axis.client.Call.invoke(Call.java:2443)
      at org.apache.axis.client.Call.invoke(Call.java:2366)
      at org.apache.axis.client.Call.invoke(Call.java:1812)
      at org.tempuri.BasicHttpBinding_ISPHostedIMServiceStub.getAllTasks(BasicHttpBinding_ISPHostedIMServiceStub.java:255)
      at com.xxxxImpl.java:195)
      at com.xxxxxImpl.getIncident(inessImpl.java:69)
      at com.xxxxService.getIncidentsPost(Geervice.java:41)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:168)
      at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:71)
      at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:280)
      at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
      at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
      at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
      at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1341)
      at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1273)
      at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1223)
      at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1213)
      at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414)
      at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
      at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <hr>
  
  <p>There is no issue with the proxy, as both are in the same network.
  We are using NTLM authentication.</p>
  
  <p>Any pointers are appreciated.</p>