Friday, September 10, 2010

ve: VEWS 2

Posted by david on 28. January 2009 23:56

the previous few posts are all out of order .. they were unsaved posts from various dates.

I’ve, once and for all, settled on using VEWS to power the geocode stuff.

I have been trying to get it working for an embarrassingly long time.

but but but, fortunately, it’s not entirely my fault. 

due to two bugs/glitches/challenges:

id/password acceptance when adding a service

the added services not actually being usable & causing a parser error, which shut the entire app down, at the top level page.

********************************

I was making fine progress by very carefully following this video, Getting Started With The Virtual Earth Web Services.

Ultimately, all the references worked, everything seemed fine and dandy. 

But, then I got the dread Parser Error. 

referenced here,

Has to do with VS not building the right proxy classes, using the Add Service dialogues.  There are a couple of other ways to do it – one was over my head, the other is described in MSDN How to Generate Client Proxy Classes.

Here is the svcutil generated file: for all 4 VEWS

svcutil.exe /target:code /language:csharp /out:VirtualEarthWebServices http://staging.dev.virtualearth.net/webservices/v1/searchservice/searchservice.svc?wsdl http://staging.dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc?wsdl http://staging.dev.virtualearth.net/webservices/v1/imageryservice/imageryservice.svc?wsdl http://staging.dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc?wsdl 

 

However, one of the forums seemed to indicate that the beta SP1 fixed the problems.  Now, I have SP1, months after the forum posting mentioned.  But I checked with Windows Update and there was some sort of ASP update. So I installed & rebooted last night, just on the off chance that things would work.

“To call one of the Virtual Earth Web Services, you need to generate proxy classes on your client. This is described in detail in the Generating Client Proxy Classes topic. If you are using Visual Studio 2008, use the svcutil.exe command-line utility (http://msdn.microsoft.com/en-us/library/aa347733.aspx) or add service references to the Virtual Earth Web Services from the Visual Studio user interface.” ( source )

So, I’ve deleted/removed all the services I had in there before the update  … I’m going to add in the services via the menu again.

The Token Service

Following Virtual Earth Web Services - Requesting a Token, I add a Web Reference to the Token Service URL:

https://staging.common.virtualearth.net/find-30/common.asmx?wsdl

Here is where the first glitch occurs.  You enter your user id, password & it immediately pops up with another request for same. Your first thought is that you goofed up. You didn’t, they did … or as the aforementioned video notes, they’re actually asking for the same user id/password for several different urls.   Anyway, after a few go rounds, it accepts the id & presents you with the service information.  This last time that I did it, the dialogue also started freaking about non secure content, asking if I wanted to limit to only secure content. I had to say No about twenty times before it gave up.  Not sure about that one.

the final thing to do here is rename the web ref.  I dub thee VEWSTokenService.

& it shows up in my App_WebReferences folder.  Hurrah. &, more importantly, I can reference it in a Using statement & all is well.  & the page at least loads.

Adding the VEWS Services

Following Virtual Earth Web Services – again he sez: “If you are using Visual Studio 2008, use the svcutil.exe command-line utility or add service references to the Virtual Earth Web Services from the Visual Studio user interface.”

I take that or to mean either one will work.  I took a swing at the svcutil method last night, but didn’t really understand wtf  I was supposed to do with the resultant files, or, rather, how to reference them correctly.  The instructions seem to think it’s self-evident. It’s not.  The MSDN metadata article also uses the same language to describe the options.

So, I’m going to make one last attempt at using the VS interface. If it fails, I’ll dive into figuring out the svcutil method.

The svcutil method was created, I gather, because of a need to be able to combine multiple services into one unit. But, Mr.Emery doesn’t mention that it’s necessary. 

MSDN Metadata site

Geocode Service: http://staging.dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc?wsdl

Imagery Service: http://staging.dev.virtualearth.net/webservices/v1/imageryservice/imageryservice.svc?wsdl

Route Service: http://staging.dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc?wsdl

Search Service: http://staging.dev.virtualearth.net/webservices/v1/searchservice/searchservice.svc?wsdl

Step 1, Add Service Reference. Add above Geocode Service URL, Rename namespace VEWSGeocode.  I just noticed that what I was renaming or declaring was a namespace, not just a name for the reference. I wonder if that’s what was screwing me. I check the video, he’s doing the Service Reference at 6 min into the video.  He does rename the namespace, “give it a friendly name.”

Failure!

so, immediately after adding the Service, I reloaded my page. It failed like last time:

Server Error in '/' Application.
--------------------------------------------------------------------------------
Parser Error 
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 
Parser Error Message: Reference.svcmap: Specified argument was out of the range of valid values.
Parameter name: site
Source Error: 
[No relevant source lines]
Source File: /App_WebReferences/VEWSGeocode/    Line: 1 

so, now, following this forum discussion

I have discovered a resolution for the problem. I've outlined the steps below. In my example, the WCF dll is named "Recruitment.dll."
 
The resolution is to use VS command prompt to generate a proxy: 
1.svcutil [RecruitmentService.dll]2.svcutil *.wsdl *.xsd /language:C# /namespace:*, RecruitmentService
3.Move the generated CS to the App_Code folder
4.Remove the Web_References folder entirely
In the code-behind, you will need to reference the CS file like this: using RecruitmentService;

another bloke says, down the page, that Publishing the site fixes the problem – but I’m hooked straight to my hosted site & not sure what kind of mess that would involve.

another bloke says Set Target of .NET 3.0 instead of 3.5 & recreate the web service calls.  me no likey.

Another forum on this subject.

I deleted the web reference, wondering if that was somehow goofing things. Still have the same error.  so the web ref is not the problem.  Added it back in.

OK OK OK, I’ll try svcutil

ran svcutil with the following code, copied straight from MSDN

svcutil.exe /target:code /language:csharp /out:VirtualEarthWebServices http://staging.dev.virtualearth.net/webservices/v1/searchservice/searchservice.svc?wsdl http://staging.dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc?wsdl http://staging.dev.virtualearth.net/webservices/v1/imageryservice/imageryservice.svc?wsdl http://staging.dev.virtualearth.net/webservices/v1/routeservice/routeservice.svc?wsdl 
 
rem  The VirtualEarthWebServices.cs file contains the proxy classes that have been generated. Add this file to your Visual Studio project. The App.config file contains configuration settings.

This generated 2 files, VirtualEarthWebServices.cs & output.config. I picked up the 2 files, moved em to a more accessible spot.

Then add the CS file to the App_Code folder. ( add existing item).

Deleted the VEWSGeocode Service Reference.

Reload my page …….. ……. & it loads. I’m about to pee.

sooo next step, theoretically, all the services should be available & accessible – If I can get their right name.

Comments

Add comment


 

biuquote
Loading