Posts

Showing posts from March, 2017

Azure Service Bus: Serialization operation failed due to unsupported type

When trying to add an object property to my Service Bus Queue, I encountered the following error: "Serialization operation failed due to unsupported type RichardLeeman.Model.MyObject." So I added the  [Serializable] annotation to the class, but to no avail. The issue seems to be that the property bag only likes simple types like int or string. So, my simple fix was to convert the class to JSON and put that in the bus. I used  System.Web.Script.Serialization.JavaScriptSerializer  to convert the object and placed the resulting string in the property bag. var client = QueueClient.CreateFromConnectionString(SERVICE_BUS_CNN, "myqueue"); var json = new JavaScriptSerializer().Serialize(myObjectInstance); var message = new BrokeredMessage("my test message"); message.Properties.Add(new KeyValuePair<string, object>("MyObjectProperty",json)); client.Send(message);

Swagger: How do I add custom return codes to my Web API?

Image
Swagger is great tool to document APIs, The standard return codes (200 - OK) do not always give enough detail about the endpoint. Fortunately, there are some simple annotations that can be added to give a better description about the return code. using Swashbuckle.Swagger.Annotations; using System.Web.Http; namespace MyNameSpace {     public class MyAPIController : ApiController     {         [HttpGet]         [Route("api/my_custom_api_route")]         [SwaggerResponse(System.Net.HttpStatusCode.OK, "All good here, thanks for asking")]         [SwaggerResponse(601, "foo message")]         public bool MyAPI()         {             return true;         }     } } The result is as follows:

Azure: How do I delete my function?

Image
I have been playing with Azure functions (which are great), but there does not seem to be an intuitive way to delete them. The first option (which requires forethought) is to create its own Resource Group (with the associated storage accounts) and delete the RG. Easy - if you knew it was coming and planned for it. The other option is go into 'Function App Settings'  -> 'Go to App Service Settings'. You can then delete the app.

Azure Function: Call a web service and return the result as a class

My current project is using Azure Functions as action triggers. Thanks to some nifty work from the Visual Studio team, we now have a local development environment. The following POC function will call a Web API (configured through API Management) and convert the resultant JSON into a class object. 1. Create a 'Model' solution that stores the class to be used. I called my MyModel. My class is called ApiResult. namespace MyModel {     public class ApiResult     {         public string Message { get; set; }     } } 2. Create an API to invoke using MyModel; using System.Web.Http; namespace MyControllers {     public class MyController : ApiController     {         [System.Web.Http.HttpGet]         [System.Web.Http.Route("api/myapiendpoint")]         public ApiResult ValidateFile()         {             return new ApiResult()             {                 Message = "Success!"             };         }     } } 3. Copy the MyMo

Azure SQL Database: Cannot connect to XXXXX.database.windows.net PART 2

My first attempt to resolve this issue (see  this  post), I was able to get past the first barrier. However, for some reason, my SSO credentials were not working. My account was configured as the system administrator account, but I could not authenticate. Then I remember that my user password was different AT THE TIME THE SQL SERVER INSTANCE WAS CREATED. I was successfully able to connect using SQL Authentication with my username and the OLD PASSWORD.

Azure SQL Database: Cannot connect to XXXXX.database.windows.net

Image
While creating an Azure POC, I create a new SQL Database and tried to connect via the online tools. I then received the following message: Fortunately, the resolution is very simple. Open the database and navigate to the Firewall Settings at the top of the Overview blade. Select 'Add client IP' to resolve the problem.