I have an integration test which spins up an apphost. I can send a request to it using the .net core HttpClient returns ok, but using JsonServiceClient throws a not found exception. Both clients are initialized to the same base url (http://localhost/) and are requesting the same uri (/metadata).
I printout the requests from both clients and have tried but I do not understand why its not working:
JsonServiceClient Initialization
public JsonServiceClient CreateJsonServiceClient(ITestOutputHelper testOutputHelper)
{
var client = new JsonServiceClient(this.ClientOptions.BaseAddress.ToString());
client.RequestFilter = req =>
testOutputHelper.WriteLine($"REQ: {req.Method} {req.RequestUri}");
client.ResponseFilter = res =>
testOutputHelper.WriteLine($"RSP: {res.StatusCode} {res.ResponseUri}");
return client;
}
HttpClient initialization
this.httpClient =
appHostFixture.CreateDefaultClient(new LoggingHandler(new HttpClientHandler(), testOutputHelper));
The test
[Fact]
public async Task GetWithDefaultValuesShouldReturnAuthorizedPrices()
{
var responseHttp = await this.httpClient.GetAsync(new Uri("/metadata", UriKind.Relative)).ConfigureAwait(false);
var responseContent = await responseHttp.Content.ReadAsStringAsync().ConfigureAwait(false);
var metadata = this.client.Get("/metadata");
var metadataString = metadata.ReadToEnd();
metadataString.PrintDump();
}
Output
BokaMera.Api.IntegrationTest.Tests.ServiceStack.ServicePriceServiceTests.GetWithDefaultValuesShouldReturnAuthorizedPrices
ServiceStack.WebServiceException : Not Found
at ServiceStack.ServiceClientBase.ThrowWebServiceException[TResponse](Exception ex, String requestUri) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Client\ServiceClientBase.cs:line 896
at ServiceStack.ServiceClientBase.ThrowResponseTypeException[TResponse](Object request, Exception ex, String requestUri) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Client\ServiceClientBase.cs:line 831
at ServiceStack.ServiceClientBase.HandleResponseException[TResponse](Exception ex, Object request, String requestUri, Func`1 createWebRequest, Func`2 getResponse, TResponse& response) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Client\ServiceClientBase.cs:line 782
at ServiceStack.ServiceClientBase.Send[TResponse](String httpMethod, String relativeOrAbsoluteUrl, Object request) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Client\ServiceClientBase.cs:line 1360
at ServiceStack.ServiceClientBase.Get(String relativeOrAbsoluteUrl) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack.Client\ServiceClientBase.cs:line 1417
at BokaMera.Api.IntegrationTest.Tests.ServiceStack.ServicePriceServiceTests.GetWithDefaultValuesShouldReturnAuthorizedPrices() in D:\bokamera\src\bokamera-api-v2\Tests\BokaMera.Api.IntegrationTest\Tests\ServiceStack\ServicePriceServiceTests.cs:line 77
--- End of stack trace from previous location where exception was thrown ---
Request:
Method: GET, RequestUri: 'http://localhost/metadata', Version: 1.1, Content: <null>, Headers:
{
}
Response:
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Request-Context: appId=
Set-Cookie: ss-pid=GAgqH1zIvIMkgOUsORRQ; expires=Sat, 21 Jul 2040 10:19:37 GMT; path=/; samesite=none; httponly
Set-Cookie: ss-id=KOavlRqM8ciDZPHpZ2uN; path=/; samesite=none; httponly
Content-Type: text/html; charset=utf-8
}
REQ: GET http://localhost/metadata
The order in the output is a bit wrong (exception comes first) but you can see that the httpclient succeeds but the jsonserviceclient fails, for the same url. Why?