web-services
C # .net और Xamarin एप्लिकेशन डेवलपमेंट का उपयोग करके वेब सेवाओं को प्रोग्रामिक रूप से कॉल करना
खोज…
परिचय
यहां हम ASP.Net C # में प्रो-व्याकरणिक रूप से कॉल और वेब सेवाओं का उपयोग करते हुए देखेंगे। इस प्रयोजन के लिए आपको निम्नलिखित ddl को डाउनलोड करना होगा जो आपको कई कार्य प्रदान करता है। Https://jrive.google.com/open?id=0B-2bGoHKJvnOckdPUHVjdFZTcFU से ImportJson डाउनलोड करें
यह लेख आप में से उन लोगों के लिए बहुत उपयोगी है जो ASP.NET C # वेब सेवाओं / वेब एपीआई सेवाओं का उपयोग करके एक परियोजना विकसित करने जा रहे हैं। यह लेख उन लोगों के लिए भी उपयोगी है जो Xamarin: मोबाइल ऐप डेवलपमेंट का उपयोग करके एक प्रोजेक्ट विकसित कर रहे हैं
टिप्पणियों
आपको ImportJson dll और restsharp ddl का संदर्भ देना होगा। ImportJson यहां से डाउनलोड किया जा सकता https://drive.google.com/open?id=0B-2bGoHKJvnOckdPUHVjdFZTcFU और restsharp.dll इंटरनेट से मिलेगा
किसी भी सुझाव / संपर्क, akhandagale65@gmail.com पर ध्यान दें
कॉलिंग सिंपल GET मेथड
/// <summary>
/// Simple Get method
/// </summary>
/// <returns> Json formated data </returns>
public string GetJsonData1()
{
IOperations _Obj = ClsOperations.GetOperations();
string url = "http://1.2.3.4:1234/Services/rest/CallService/WebRequest/";
string jsonResult = _Obj.GetJsonResult(url);
return jsonResult;
}
डेटा पोस्ट / पोस्ट विधि के साथ वेब सेवा को कॉल करना
/// <summary>
/// Post Method with input parameter
/// </summary>
/// <returns> Json formated data </returns>
public string GetJsonData2()
{
IOperations _Obj = ClsOperations.GetOperations();
string url = "http://1.2.3.4:1234/Services/rest/CallService/WebRequest/";
Dictionary<string, object> objDec = new Dictionary<string, object>();
objDec.Add("@FirstParameter", "Value1");
objDec.Add("@SecondParameter", "Value2");
objDec.Add("@ThirdParameter", "Value3");
string jsonResult = _Obj.GetJsonResult(url, objDec);
return jsonResult;
}
डेटा पोस्ट / पोस्ट विधि के साथ वेब सेवा को कॉल करना (JSON प्रारूप में डेटा पोस्ट किया गया)
/// <summary>
/// Post Method with Input/ data to post in JSON format
/// </summary>
/// <returns> Json formated data </returns>
public string GetJsonData3()
{
IOperations _Obj = ClsOperations.GetOperations();
string url = "http://1.2.3.4:1234/Services/rest/CallService/WebRequest/";
string inputjson = "{\"@FirstParameter\": \"Value1\",\"@SecondParameter\": \"Value2\",\"@ThirdParameter\": \"Value3\"}";
string jsonResult = _Obj.GetJsonResult(url, null,inputjson );
return jsonResult;
}
IEnumerator ऑब्जेक्ट के रूप में आउटपुट के साथ वेब सेवा कॉल
/// <summary>
/// Post Method with Input/ data to post in JSON format Or you can send dictionary as shown in previous methods
/// </summary>
/// <returns> Json formated data </returns>
public void GetJsonData4()
{
IOperations _Obj = ClsOperations.GetOperations();
string url = "http://1.2.3.4:1234/Services/rest/CallService/WebRequest/";
string inputjson = "{\"@FirstParameter\": \"Value1\",\"@SecondParameter\": \"Value2\",\"@ThirdParameter\": \"Value3\"}";
string jsonResult = _Obj.GetJsonResult(url, null, inputjson);
IEnumerator objIEnumerator = _Obj.GetJsonEnumerableResult(jsonResult);
// you can perform further operations on it
}
वेब सेवा आउटपुट सूची प्रारूप या डेटाटेबल प्रारूप में
/// <summary>
/// Post Method with Input/ data to post in JSON format Or you can send dictionary as shown in previous methods
/// </summary>
/// <returns> Json formated data </returns>
public DataTable GetJsonData6()
{
IOperations _Obj = ClsOperations.GetOperations();
string url = "http://1.2.3.4:1234/Services/rest/CallService/WebRequest/";
string inputjson = "{\"@FirstParameter\": \"Value1\",\"@SecondParameter\": \"Value2\",\"@ThirdParameter\": \"Value3\"}";
IEnumerator objIEnumerator = _Obj.GetJsonEnumerableResult(url, null, inputjson);
// you can perform further operations on it
// If you want to convert it in Datatable / List
List<ClsMyPropertyClass> lst = new List<ClsMyPropertyClass>();
while (objIEnumerator.MoveNext())
{
lst.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<ClsLineEDoDetails>(objIEnumerator.Current.ToString()));
}
// Upto this you will get List , and you can perform operations on it
// Now if youu want result in datatable, here i written function for List to datatable conversion
return CommonServiceCall.ToDataTable(lst);
}
जबरदस्ती तरीके से GET OR POST करें
/* By Default if you send only url then automatically it will recognize as GET Method and if service having parameters with, Then automatically will convert to POST Method. But I observed some of the services having only URL but are POST Type. For the purpose you can forcefully make the method as you want. As bellow: */
/// <summary>
/// If you want make the service call GET OR POST forcefully then
/// </summary>
/// <returns> Json formated data </returns>
public void GetJsonData5()
{
IOperations _Obj = ClsOperations.GetOperations();
string url = "http://1.2.3.4:1234/Services/rest/CallService/WebRequest/";
string inputjson = "{\"@FirstParameter\": \"Value1\",\"@SecondParameter\": \"Value2\",\"@ThirdParameter\": \"Value3\"}";
string _result = _ Obj.GetJsonResult(url, null, inputjson, ServiceType.POST);;
}