Thursday, November 26, 2020

Web API Tutorials With Examples

 

Lesson 1.What is Web API?

ASP.NET Web API is a framework for building HTTP services that can be accessed from any client including browsers and mobile devices. It is an ideal platform for building RESTful applications on the .NET Framework.

The ASP.NET Web API is an extensible framework for building HTTP based services that can be accessed in different applications on different platforms such as web, windows, mobile, etc. It works more or less the same way as ASP.NET MVC web application except that it sends data as a response instead of Html view. It is like a web service or WCF service but the exception is that it only supports HTTP protocol.





ASP.NET Web API Characteristics

  1. ASP.NET Web API is an ideal platform for building RESTful services.
  2. ASP.NET Web API is built on top of ASP.NET and supports ASP.NET request/response pipeline
  3. ASP.NET Web API maps HTTP verbs to method names.
  4. ASP.NET Web API supports different formats of response data. Built-in support for JSON, XML, BSON format.
  5. ASP.NET Web API can be hosted in IIS, Self-hosted, or other web servers that support .NET 4.0+.
  6. ASP.NET Web API framework includes a new HttpClient to communicate with the Web API server. HttpClient can be used in ASP.MVC server side, Windows Form application, Console application, or other apps.

ASP.NET Web API Versions

Web API VersionSupported .NET FrameworkCoincides withSupported in
Web API 1.0.NET Framework 4.0ASP.NET MVC 4VS 2010
Web API 2 - Current.NET Framework 4.5ASP.NET MVC 5VS 2012, 2013

ASP.NET Web API vs WCF

Web APIWCF
Open source and ships with .NET framework.Ships with .NET framework
Supports only HTTP protocol.Supports HTTP, TCP, UDP and custom transport protocol.
Maps http verbs to methodsUses attributes based programming model.
Uses routing and controller concept similar to ASP.NET MVC.Uses Service, Operation and Data contracts.
Does not support Reliable Messaging and transaction.Supports Reliable Messaging and Transactions.
Web API can be configured using HttpConfiguration class but not in web.config.Uses web.config and attributes to configure a service.
Ideal for building RESTful services.Supports RESTful services but with limitations.

When to choose WCF?

  1. Choose WCF if you use .NET Framework 3.5. Web API does not support .NET 3.5 or below.
  2. Choose WCF if your service needs to support multiple protocols such as HTTP, TCP, Named pipe.
  3. Choose WCF if you want to build a  service with WS-* standards like Reliable Messaging, Transactions, Message Security.
  4. Choose WCF if you want to use Request-Reply, One Way, and Duplex message exchange patterns.

When to choose ASP.NET Web API?

  1. Choose Web API if you are using .NET Framework 4.0 or above.
  2. Choose Web API if you want to build a service that supports only HTTP protocol.
  3. Choose Web API to build RESTful HTTP based services.
  4. Choose Web API if you are familiar with ASP.NET MVC.

Tuesday, November 24, 2020

Aspose Words for .NET



Aspose Words for .NET

·       Create, manipulate, render or convert Word files to multiple formats as well as generate reports without depending on any external software.

Aspose.Words for .NET is an advanced document processing API to perform a wide range of management and manipulation tasks.

API supports to generate, modify, convert, render and print files without utilizing Microsoft Word directly within cross-platform applications.

Moreover, API supports all the popular formats as well as allows exporting or converting Word files to fixed-layout and most commonly used image/multimedia formats.

By integrating API, some of the basic tasks developers can perform such as designing of fully-featured Microsoft Word reports having standard mail merge fields, reliable conversion between several popular formats, high fidelity rendering of pages, formatting of all document elements and more.

A Word Document Processing API that allows the developers to work with Microsoft Word® documents without needing Office Automation.

 

Advanced .NET Word API Features

·         Perform mail merge & generate reports

·         Insert formatted text, paragraphs, images, and tables

·         Fill tables using data from the database as well as create and modify table styles

·         Create mailing labels

·         Move sections between files

·         Mail merge data from multiple tables

·         Add watermark to document

·         Format date and numeric fields during mail merge

·         Join and split files

·         Encrypt documents as well as Load encrypted files

·         Find and replace text, enumerate over document content

·         Preserve or extract OLE objects and ActiveX controls

·         Preserve or remove VBA macros

·         Preserve VBA macros' digital signature

·         Detect digital signatures

·         Insert HTML contents

·         Interconvert file format

·         Add a bookmark at a deep level

·         Convert EquationXML to Office Math

·         Nested reports are supported by LINQ reporting engine

·         Create snip corner rectangle

·         Save the resources of MHTML document using the "Content-Id" URL Scheme

·         Show or hide comments in fixed file format

·         Show revisions in balloons

Popular File Format Conversion 

API allows quick, reliable & high-quality conversion from any supported file format to another with just two lines of code. It is that simple!

Save the document in different formats - C#

// load the file to be converted
var wrdf = new Aspose.Words.Document(dir + "template.doc");
// save in different formats
wrdf.Save(dir + "output.docx", Aspose.Words.SaveFormat.Docx);
wrdf.Save(dir + "output.pdf", Aspose.Words.SaveFormat.Pdf);
wrdf.Save(dir + "output.html", Aspose.Words.SaveFormat.Html);

 

 Render, Print or View Word Files

Aspose.Words for .NET has its own rendering engine specially designed for rendering & printing with the highest of fidelity to the Microsoft Word. Using this feature, developers can render (draw) any page onto a .NET Graphics object while setting the size and zoom level to create thumbnails for displaying images in the browser. Moreover, API is fully integrated with the .NET printing infrastructure and have the ability to completely customize the process, so that developers can easily print or preview documents within their own applications

Few of the rendering capabilities that API can perform

  • Render pages or full documents to PDF, XPS or SWF.
  • Document pages to images including but limited to PNG, EMF, JPEG, GIF.
  • Individual document shapes into raster or vector images.
  • Render pages or shapes to a .NET Graphics object with transforms.

Programming with Document Object Model

Aspose.Words for .NET allow you to create, build, and modify documents - including document formatting with an intuitive document object model that consists of over 100 classes. Some of the manipulations feature that API can perform

  • Manipulate all elements including but not limited to sections, headers, footers, paragraphs, lists, tables, text, fields, and much more.
  • Specify detailed formatting for any element including shapes, text boxes, images, OLE objects, and controls.
  • API can easily deal complex and deeply nested expressions containing IF blocks, formulas, and other fields.
  • Provides utility features such as joining or splitting, copying fragments between documents, protecting and unprotecting files, and a lot more.

Reporting & Mail Merge

Aspose.Words for .NET provides LINQ Reporting Engine to generate documents based upon template documents and data from different sources including databases, XML, JSON, OData, objects of custom CLR types, external documents, and more out of the box. API's Reporting Engine supports

  • Repeatable and conditional document blocks.
  • Dynamically generated charts and images.
  • Insertion of outer documents and HTML blocks into a document.
  • Various types of data sources for the creation of a single file.
  • Built-in support of data relations.
  • WYSIWYG generated file as of the corresponding template.

Additionally, developers can use API's extended syntax for mail merge fields to perform more complex operations during mail merge operations such as inserting images or repeatable regions. The data to drive your reports or mail merges can come from an ADO.NET data table, business objects, or from a completely custom data source.

Execute simple mail merge - C#

// load the template containing merged fields
var wfle = new Aspose.Words.Document(dir + "template.doc");
// fill the fields with user data
wfle.MailMerge.Execute(
    new string[] { "FullName", "Company", "Deparment", "City" },
    new object[] { "John Doe", "Aspose", "Sales", "London" });
// save the result
wfle.Save(dir + "merged.doc");


















Saturday, November 21, 2020

How to use POSTMAN to test Web API Services

 


How To Use Postman 


Let’s see how to use POSTMAN to send an HTTP request to our local ASP.NET Web API Services and check the response.


Step 1:  Download and install POSTMAN from Postman

Step 2: Once the Postman is successfully installed, open the Postman. It will look like the image shown below.

how to use POSTMAN to test web API Services


GET Request using Postman:

Select the HTTP Method as “GET” and enter the URL of your Web API as shown in the below image.

GET Request using Postman

Once you click on the Send button, an HTTP request is sent to the provided URL. The response coming from the Web API Server is displayed in the below image.

how to test Get Request Using POSTMAN

As you can see in the above image, the HTTP response shows data and response status. Thus, you can also use Postman to test your Web API.

POST Request using Postman:
  1. Choose the HTTP verb as POST
  2. Set the URL
  3. Set the Content-Type as application/json. To do this click on the Header tab and provide the key value as shown in the below image

POST Request using Postman

Next, we need to provide the string value that we want to add to the string array. We need to provide string value in the request body. To do so click on the body tab and provide the string value as shown below.

POST Request using Postman

Once you provided the string value in the request body, click on the send button which will issue a post request to the web API. In the same way, you can test the PUT and DELETE Requests. In this article series, we are going to use the tool Fiddler and Postman to test the services. 


NET Core Code Security, Authorization/Authentication, and code architecture

Complex NET Core interview questions (Code Security, Authorization/Authentication, and code architecture)  _________________________________...