Test

<back to all web services

HelloInterface

import 'package:servicestack/servicestack.dart';
import 'dart:typed_data';

abstract class IPoco
{
    String? name;
}

abstract class IEmptyInterface
{
}

class EmptyClass implements IConvertible
{
    EmptyClass();
    EmptyClass.fromJson(Map<String, dynamic> json) : super();
    fromMap(Map<String, dynamic> json) {
        return this;
    }

    Map<String, dynamic> toJson() => {};
    getTypeName() => "EmptyClass";
    TypeContext? context = _ctx;
}

class HelloInterface implements IConvertible
{
    IPoco? poco;
    IEmptyInterface? emptyInterface;
    EmptyClass? emptyClass;

    HelloInterface({this.poco,this.emptyInterface,this.emptyClass});
    HelloInterface.fromJson(Map<String, dynamic> json) { fromMap(json); }

    fromMap(Map<String, dynamic> json) {
        poco = JsonConverters.fromJson(json['poco'],'IPoco',context!);
        emptyInterface = JsonConverters.fromJson(json['emptyInterface'],'IEmptyInterface',context!);
        emptyClass = JsonConverters.fromJson(json['emptyClass'],'EmptyClass',context!);
        return this;
    }

    Map<String, dynamic> toJson() => {
        'poco': JsonConverters.toJson(poco,'IPoco',context!),
        'emptyInterface': JsonConverters.toJson(emptyInterface,'IEmptyInterface',context!),
        'emptyClass': JsonConverters.toJson(emptyClass,'EmptyClass',context!)
    };

    getTypeName() => "HelloInterface";
    TypeContext? context = _ctx;
}

TypeContext _ctx = TypeContext(library: 'test.servicestack.net', types: <String, TypeInfo> {
    'IPoco': TypeInfo(TypeOf.Interface),
    'IEmptyInterface': TypeInfo(TypeOf.Interface),
    'EmptyClass': TypeInfo(TypeOf.Class, create:() => EmptyClass()),
    'HelloInterface': TypeInfo(TypeOf.Class, create:() => HelloInterface()),
});

Dart HelloInterface DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .xml suffix or ?format=xml

HTTP + XML

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

POST /xml/oneway/HelloInterface HTTP/1.1 
Host: test.servicestack.net 
Accept: application/xml
Content-Type: application/xml
Content-Length: length

<HelloInterface xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Test.ServiceModel">
  <EmptyClass />
  <EmptyInterface i:nil="true" />
  <Poco i:nil="true" />
</HelloInterface>