수색…


소개

여기서 우리는 Pro-grammatically ASP.Net C #에서 웹 서비스를 사용하고 호출하는 것을 볼 것입니다. 목적을 위해 많은 기능을 제공하는 ddl을 다운로드해야합니다. ImportJson을 https://drive.google.com/open?id=0B-2bGoHKJvnOckdPUHVjdFZTcFU 에서 다운로드 하십시오.

이 기사는 ASP.NET C # 웹 서비스 / 웹 API 서비스를 사용하여 프로젝트를 개발하려는 사용자에게 매우 유용합니다. 이 기사는 Xamarin을 사용하여 프로젝트를 개발하는 사람들에게도 유용합니다 : Mobile App Development

비고

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;
    }

데이터 POST / POST 메서드를 사용하여 웹 서비스 호출

        /// <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;
    }

데이터 POST / POST 메소드로 웹 서비스 호출 (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

    }

목록 형식 또는 DataTable 형식의 웹 서비스 출력

    /// <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 또는 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);;
                     }


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow