ServiceStack - Post Files Async using JsonServiceClient - post

I've trying to POST a single file from one service to another as a stream using an IServiceClient (I'm using the JsonServiceClient). I can achieve this by using code similar to:
using (IServiceClient serviceClient = new JsonServiceClient(myBaseUrl)
serviceClient.PostFile<TResponse>(relativeOrAbsoluteUrl, fileToUpload, fileName, contentType);
I see from an old SO post that there is a JsonHttpClient that I can't seem to find anymore - gone in favour of the JsonServiceClient?. That had an equivalent async method to achieve the same thing as my code example, but I can't see any way to do this using ServiceStack in the latest version ServiceStack (6.1.x).
Is there a recommended (ServiceStack) way to do this which supports async/await, or do I need to roll my own implementation (only way I can think of doing this will be to use the HttpClient and specify a MultipartFormDataContent on the request)?

The recommended ServiceClient for .NET 6+ is to use is the JsonApiClient which has a number of APIs to Upload Files from C#.

Related

KeyVaultClient and KeyVaultCredentials not present in new SDKs

We were using KeyVaultClient and KeyVaultCredentials classes as provided in the SDK -
com.microsoft.azure
azure-keyvault
Recently got a warning that this library is deprecated and is divided into 3 libraries - azure-keyvault-security-certificates, azure-keyvault-security-secrets and azure-keyvault-security-keys but I could not find these classes in any of the libraries. Am I still supposed to use azure-keyvault for these classes?
Depending on what functionality of Key Vault you want to use, instead of a KeyVaultClient you would use a CertificateClient, KeyClient or SecretClient.
For example, you can instantiate a simple client the following way:
KeyClient keyClient = new KeyClientBuilder()
.vaultUrl("<your-key-vault-url>")
.credential(new DefaultAzureCredentialBuilder().build())
.buildClient();
There are many more methods you can use in a client builder to customize the resulting client.
As for a replacement for KeyVaultCredentials, client builders allow you to authenticate the client to be created via the credential() method, so you can choose the way that best fits your solution. For more information on the available credential types and their diffecences you can check the Azure Identity README.

Can I use Zebble for only UI and use Xamarin for everything else

I would like to use Zebble only for producing UI and all other things I would like to use Xamarin apis/custom http apis/local db or whatever it may be. Basically a UI project with zebble and other things will be in PCLs.
Will it be compatible? Could you please advice?
Yes you can. There is nothing in Zebble that prevents you from using the native APIs directly.
For custom http calls, I recommend using the HttpClient class which is by default available in all 3 platforms of a newly created Zebble project.
For Device APIs, you can of course use the standard API classes of each platform, but to save time and achieve 100% code reuse I strongly recommend using the http://zebble.net/docs/device-api. For example if you want o use the lamp (aka flash, led or torch) you can very easily implement that on all platforms with very little code code:
// Determines if a lamp feature is available on the device.
if (await Device.Torch.IsAvailable()) { ... }
// This will switch the lamp on.
await Device.Torch.TurnOn();
// This will switch the lamp off.
await Device.Torch.TurnOff();

Make available my swagger APIs to be read through swagger-ui (new swagger-node project)

I am using the Swagger Node project with Express 4 to build my apis. https://github.com/swagger-api/swagger-node
I can make my "swagger api" work, however I could not get expose my apis as JSON to be read by the Swagger-UI(https://github.com/swagger-api/swagger-ui).
How can I achieve it? I know that the previous version I need to use the following method:
swagger.configureSwaggerPaths("", "/api-docs", "");
But with the changes in the project, I dont what to call..
Ty
Maybe look into swagger-tools offered by Apigee-127, i believe this is the best module for node/swagger integration

How to pass data in body of a HttpConnection in blackberry

Actually I want to pass data in body of a httpconnection.
Using apache httpclient library in blackberry, integrated jar file in my project but getting compilation error while running my project.
Kindly updated me on the same.
I have not tried using Apache HttpClient lib in a BB project before, because I did not for a moment think it would work...
In short, you need the code to be compatible with J2ME, and compilable using the RIM tool chain. And then we get into other problems....
First of, be aware that networking in BlackBerry is NOT as straightforward as one might wish.
Have a look at this video for the back ground theory: Networking Transports on the BB Platform
Ok, then for some code (I assume here you already went through the trouble of obtaining an HttpConnection):
byte [] bodyBytes = getBodyBytesFromSomewhere();
OutputStream out = httpConnection.openOutputStream();
out.write(bodyBytes);
out.flush();
out.close();//If you are done, which I'm guessing you are
The above code is of course very simplistic, and completely ignores all the many, many errors that will occur during network IO.
I would suggest you also look at this API,this forum entry,and this one. OS6.0 also introduced a new HTTP Connection API - can't find a link for that right now (sorry!)

Getting Authentication working on Mono for Android with servicestack

I've got ServiceStack working nicely on the server and with a Windows test client, and now need to get it working in my Mono For Android application.
I've downloaded the following:
ServiceStack.Common.dll
ServiceStack.Interfaces.dll
ServiceStack.Text.dll
from the github tip, and added references to these in my Mono for Android project.
However, we need to use authentication, so need the ServiceStack.ServiceInterface.Web namespace to be available for the client, so I can do the following:
var c = new JsonServiceClient("http://localhost:53434");
var authResponse = c.Get(new Auth { UserName = "myusername", Password = "password", RememberMe = true });
Looking at my working test client, Auth is defined in ServiceStack.ServiceInterface.dll, so presumably I need to get hold of this DLL, or its source and compile it in my project.
Am I on the right lines here, or is there a simpler way to set things up? I've searched around but can't find a good resource on how to use ServiceStack with Mono For Android - if there is one, please feel free to point me to it!
I note this StackOverflow indicates I'm on the right lines - all I might need is ServiceStack.ServiceInterface.dll compiled for Mono For Android.
James
You shouldn't have to compile the server ServiceStack.ServiceInterface.dll for use in any client library as there is a copy of the Auth DTOs is also available in the ServiceStack.Common.dll client library at ServiceStack.Common.ServiceClient.Web.AuthDtos.cs.
This is possible since both server and client DTOs generate the same wireformat.

Resources