A minor "bug" in get methods implementaion of serviceclientbase.cs

you might want to have a look at this modifed version of the get implementations in the serviceclientbase.cs

I noticed that in the get the request do not push down the requestdto, so the call to

(webrequestutils.cs)
public static Type GetErrorResponseDtoType(object request)
{
var hasResponseStatus = typeof(TResponse) is IHasResponseStatus
|| typeof(TResponse).GetPropertyInfo(“ResponseStatus”) != null;

        return hasResponseStatus ? typeof(TResponse) : GetErrorResponseDtoType(request);
    }

fails to infer the response dto from the request dto.

serviceclientbase.cs :

public abstract class ServiceClientBase : IServiceClient, IMessageProducer, IHasCookieContainer
{

public virtual void Get(IReturnVoid requestDto)
{
Get<byte[]>(requestDto.ToUrl(HttpMethods.Get, Format));
}

    public virtual HttpWebResponse Get(object requestDto)
    {
        return privateGet<HttpWebResponse>(requestDto.ToUrl(HttpMethods.Get, Format),requestDto);
    }

    public virtual HttpWebResponse Get(string relativeOrAbsoluteUrl)
    {
        return Get<HttpWebResponse>(relativeOrAbsoluteUrl);
    }

    public virtual TResponse Get<TResponse>(IReturn<TResponse> requestDto)
    {
				return privateGet<TResponse>(requestDto.ToUrl(HttpMethods.Get, Format), requestDto);
    }

    public virtual TResponse Get<TResponse>(object requestDto)
    {
				return privateGet<TResponse>(requestDto.ToUrl(HttpMethods.Get, Format), requestDto);
    }


			private TResponse privateGet<TResponse>(string relativeOrAbsoluteUrl,object requestDto)
			{
				return Send<TResponse>(HttpMethods.Get, relativeOrAbsoluteUrl, requestDto);
			}

    public virtual TResponse Get<TResponse>(string relativeOrAbsoluteUrl)
    {
        return Send<TResponse>(HttpMethods.Get, relativeOrAbsoluteUrl, null);
    }

This is kind of unreadable. Can you provide a concrete example of what the issue is? i.e. what combination Request/Response DTO and service client method has what issue?

Consider this test calling the same operation that raises and exception in its implementation:
If I call it with get method in WebServiceException.ResponseDto there is ServiceStack.ErrorResopnse ,
if I do a POST , WebServiceException.ResponseDto contains the OperationResponse

Note that the responsedto does not implement : IHasResponseStatus (since it cannot, because we implemented a custom response status with different properties, if I do implement IHasResponseStatus the issue disappear)

[Test]
public void TestMethod1()
{
	var f = new WebApplication1.ServiceModel.Hello();
	f.Name = "ciao";
	var t = new JsonServiceClient("http://localhost:26809/");
	try
	{
		var resp = t.Get(f);
	}
	catch (WebServiceException ex)
	{
		**//returns ServiceStack.ErrorResopnse**
		Debug.WriteLine(ex.ResponseDto.GetType().Name);
	}
	try {
		var resp = t.Post(f);
	}
	catch (WebServiceException ex)
	{
		**//returns HelloResponse**
		Debug.WriteLine(ex.ResponseDto.GetType().Name);
	}

}

As I said, in the previous post, the reason is that when calling a Get the requestdto is not send down to the “shared”

return Send<TResponse>(HttpMethods.Get, relativeOrAbsoluteUrl, requestDto); 

method.

For this reason when the request fails , the code enters into HandleResponseException
with a null request.
For this reason WebRequestUtils.GetErrorResponseDtoType(request); fails to resolve HelloResponse as the response dto for Hello … and so ServiceStack.ErrorResopnse is returned

Hope I explained the situation better now.
best reagards
enrico

I’ve added but had to revert this as it was a breaking change that broke a lot of tests since passing a Request DTO re-extended the query string with additional params from the request DTO.

Any other refactored solution to support this is too disruptive at this time so I’m going to leave the current behavior.