Make sure you read about the limitations of SOAP when creating the services that you want to use SOAP. those. you need to save one XSD / WSDL namespace. For instance. You can change the default WSDL namespace in your AppConfig with:
SetConfig(new EndpointHostConfig { WsdlServiceNamespace = "http://my.new.namespace.com/types", });
Specifies which WSDL / XSD namespace will be used on the generated WSDL page. You also need to map this XSD namespace to your [DataContract] DTO, specifying a namespace for each DataContract, which you can do by manually specifying each
[DataContract(Namespace="http://my.new.namespace.com/types")]
or you can specify
[assembly: ContractNamespace("http://my/custom/namespace", ClrNamespace = "TheGuest.Test")]
to install it on multiple DTOs in a common C # namespace.
Also, several things have changed lately, we added a New API and added different attributes so that you can annotate your services (which will appear in the metadata / and Api Docs / Swagger pages). Given these changes, a new way to create your service:
[DataContract] [Api("A sample web service.")] public class Greet { [DataMember] [ApiMember("The name of the person you wish to greet")] public string Name { get; set; } } [DataContract] public class GreetResponse { [DataMember] public string Result { get; set; } } public class GreetService : Service { public GreetResponse Any(Greet request) { return new GreetResponse { Result = "Hello " + request.Name }; } }
Tell ServiceStack what type of service response
In order for ServiceStack to determine the response type of your service, you must specify any of the following tips:
Using Type Return Type
Your services can either return type object , or now ResponseDto , for example:
public class GreetService : Service { //1. Using Object public object Any(Greet request) { return new GreetResponse { Result = "Hello " + request.Name }; } //2. Above service with a strong response type public GreetResponse Any(Greet request) { return new GreetResponse { Result = "Hello " + request.Name }; } }
If you use option 2) ServiceStack will use the GreetResponse type.
Use the IReturn Marker Interface
[DataContract] public class Greet : IReturn<GreetResponse> { ... }
Another advantage of using the Marker interface is that it provides a more concise client API, for example:
GreetResponse response = client.Send(new Greet { Name = "World!" });
If you did not have a Marker interface, the client API would be:
GreetResponse response = client.Send<GreetResponse>(new Greet { Name = "World!" });
Use typeof naming convention (RequestDto) .Name + 'Response'
If your services have an object response type and a token interface, than you can use the {RequestDto}Response naming convention to tell ServiceStack what the response type is.
Note. For ServiceStack to find the type of response, it must be in the same namespace as the DTO request. In addition, each DTO request and response must be uniquely named, this is what allows you to call the ServiceStack service only with the name of the DTO request , and not with the full namespace.