Results 1 to 2 of 2

Thread: Using NTLM authentication on client proxy created using WebServiceProxyFactory

  1. #1
    Join Date
    Mar 2011
    Posts
    25

    Default Using NTLM authentication on client proxy created using WebServiceProxyFactory

    Hi,

    I'm running into some problems when calling webservices through a proxy created by WebServiceProxyFactory.
    Spring successfully retrieves the wsdl to generate the proxy, but when I call web methods on the proxy, it fails with 401 (unauthorized) exception.
    I have configured the correct credentials on the WebServiceProxyFactory.

    Inspection with wireshark confirms that on the GET call to retrieve the wsdl, authentication succeeds.
    And that the web method invocation (http POST) fails wit a 401.

    When I use VS to generate a proxy (taking the "classic" create web reference approach), I can successfully invoke authenticated web method calls.

    I'm probably missing something here. Any thoughts?

    Some more details:

    I configured the website on our dev server (Win server 2003, IIS 6.0, .net 3.5 sp1) to use NTLM authentication.

    The container of the client configures successfully, and when I use wireshark to monitor http traffic and run the client, I can see that it successfully authenticates when it does a GET to retrieve the wsdl. On the first method call by the client (a POST obv), a 401 is returned and the client fails with:

    Code:
    2012-03-05 13:54:15,012 ERROR - Could not invoke method 'MyMethod' on target object
    [MyNamespace.MyClass]
    System.Net.WebException: The request failed with HTTP status 401: Unauthorized.
       at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClie
    ntMessage message, WebResponse response, Stream responseStream, Boolean asyncCal
    l)
       at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodN
    ame, Object[] parameters)
       at SoapHttpClientProxy_41aa3e21304d4e689ab2a0d9ba69c419.MyRemoteMethod(Int64
     changeNumber)
    My current configuration on the server:

    HTML Code:
      <object id="MyService" type="WebServiceExporter">
        <property name="TargetName" value="myTarget"/>
        <property name="Namespace" value="http://services.mycompany/2012/01/21"/>
        <property name="Description" value="My Description"/>
        <property name="MemberAttributes">
          <dictionary>
          </dictionary>
        </property>
      </object>
    The client:

    HTML Code:
      <object id="credential" type="System.Net.NetworkCredential, System">
        <property name="Domain" value="mydomain" />
        <property name="UserName" value="myuser" />
        <property name="Password" value="mypassword" />
      </object>
    
      <object id="webServiceProxyFactoryBase"
              type="WebServiceProxyFactory"
              abstract="true">
        <property name="Credential" ref="credential" />
        <property name="ProductTemplate">
          <object>
            <property name="Timeout" value="10000" />
          </object>
        </property>
      </object>
    
      <object id="myWebServiceProxy" 
              type="WebServiceProxyFactory"
              parent="webServiceProxyFactoryBase">
        <property name="ServiceUri" value="${rooturl}/myservice.asmx" />
        <property name="ServiceInterface" value="myinterface>" />
      </object>



    Regards,


    ~Marijn


    Note: I previously posted a more detailed question, but that one never became visible on the forum, probably due to moderation?
    Edit: well, it's visible now: http://forum.springframework.net/sho...ces-quot-calls; I've merged that post into this one.
    Last edited by Marijn; 06-25-2012 at 11:19 AM.

  2. #2
    Join Date
    Mar 2011
    Posts
    25

    Default

    (sorry for the late pingback)

    Well, this was obviously a configuration mistake of mine ... as stated in de documentation on webservices you should configure the credentials on the ProductTemplate, as well as on the factory object:

    HTML Code:
      <object id="credential" type="System.Net.NetworkCredential, System">
        <!-- snip -->
      </object>
    
      <object id="webServiceProxyFactoryBase"
              type="WebServiceProxyFactory"
              abstract="true">
        <property name="Credential" ref="credential" />
        <property name="ProductTemplate">
          <object>
            <property name="Timeout" value="10000" />
            <!-- also configure the credentials of the created proxy! -->
            <property name="Credentials" ref="credential"/>
          </object>
        </property>
      </object>
    
      <object id="myWebServiceProxy" 
              type="WebServiceProxyFactory"
              parent="webServiceProxyFactoryBase">
      <!-- snip -->
    The first credential is needed by the WebServiceProxyFactory to retrieve the wsdl.
    The second credential is used by the WebServiceProxyFactory to inject on the web service proxy object it creates.
    I you omit the second credential, the WebServiceProxyFactory is able to retrieve the wsdl, but the proxies it create don't use a credential, which leads to the error from my previous post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •