Monday, October 24, 2016
Tuesday, October 4, 2016
How to Query REST API ?
> domain\username:password must be authorize to query to the REST API.
> For POST HttpRequest is content type and use charset=utf-8 to convert.
> For GET HttpRequest is Accept
POST:
Uri address = new Uri(@"https://xx.xx.xx.xx:xxxx/abc/config/anything/");
HttpWebRequest request = WebRequest.CreateDefault(address) as HttpWebRequest;
request.Method = "POST";
request.Headers["Authorization"] = "Basic " +
Convert.ToBase64String(Encoding.Default.GetBytes(@"domain\username:password"));
request.ContentType = "application/vnd.com.cisco.ise.identity.guestuser.2.0+xml; charset=utf-8";
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
//Inserting data
string data="xml data";
byte[] bytes = Encoding.UTF8.GetBytes(data);
request.ContentLength = bytes.Length;
using (Stream requestStream = request.GetRequestStream())
{
// Send the data.
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
}
Get By Name:
string name="";
Uri address = new Uri(@"https://xx.xx.xx.xx:xxxx/abc/config/anything/name/" +name +" ");
HttpWebRequest request = WebRequest.CreateDefault(address) as HttpWebRequest;
request.Method = "GET";
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(@"domain\username:password"));
request.Accept = "application/vnd.com.cisco.ise.identity.guestuser.2.0+xml";
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string s = reader.ReadToEnd();
}
Get All:
Uri address = new Uri(@"https://xx.xx.xx.xx:xxxx/abc/config/anything/ ");
HttpWebRequest request = WebRequest.CreateDefault(address) as HttpWebRequest;
request.Method = "GET";
request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(@"domain\username:password"));
request.Accept = "application/vnd.com.cisco.ise.identity.guestuser.2.0+xml";
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string s = reader.ReadToEnd();
}
Monday, October 3, 2016
How to create a web service ?
Open Visual Studio create new web site. File > New >Website
Add an item as Web Service to the project. Webservice.asmx
Now create some web methods
[WebMethod]
public string GetbyId(string name){}
if the response is in Custom Created Class then return that class object as below
[WebMethod]
[System.Xml.Serialization.XmlInclude(typeof(Students))]
public string GetAll(string name){}
Public Class Student
{
public string name{get; set;}
public string rollnumber{get; set;}
}
Step 2: Publishing the Web Service
To publish the web service the procedure is same as publishing the website because as we created the Web Service under Web Site Project.
Sunday, September 18, 2016
FusionChart with C#,Linq,EntiyFramework,Asp .NET,Xml Best Way.
-------------------------------------------Page Html-------------------------------------------------------
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>FusionChart Test</title
<script src="FusionChart/fusioncharts.js"
type="text/javascript"></script>
<script src="FusionChart/fusioncharts.charts.js"
type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Literal ID="Literal1"
runat="server"></asp:Literal>
</div>
</form>
</body>
</html>
-------------------------------------------------------------------------------------
Step2:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using InfoSoftGlobal;
public partial class FusionChartTest
: System.Web.UI.Page
{
Entities ctx = new
Entities();
protected void
Page_Load(object sender, EventArgs e)
{
---------------Getting the required
result and save into class-----------------------
var model = ctx.Table
.Where(o=>o.DateTime.Value.Year==DateTime.Now.Year)
.GroupBy(o => new
{
Month =(int) o.DateTime.Value.Month,
Year = o.DateTime.Value.Year
})
.Select(g => new SomeClass
{
Month = g.Key.Month,
Year = g.Key.Year,
Value = g.Count()
})
.OrderByDescending(a => a.Year)
.ThenByDescending(a => a.Month)
.ToList();
List<SomeClass>
list=new List<SomeClass>(model);
-------------------------------------------------------------------------------------
--------------------------Forming the
xml to display as chart------------------------
StringBuilder xmlData = new
StringBuilder();
xmlData.Append("<chart
caption='Monthly Unit Sales' xAxisName='Month' yAxisName='Units' showValues='0'
formatNumberScale='0' showBorder='1'>");
foreach (var item in list)
{
xmlData.AppendFormat("<set
label='{0}' value='{1}' />", item.Month + "," + item.Year, item.Value);
}
xmlData.Append ( "</chart>");
Literal1.Text = InfoSoftGlobal.FusionCharts.RenderChart("FusionChart/Charts/line.swf", "", xmlData.ToString(), "browser_share", "640", "340",
false, true);
}
-------------------------------------------------------------------------------------
}
--------------------------------Custom
Class to Save the Result----------------------
public class SomeClass
{
public int Month { get; set; }
public int Year { get; set; }
public int Value { get; set; }
}
-------------------------------------------------------------------------------------
Thursday, March 17, 2016
How to Replace 0 with 1 in Linq to Entity ? (Linq if-statement)
Description:
first it is asking column1==0 ? if true 1 will assign to column1 for assignment here use : operator
Basic Example:
column1= = 0 ? 1 : column1
Real Example:
let value1 = Grp.Count(x => x.Column1== "value") == 0 ? 1 : Grp.Count(x => x.hours_to_resolve <= 3 && x.Column1== "value")
/
Convert.ToDouble(Grp.Count(x => x.Column1== "value") == 0 ? 1 : Grp.Count(x => x.Column1== "value"))
Subscribe to:
Posts (Atom)
Secure you Asp .NET by Web.config & Global.ascx?
Add to Global.ascx protected void Application_BeginRequest(object sender,EventArgs e) { //to remove x frame Resp...
-
Step by Step procedure to Attest your degree for Saudi Arabia. In order to change your profession on the Iqama, you need to a...
-
Comparison of Data Access and Entity Framework 5 Feature Data Access Entity Framework 5.0 Vis...