1
votes

I am testing the api created using ServiceStack using SoapUI and when I try to send the required DataMember thru headers, the api returns the correct values. When I try to send the required DataMember thru Body, I am getting the below error... Please help

Request sent through the body

<GetProductDetailsReq>
<AToken>ck0b0YYBPkrnVF/j6e16DUPzxLX2SMCXewoR4T</AToken>
</GetProductDetailsReq>

POST http://localhost/ServiceStackAPI/GetProductDetails HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/xml
Accept: application/xml
Content-Length: 777
Host: localhost
Proxy-Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

Response Status

Error Code SerializationException Message Could not deserialize 'application/xml' request using ServiceModel.DTO.GetProductDetailsReq' Error: System.Runtime.Serialization.SerializationException: Error in line 1 position 66. Expecting element 'GetProductDetailsReq' from namespace ''.. Encountered 'Element' with name 'GetProductDetailsReq', namespace 'http://schemas.servicestack.net/types'. at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName, DataContractResolver dataContractResolver) at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName, DataContractResolver dataContractResolver) at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(XmlDictionaryReader reader) at System.Runtime.Serialization.XmlObjectSerializer.ReadObject(Stream stream) at ServiceStack.Text.XmlSerializer.DeserializeFromStream(Type type, Stream stream) at ServiceStack.WebHost.Endpoints.Support.EndpointHandlerBase.CreateContentTypeRequest(IHttpRequest httpReq, Type requestType, String contentType) Stack Trace at ServiceStack.WebHost.Endpoints.Support.EndpointHandlerBase.CreateContentTypeRequest(IHttpRequest httpReq, Type requestType, String contentType) at ServiceStack.WebHost.Endpoints.RestHandler.GetRequest(IHttpRequest httpReq, IRestPath restPath) at ServiceStack.WebHost.Endpoints.RestHandler.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, String operationName)

1

1 Answers

0
votes

Check the SOAP Limitations to ensure you're creating Services that can be sent in SOAP, i.e. If the Request DTO is called GetProductDetails then it must return a Response DTO called GetProductDetailsResponse. Also you need to ensure your DTO's have [DataContract] on all types and [DataMember] on all public properties and that your DTO's are in a single namespace.

The other issue with this request is that you're using the SOAP requests to wrong endpoint address. i.e. The SOAP endpoint is either /soap11 or /soap12. In the above example it's attempting to send it to the /GetProductDetails custom HTTP route, when for SOAP it needs to be either /soap11 or soap12.

If you did just want to just send XML over HTTP then you should just send the raw XML payload which you can find out what it looks like by serializing the Request DTO, e.g:

string requestXml = new GetProductDetails { ... }.ToXml();

Which you can easily send with HTTP Utils:

var responseXml = "http://localhost/ServiceStackAPI/GetProductDetails"
    .PostXmlToUrl(xmlRequest);

var responseDto = responseXml.FromXml<GetProductDetailsResponse>();

Assuming you have a [Route("/GetProductDetails")] defined on the GetProductDetails Request DTO.