WP7, How to use a service reference after adding it to Visual Studio 2010
Asked Answered
L

3

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?

Linsang answered 24/11, 2010 at 0:57 Comment(0)
F
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.

Femoral answered 24/11, 2010 at 1:7 Comment(5)
That's what I tried, but I don't see anything. I added the URL for the service in the address box (dev.virtualearth.net/webservices/v1/geocodeservice/…), 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.Linsang
You may need to build your solution first. Then try a simple line such as GeoCodeService svc = new GeoCodeService() and see if that works.Femoral
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.Femoral
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.Linsang
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 namespaceLinsang
M
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.

Marquismarquisate answered 19/9, 2014 at 18:3 Comment(1)
Thanks very much for this answer! This was frustrating me out of all proportion to its importance.Disloyal
F
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.

Femoral answered 24/11, 2010 at 1:7 Comment(5)
That's what I tried, but I don't see anything. I added the URL for the service in the address box (dev.virtualearth.net/webservices/v1/geocodeservice/…), 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.Linsang
You may need to build your solution first. Then try a simple line such as GeoCodeService svc = new GeoCodeService() and see if that works.Femoral
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.Femoral
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.Linsang
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 namespaceLinsang
N
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.

Nikolaus answered 8/10, 2019 at 14:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.