PDA

View Full Version : Web Services Proxy Problem with Integrated Windows Authentication


Sabit Biba
09-05-2007, 01:37 PM
Hi,

I wrote an example client web application that will connect to a spring generated Web Service proxy as explained in http://www.springframework.net/doc-latest/reference/html/webservices.html.
However, the problem that I encountered after configuring the Web Service and Client was, that if spring is used to generate the proxy it will only work if the Virtual Directory is set to Anonymous Access, if Windows Integrated Authentication is selected the following error is displayed “System.Net.WebException: The request failed with HTTP status 401: Access Denied.”

Configuration Files:

Client Config:

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net" >
<object id="HelloWorldService" type="Spring.Web.Services.WebServiceProxyFactory, Spring.Services">
<property name="ServiceUri" value="http://localhost/SpringExampleWebServiceDynamic/HelloWorldExporter.asmx"/>
<property name="ServiceInterface">
<value>CommonInterface.IMyService, CommonInterface</value>
</property>
</object>
</objects>


Web Server Config:

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net" >
<object name="HelloWorld.asmx" type="DynamicWebService.HelloWorldService, DynamicWebService"/>

<object id="HelloWorld" type="DynamicWebService.HelloWorldService, DynamicWebService">
<property name="message">
<value>This Web Services Proxy was generated Dynamically</value>
</property>
</object>

<object id ="HelloWorldExporter" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName">
<value>HelloWorld</value>
</property>
<property name="NameSpace">
<value>http://myCompany.services</value>
</property>
<property name="MemberAttributes">
<dictionary>
<entry key="HelloWorld">
<object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
<property name="MessageName">
<value>SabitBiba</value>
</property>
</object>
</entry>
</dictionary>
</property>
<property name="Interfaces">
<list>
<value>CommonInterface.IMyService, CommonInterface</value>
</list>
</property>
</object>
</objects>


While investigateing the source code I noticed that when SoapHttpClientProtocol is initiated the UseDefaultCredentials property is set to false.
By introducing a UseDefaultCredentials as a property in WebServiceProxyFactory class and modifying the GetObject method I was able to connect to Web Services with Integrated Windows Authentication selected in virtual directory.

private bool useDefaultCredentials = false;
public bool UseDefaultCredentials
{
get { return useDefaultCredentials; }
set { useDefaultCredentials = value; }
}

public virtual object GetObject()
{
if (proxyConstructor == null)
{
GenerateProxy();
}
Object proxyObject = ObjectUtils.InstantiateType(proxyConstructor, ObjectUtils.EmptyObjects);
if (UseDefaultCredentials)
{
SoapHttpClientProtocol soapHttpProxy = proxyObject as SoapHttpClientProtocol;
if (soapHttpProxy != null)
soapHttpProxy.UseDefaultCredentials = true;
}

return proxyObject;

//return ObjectUtils.InstantiateType(proxyConstructor, ObjectUtils.EmptyObjects);
}


New Client config File. Please Note UseDefaultCredentials property:

?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net" >
<object id="HelloWorldService" type="Spring.Web.Services.WebServiceProxyFactory, Spring.Services">
<property name="ServiceUri" value="http://localhost/SpringExampleWebServiceDynamic/HelloWorldExporter.asmx"/>
<property name="ServiceInterface">
<value>CommonInterface.IMyService, CommonInterface</value>
</property>
<property name="UseDefaultCredentials" value="true"></property>
</object>
</objects>


I would be grateful if you could review my solution with respect to the problem at hand. I am not aware of any other solution method, but I would appreciate any advise if a known solution already exists for this problem

Regards,

.ben
09-05-2007, 06:46 PM
Can't this be set via the ProductTemplate property?

Bruno Baia
09-05-2007, 07:23 PM
Hi,

Can't this be set via the ProductTemplate property?
Yep !

See reference documentation for an example :
26.2. Client-side (http://www.springframework.net/doc-latest/reference/html/webservices.html#client-side)
5.5.4. IConfigurableFactoryObject (http://www.springframework.net/doc-latest/reference/html/objects.html#objects-factory-lifecycle-configurablefactoryobject)

The WebServiceProxyFactory also implements the interface, Spring.Objects.Factory.IConfigurableFactoryObject, allowing to specify configuration for the product that the WebServiceProxyFactory creates. This is done by specifying the ProductTemplate property. This is particularly useful for securing the web service.


In your example :

<objects xmlns="http://www.springframework.net" >
<object id="HelloWorldService" type="Spring.Web.Services.WebServiceProxyFactory, Spring.Services">
<property name="ServiceUri" value="http://localhost/SpringExampleWebServiceDynamic/HelloWorldExporter.asmx"/>
<property name="ServiceInterface" value="CommonInterface.IMyService, CommonInterface"/>
<property name="ProductTemplate>
<object>
<property name="UseDefaultCredentials" value="true"/>
</object>
</property>
</object>
</objects>



HTH,
Bruno

Sabit Biba
09-06-2007, 10:19 AM
It works. Thats perfect!
Thanks!