473,396 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Why Using a JSON service returns exceptions and errors?

HaLo2FrEeEk
404 256MB
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 WindowsFormsApplication2.ReachJson;

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.IReachJson' 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 'WindowsFormsApplication2.Form1' 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?
Feb 1 '11 #1
2 2007
Aimee Bailey
197 Expert 100+
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...

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ConsoleApplication1.Json;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             const string apiKey = "key_goes_here";
  14.             ReachApiJsonClient client = new ReachApiJsonClient(apiKey);
  15.  
  16.             MetaDataResponse metaData = client.GetGameMetadata(apiKey);
  17.  
  18.             if (metaData.status == 0)
  19.             {
  20.                 if (metaData.Data != null)
  21.                 {
  22.                     Dictionary<int, Weapon> di = metaData.Data.AllWeaponsById;
  23.                     for (int x = 0; x < di.Keys.Count; x++)
  24.                     {
  25.                         Console.WriteLine("{0} is {1}.",x,di[x].Name);
  26.                     }
  27.                 }
  28.             }
  29.         }
  30.     }
  31. }
  32.  
Also, there is a great rescource at http://www.haloreachapi.net for more information on this subject.
Feb 5 '11 #2
HaLo2FrEeEk
404 256MB
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:

http://www.bungie.net/api/reach/ReachApiSoap.svc

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

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

This is a different, completely publically-accessible API that helps with AJAX loading for certain pages on the site. This API has 2 methods: GetScreenshotTooltip() and GetGameViewerData() 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:

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

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.
Feb 6 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: John | last post by:
Hi I need to be able to call a web service method, receive the dataset that web method returns and store it in an access table. My problem is that I don't know how to "receive" a complex type...
1
by: Information | last post by:
Hi, I am doing a course project now for practive xml. I heard from somewhere that xml request can go through firewall. currently in our school there is a firewall which only can log on by vpn when...
4
by: karpagam | last post by:
Since WebServices are a standardized way to invoke a method of another application over the internet, is there a way to integrate two different applications running on different platforms (Say a...
2
by: Jonathan Woods | last post by:
Hi there, I have encountered problem of losing data sending over internet using web service. I consume web service that connected Oracle Database. I submit 687 SOAP Messages to 1 Web Method...
1
by: Andrew Poulos | last post by:
There's an object: foo = new Object(); and a property called 'bar' with a value of 1 is to be added to it using JSON. If I try the following it only demonstrates my ignorance: var str =...
2
by: Daz | last post by:
Hi everyone. Sorry for the confusing subject, I couldn't think how best to word it. What I would like to know, is if there is an equivilant to this code, in using JSON. <script...
2
by: mfsiddiq | last post by:
Hi i want to know how to set cookies in your browser using java if you are using web service.I have written this code but unable to understand how to set it in the browser String myCookie =...
1
by: kashok | last post by:
Hi all, What is the use of using our own web service in asp.net instead of using ordinary class files for defining functions.. what is the benefit of using web service....... Thnk u!
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.