如何在c#中使用WCF服务

时间:2017-03-17 07:16:38

标签: c# jquery html5 wcf c#-4.0

export function fetchUsers () {
    return {
        type: 'FETCH_USER',
        payload: axios.get('./users.json').then( (response) => 
        console.log(response.data) )
    };
}

当我在文本中输入ifsc而不是使用c#中的wcf服务验证ifsc时。

IFSC CODE在json中

我想通过API验证ifsc。

api url: /** * Relay is just an observable which subscribe an observer, but it wont unsubscribe once emit the items. So the pipeline keep open * It should return 1,2,3,4,5 for first observer and just 3, 4, 5 fot the second observer since default relay emit last emitted item, * and all the next items passed to the pipeline. */ @Test public void testRelay() throws InterruptedException { BehaviorRelay<String> relay = BehaviorRelay.create("default"); relay.subscribe(result -> System.out.println("Observer1:" + result)); relay.call("1"); relay.call("2"); relay.call("3"); relay.subscribe(result -> System.out.println("Observer2:" + result)); relay.call("4"); relay.call("5"); }

并参考ref:https://github.com/mangrep/ifsc-rest-api

我想从WCF服务获得响应,并且如果它比呼叫成功响应或无效呼叫失败响应那么将获得响应。

2 个答案:

答案 0 :(得分:1)

 public class ResponseData
    {
        public string status { get; set; }
        public string message { get; set; }
    }
    public ResponseData CheckIFSCCodeValid(string IFSCcode)
    {

        WebClient client1 = new WebClient();
        string jsonString = client1.DownloadString("http://api.techm.co.in/api/v1/ifsc/"+ IFSCcode);
        ResponseData responseData = new ResponseData();
        responseData = JsonConvert.DeserializeObject<ResponseData>(jsonString);
        return responseData;
    }

像这样调用方法

 ResponseData responseData = CheckIFSCCodeValid("SBIN0011050");
        if (responseData.status == "success")
        {
            //IFSC code is valid
        }
        else
        {
            ////IFSC code is invalid
        }

答案 1 :(得分:-1)

[的WebMethod]

public static string getifsccode(string id)
{
    string url = @"http://api.techm.co.in/api/v1/ifsc/" + id;
    WebClient webClient = new WebClient();
    string json = webClient.DownloadString(url);
    return json;
}