PDA

View Full Version : A simple Spring Web Service. How to access it?


mainecoona
11-27-2006, 12:45 PM
Hi, all!
I'm trying to expose a PONO as a Web Service.
I take the example from the doku and can't find the way to access it as a Web Service.
I mean http://localhost/...

Can you please correct my files or send me an example of PONO as a web service.


Assembly has a name "SpringWebService1"
Files:

HelloWorldService.cs

using System;
using System.Collections.Generic;
using System.Text;
using Spring.Web.Services;
using System.Web.Services;

namespace SpringWebService1
{
public interface IHelloWorld
{
string HelloWorld();
}
public class HelloWorldService : IHelloWorld
{
private string message;
public string Message
{
set { message = value; }
}
public string HelloWorld()
{
return this.message;
}
}
}
SpringWebService1.vshost.exe.config (I have started with app.config, but Visual Studio opens automatically this file)

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context type="Spring.Context.Support.WebApplicationContext, Spring.Web">
<resource uri="config://spring/objects" />
</context>
<objects xmlns="http://www.springframework.net">
<object name="HelloWorld.asmx" type="SpringWebService1.HelloWorldService, SpringWebService1" abstract="true"/>
<object id="HelloWorld" type="SpringWebService1.HelloWorldService, SpringWebService1">
<property name="Message" value="Hello, World!"/>
</object>
<object id="HelloWorldExporter" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="HelloWorld"/>
<property name="Namespace" value="http://myCompany/services"/>
<property name="Description" value="My exported HelloWorld web service"/>
<property name="MemberAttributes">
<dictionary>
<entry key="HelloWorld">
<object type="System.Web.Services.WebMethodAttribute, System.Web.Services">
<property name="Description" value="My Spring-configured HelloWorld method."/>
<property name="MessageName" value="ZdravoSvete"/>
</object>
</entry>
</dictionary>
</property>
</object>
</objects>
</spring>
<system.web>
<httpHandlers>
<add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web"/>
</httpHandlers>
</system.web>
</configuration>
Server.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using Spring.Context.Support;

namespace SpringWebService1
{
public class Server
{
[STAThread]
static void Main()
{
try
{
ContextRegistry.GetContext();
Console.Out.WriteLine("Server listening...");
}
catch (Exception e)
{
Console.Out.WriteLine(e);
}
finally
{
Console.Out.WriteLine("--- Press <return> to quit ---");
Console.ReadLine();
}
}
}

}

Bruno Baia
11-27-2006, 10:42 PM
Hi,

Thanks to give Spring a try :)
Take a look to the Spring.Calculator and SpringAir example. Both expose PONOs as a Web Service.


Hope this helps,
Bruno

mainecoona
11-28-2006, 06:14 AM
Hi, Bruno!
Thank you for the answer.

I have found, that Spring.Net kann not host Web Services.