Skip to content
kppullin edited this page May 17, 2012 · 6 revisions

If you want to support SOAP, you have to note some important things, because of the lack of other HTTP verbs except of POST in SOAP.

Rest only

If you only want to support REST, you can take the easy route:

//Request DTO
public class Customers {...}
public class CustomersService : RestServiceBase<Customers>
{
    //Get customers
    public override object OnGet(Customers request) {...}
    
    //Add customer
    public override object OnPost(Customers request) {...}
    
    //Update customer
    public override object OnPut(Customers request) {...}
    
    //Delete customer
    public override object OnDelete(Customers request) {...}
}
//In the AppHost's configure method
Routes.Add<Customers>("/customers")
    .Add<Customers>("/customers/{Id}");

Soap + Rest

SOAP only supports POST requests. But the REST example makes use of GET, DELETE (...) requests, which aren't available with SOAP. So if you want to support SOAP and REST, you need to create one service for each operation:

//Request DTO
public class GetCustomers {...}
//Service
public class GetCustomersService : ServiceBase<GetCustomers> {
   object Run(GetCustomers request){...}
}

//Request DTO
public class AddCustomer {...}
//Service
public class AddCustomerService : ServiceBase<AddCustomer>  {
   object Run(AddCustomer request){...}
}

//Request DTO
public class UpdateCustomer {...}
//Service
public class UpdateCustomerService : ServiceBase<UpdateCustomer> {
   object Run(UpdateCustomer request){...}
}

//Request DTO
public class DeleteCustomer {...}
//Service
public class DeleteCustomerService : ServiceBase<DeleteCustomer> {
   object Run( DeleteCustomer  request){...}
}

The method Run gets executed on each HTTP verb and on each endpoint.

SOAP also expects that each request always returns the same response DTO. So you need to follow the response DTO naming convention, otherwise ServiceStack won't be able to generate the WSDLs and the SOAP endpoint won't work.

Naming convention: {Request DTO Name} + Response

Example: Request DTO: DeleteCustomer --> Response DTO: DeleteCustomerResponse.

If you would leave the services as they are, the REST endpoint wouldn't exist. So you need to hook them all up on the same URL like that:

//In the AppHost's configure method
Routes.Add<GetCustomers>("/customers", "GET")
  .Add<GetCustomers>("/customers/{Id}", "GET")
  .Add<AddCustomer>("/customers", "POST")
  .Add<UpdateCustomer>("/customers/{Id}", "PUT")
  .Add<DeleteCustomer>("/customers/{Id}", "DELETE")

Note: Don't forget to specify the HTTP verb filters!

Now this webservice supports REST and SOAP and has the same REST endpoint as the above service, they equal 1:1.

Clone this wiki locally