11

I'm following this example for connecting to the Bing Maps geocode service:

Link

About half way down the page, it explains how to add a service reference in Visual Studio 2010, which I was able to do successfully. Then it says to add "using GeoCode.GeoCodeService", but when I do, I get an error saying "The type or namespace 'GeoCode' could not be found"

Am I doing something wrong. The steps are pretty simple and nothing gave an error. What else do I need to do in order to access the service?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
CACuzcatlan
  • 5,407
  • 8
  • 41
  • 59

3 Answers3

6

After you added a Reference using your WSDL URL:

Under Solution, under Service References, right click on your Service Reference folder that you want to reference (example: com.gold.services.description1)

Select View in Object Browser. You will see the class name in the Object Browser window that will open up. (example: GoldWeb.com.gold.services.description1)

Copy and paste the class name into your code.

Example:

using GoldWeb.com.gold.services.description1;

Then you are ready to start using its classes.

live-love
  • 48,840
  • 22
  • 240
  • 204
5

When you added the service reference, you gave it a class name. Have a look in your solution explorer to see what you called it, and then you have to instantiate that class to use the service.

Darbio
  • 11,286
  • 12
  • 60
  • 100
  • That's what I tried, but I don't see anything. I added the URL for the service in the address box (http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc), then I typed in "GeoCodeService" in the Namespace box. In solution explorer I see Properties, Services, then Service References. Under Service References I see GeoCodeService (same as what I typed into the namespace box earlier). But I can't create an instance of GeoCodeService. – CACuzcatlan Nov 24 '10 at 01:26
  • 1
    You may need to build your solution first. Then try a simple line such as `GeoCodeService svc = new GeoCodeService()` and see if that works. – Darbio Nov 24 '10 at 01:28
  • 1
    Also... If GeoCodeService is a namespace, you may need to do something like `GeoCodeService.GeoCodeServiceService svc = new ..... ()` or put the namespace into your `using` directive at the top of the source file. – Darbio Nov 24 '10 at 01:29
  • I rebuilt the solution, but it still doesn't work. Says "the type or namespace GeoCodeService cannot be found". I'm using Visual Studio 2010 Express for Windows Phone. As far as I know, this is the only version that you can use to develop phone apps, so I can't imagine that it would be a limitation of Visual Studio Express. – CACuzcatlan Nov 24 '10 at 01:37
  • My namespace was off and intellisense didn't show it earlier because I hadn't build the solution. After building the solution, I clicked on the service in solution explorer and clicked "view in object browser" and it showed me the correct namespace – CACuzcatlan Nov 24 '10 at 01:57
0

I seen this happen, when a service may be added to one project and is being back referenced in another project. For instance, the main project has the service reference, but library code, that's is reference in the main project, tries to instantiate the webservice. This is a circular/backreference and you can't add the namespace of the main project back into the library project, since the library project is already reference into the main project. I know this seem obvious, but in really big projects, it's easy to get lost to where you're at in code.

Razorfisk
  • 11
  • 1