System.Collections.ListofTips System.Collections.ListofTips

May 17, 2008 May 17, 2008

Consumir Web Services con Spring.net Consuming Web Services with Spring.net

Filed under: Spring.net — José Franco @ 8:14 pm Filed under: Spring.net - Jose Franco @ 8:14 pm

Bueno, el ejemplo que arme anteriormente, lo publique con el IIS en un directorio virtual llamado WSUserAuthentication Well, the arm example above, with the publication in an IIS virtual directory called WSUserAuthentication

Ahora, vamos a armar un cliente que consuma este WS, sin una Web Refence , sino por spring.net. Now, let's build a client that consumes this WAS without a Web Refence but by spring.net.

Generamos un nuevo proyecto web, tenemos que refenciar a las librerías de Spring, como también a la interfaz de nuestro Web Services y la capa que genere como “TransferObjects”, que tiene el objeto que va a recibir el cliente. Create a new web project, we must refenciar the Spring libraries, as well as the interface of our Web Services and the layer that generates as TransferObjects ", which is the object that the client will receive.

Habría que pensar cómo vamos a hacer, para versiones posteriores, el control de las versiones de los asemblys, en caso de hacer modificaciones en nuestro WS, una alternativa seria colocarlos en la GAC, para olvidarnos de tener que copiar en todos los desarrollos que llamen al WS, la última versión en caso de necesitarla. Would have to think how we will do so later, the control of the versions of the asemblys, if we make changes in WAS, an alternative would place them in the GAC, to forget about having to copy all the developments that call WAS andalusia, the latest version if needed.

En mi caso, genero una carpeta de Configuración, con un Xml de los objetos que consumo en spring, en este caso In my case, I generate a setup package, with one of the objects that Xml consumption in spring, in this case

<? xml <? Xml
version =1.0 version = "1.0"
encoding =utf-8?> encoding = "utf-8"?>

< objects <Objects
xmlns =http://www.springframework.net> xmlns = "http://www.springframework.net">

< description > An example that demonstrates simple IoC features. </ description > <Description> An example that demonstrates simple IOC features. </ Description>

<!– Web Services –> <! - Web Services ->

< object <Object
id =UsuarioWS id = "UsuarioWS"


type =Spring.Web.Services.WebServiceProxyFactory, Spring.Services> type = "Spring.Web.Services.WebServiceProxyFactory, Spring.Services">

< property <Property


name =ServiceUri name = "ServiceUri"


value =http://localhost/WSUserAuthentication/UserServices.asmx value = "http://localhost/WSUserAuthentication/UserServices.asmx"

/> />

< property <Property


name =ServiceInterface name = "ServiceInterface"


value =Synnax.Core.WS.UserAuthentication.Entitys.IUserService, Synnax.Core.WS.UserAuthentication.Entitys value = "Synnax.Core.WS.UserAuthentication.Entitys.IUserService, Synnax.Core.WS.UserAuthentication.Entitys"

/> />

</ object > </ Object>

</ objects > </ Objects>

Genero un objeto, llamado “UsuarioWS”, que es del tiplo del WebServiceProxyFactory, que especificamos la ServiceUri que es donde tenemos corriendo nuestro WS, con el servicio que insumimos, y la interfaz que implementa. Gender an object called "UsuarioWS", which is treble the WebServiceProxyFactory, which specify the ServiceUri where we ran our WAS, with the service inputs and implements the interface.

Definimos el contexto del spring, y la configuracion de los objetos. We define the context of the spring, and the configuration of the objects.

< configuration > <Configuration>

< configSections > <ConfigSections>

< sectionGroup <SectionGroup
name =spring> name = "spring">

< section <Section
name =context name = "context"
type =Spring.Context.Support.ContextHandler, Spring.Core/> type = "Spring.Context.Support.ContextHandler, Spring.Core" />

</ sectionGroup > </ SectionGroup>

</ configSections > </ ConfigSections>

< appSettings /> <AppSettings />

< connectionStrings /> <ConnectionStrings />

< system.web > <System.web>

< compilation <Compilation
debug =false> debug = "false">

< assemblies > <Assemblies>

< add <Add
assembly =Spring.Core, Version=1.1.2.20125, Culture=neutral, PublicKeyToken=65E474D141E25E07/> assembly = "Spring.Core, Version = 1.1.2.20125, Culture = neutral, PublicKeyToken = 65E474D141E25E07" />

< add <Add
assembly =Spring.Services, Version=1.1.2.20125, Culture=neutral, PublicKeyToken=65E474D141E25E07/> assembly = "Spring.Services, Version = 1.1.2.20125, Culture = neutral, PublicKeyToken = 65E474D141E25E07" />

< add <Add
assembly =Spring.Web, Version=1.1.2.20125, Culture=neutral, PublicKeyToken=65E474D141E25E07/></ assemblies ></ compilation > assembly = "Spring.Web, Version = 1.1.2.20125, Culture = neutral, PublicKeyToken = 65E474D141E25E07" /> </ assemblies> </ compilation>

< authentication <Authentication
mode =Windows/> mode = "Windows" />

</ system.web > </ System.web>

< spring > <Spring>

< context > <Context>

< resource <Resource
uri =~/Configuration/Objects.xml/> uri = "~ / Configuration / Objects.xml" />

</ context > </ Context>

</ spring > </ Spring>

</ configuration > </ Configuration>

Y desde la aplicación And since the implementation

IUserService _ws = ( IUserService ) ContextRegistry .GetContext().GetObject( “UsuarioWS” ); IUserService _ws = (IUserService) ContextRegistry. GetContext (). GetObject ( "UsuarioWS");

lblMessage.Text = _ws.Test(); lblMessage.Text = _ws.Test ();

Con nuestro metodo, Test, como devuelve un string, no hay que castearlo, encambio en el otro metodo tendriamos que estar usando, los objetos de Transfer Objects. With our method, Test, returned as a string, no caste, encambio in the other method would have to be using the objects of Transfer Objects.

Les dejo, el ejemplo para que lo vean: I leave you, for example to see:

Consumiendo Web Services con Spring Consuming Web Services with Spring

Sepan disculpar, los horrores de ortografía, ya que lo hice rapidito a este post, Saludos! Apologize know the horrors of spelling, as I did this post quickly, Greetings!

Share and Enjoy: Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • E-mail this story to a friend!
  • BarraPunto
  • blogmarks
  • co.mments
  • De.lirio.us
  • kick.ie
  • LinkedIn
  • Linkter
  • Live
  • Meneame
  • MyShare
  • Print this article!
  • TwitThis
  • YahooMyWeb
Bookmark and Share: Bookmark and Share:

No Comments » No Comments »

No comments yet. No comments yet.

RSS feed for comments on this post. TrackBack URL RSS feed for comments on this post. TrackBack URL

Leave a comment Leave a comment

Powered by WordPress Powered by WordPress