0

I have Skype web API which can be called and used inside javascript. Now, I have created a simple C#.Net console application and want to use the API.

So, Does c# has any API using which we can run javascript and get the output in json or xml or any other standard format.

Thanks in advance.

2 Answers 2

2

You don't need to run Javascript inside your C# code. .NET has its own set of functionality to get the information.

The System.Net.WebClient class has a .DownloadString() method that you can use to get the same information from the Skype API as you would in your JavaScript code.

Take that string that you receive from there and use Newtonsoft's JSON DLL (available through NuGet) to turn that string into a JSON object that you can get all of the information from.

Here is an example of the code that I used to do this in one of my projects, modified for generality. For reference, the DLL's you'll need to add usings for are System.Net, and Newtonsoft.Json.Linq.

private static GetData(string urlParameter) {
    string response = string.Empty; // This will be the data that is returned.
    string url  = "http://skype.api.com/someCall?param={0}"; // The API URL you want to call.

    using (var client = new WebClient()) {
        // This will get the data from your API call.
        response = client.DownloadString(string.Format(url, urlParameter));
    }

    JObject obj = null; // This is the Newtonsoft object.

    try {
        obj = JObject.Parse(response);

        // Continue on processing the data as need be.
    }
    catch {
        // Always be prepared for exceptions
    }
Sign up to request clarification or add additional context in comments.

4 Comments

Hi Krillgar, Thanks for the response. I was in a myth that this function(DownloadString) simply download data given a webpage. I wasn't knowing it can return the result given a web API with proper input parameter. Thanks for clearing my doubt. Let me try and get back to you. Thank you very much..
If you gave it a url that returned HTML, it would give you the HTML in the response object. If you go to your browser and type in your web API with the parameter, it will fill your browser window with the JSON object. Fundamentally, it doesn't matter to anything whether the URL you enter returns JSON, HTML, or even just a plain string. It's the headers of the response that determine how the browser interprets what it is given. You could even use DownloadString() with an image response, and I wouldn't be surprised if the response was populated with the binary of the image. I haven't tried
Any luck with this? If it was able to work for you, please mark it as an answer for anyone else who might come across this.
thanks for reminding me i will definitely try this weekend sorry for not trying soon after the solution provided by you. Quite busy whole week with office work :( Once it work for me i will certainly mark this as answer as you said. Thanks
0

The API you are attempting to call is used by the client through their web browser. It makes no sense to attempt to integrate with it using C# on the server side; it'll never work because it won't be able to talk to Skype running on the user's computer. If you're writing a web app in C# then you need to make the Skype API calls in client-side JS running in the user's browser. If you're not writing a web app then I have no idea what you're trying to accomplish, but it's not going to work.

1 Comment

There are ways to retrieve the data in C# code without going through a client-side browser. See my answer for how to do that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.