Why Using a JSON service returns exceptions and errors?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    Why Using a JSON service returns exceptions and errors?

    I'm familiar with SOAP services and how they're used, but I recently was given a service URL to a JSON service and was wondering if I could use it in my C# project. I've tried adding a service reference to the URL:

    http://www.bungie.net/stats/reach/ReachJson.svc

    And it does find the service, along with two methods. I named the service reference "ReachJson" , and added a using line to my code:

    using WindowsFormsApp lication2.Reach Json;

    Then I tried creating a client in two different ways. First:

    ReachJsonClient client = new ReachJsonClient ();

    With this I get the following error on the line where I create the client:

    Could not find default endpoint element that references contract 'ReachJson.IRea chJson' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
    Then I tried this:

    static ReachJsonClient client = new ReachJsonClient ();

    And got this error on my Application.Run () line in program.cs:

    The type initializer for 'WindowsFormsAp plication2.Form 1' threw an exception.
    Is there anything I can do to get this working, or would that all be on the side of the service host?
  • Aimee Bailey
    Recognized Expert New Member
    • Apr 2010
    • 197

    #2
    have you tried sticking the url in your web browser :)

    ---

    scrub that last bit, did a bit of digging and apparently you need to provide an API key from bungie every time you want to use the service, so to grab it you need to create an account at bungie (you will need a pro account), then visit http://www.bungie.net/Account/reachapikey.aspx to grab your key, the key needs to be created everytime you make a service call, so i suggest making it a const in your app.

    heres a little app i made to test it...

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using ConsoleApplication1.Json;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                const string apiKey = "key_goes_here";
                ReachApiJsonClient client = new ReachApiJsonClient(apiKey);
    
                MetaDataResponse metaData = client.GetGameMetadata(apiKey);
    
                if (metaData.status == 0)
                {
                    if (metaData.Data != null)
                    {
                        Dictionary<int, Weapon> di = metaData.Data.AllWeaponsById;
                        for (int x = 0; x < di.Keys.Count; x++)
                        {
                            Console.WriteLine("{0} is {1}.",x,di[x].Name);
                        }
                    }
                }
            }
        }
    }
    Also, there is a great rescource at http://www.haloreachapi.net for more information on this subject.

    Comment

    • HaLo2FrEeEk
      Contributor
      • Feb 2007
      • 404

      #3
      Maybe I should have explained a little better. I know all about the API, I've written quite a few programs using it in both C# and PHP. That's not what I'm having an issue with. There are two endpoints: JSON and SOAP. The SOAP endpoint can easily be used in Visual Studio, just add a service reference to the SOAP service:



      However, that's not what I was asking for help with. Take a look back at the first post, at the URL:



      This is a different, completely publically-accessible API that helps with AJAX loading for certain pages on the site. This API has 2 methods: GetScreenshotTo oltip() and GetGameViewerDa ta() neither of which require a key. In your example program you used the actual Reach API (so you couldn't run it since you don't have a key); try modifying it with a service reference to this URL:



      You'll actually be able to run that since it doesn't require a key. Let me know if it works for you, because it doesn't for me, and there is no SOAP version of this service available like there is the actual API.

      And I apologize for the confusion. I know all about the Reach API, I've been developing with it for months now. I've written quite a few programs and done some PHP-based development for my site using it. I have an API key, I've played Halo for years, I've been registered at Bungie for years, and I'm one of the only really active people in the private Reach API forum on Bungie.net. I hope you're not put out by this, I should have explained it.

      Comment

      Working...