Posted by david on 29. January 2009 22:02
In the last episode of 24, we managed to get the structure & namespaces working … or, at least, not redlined. I used the svcutil command line to consolidate the VEWS into one Service Reference – & things looked OK on the surface.
-------------------------------------
now to start getting all the parts working together. First, since everything looks legal, let’s go ahead & try connecting to the geocode service ..
add a “var geoRequest = new GeocodeRequest();” … GeocodeRequest fails.
Shit, now VirtualEarthWebServices is unrecognized. but commenting out the geoRequest line removes the error from VirtualEarthWebServices.
check webconfig to make sure VEWSTokenService has username & password. …. OK
try
“VirtualEarthWebServices.GeocodeRequest geoRequest = new VirtualEarthWebServices.GeocodeRequest” …. fails.
ok, got it. Previously, when I was adding service references the user interface, one at a time, it was easy to give the individual services friendly names, like VEWSGeocode, or VEWSSearch. It seems that I’ve lost the ability to friendly name the services, perhaps because they were all bundled up into one. The individual services are not referenced via VirtualEarthWebServices, they are referenced by a very very long namespace: geocode is the following:
dev.virtualearth.net.webservices.v1.geocode
There’s probably an easy way to alias this …
sooo, my entire line to instantiate a new geocoderequest is:
dev.virtualearth.net.webservices.v1.geocode.GeocodeRequest geoRequest = new dev.virtualearth.net.webservices.v1.geocode.GeocodeRequest();
---------------------------------
So the entire segment, which will eat up a text box address & return a lat and a long is this:
string token = GetToken();
dev.virtualearth.net.webservices.v1.geocode.GeocodeRequest geoRequest = new dev.virtualearth.net.webservices.v1.geocode.GeocodeRequest();
geoRequest.Credentials = new dev.virtualearth.net.webservices.v1.common.Credentials();
geoRequest.Credentials.Token = GetToken();
geoRequest.Query = inputtextbox.Text;
dev.virtualearth.net.webservices.v1.geocode.GeocodeOptions myOptions = new dev.virtualearth.net.webservices.v1.geocode.GeocodeOptions();
myOptions.Count = 1;
GeocodeServiceClient myServiceClient = new GeocodeServiceClient();
dev.virtualearth.net.webservices.v1.geocode.GeocodeResponse myGeocodeResponse = myServiceClient.Geocode(geoRequest);
responseLatitude.Text = myGeocodeResponse.Results[0].Locations[0].Latitude.ToString();
responseLongitude.Text = myGeocodeResponse.Results[0].Locations[0].Longitude.ToString();
&, BION, it is all kosher. For now.
------------------------------------
the token service stuff is all goofy …
// Set Virtual Earth Platform Developer Account credentials to access the Token Service
VEWSTokenService.CommonService commonService = new VEWSTokenService.CommonService();
commonService.Credentials = new System.Net.NetworkCredential("VEDevAccountID", "VEDevAccountPassword");
// Set the token specification properties
VEWSTokenService.TokenSpecification tokenSpec = new VEWSTokenService.TokenSpecification();
tokenSpec.ClientIPAddress = "ClientIPAddress";
tokenSpec.TokenValidityDurationMinutes = 60;
string token = "";
// Get a token
try
{
token = commonService.GetClientToken(tokenSpec);
}
catch (Exception ex)
{
throw ex;
}
return token;
VEWSTokenService is unrecognized.
Try a build ….. that seemed to … nope, didn’t help, page is still breaking: Compiler Error Message: CS0246: The type or namespace name 'VEWSTokenService' could not be found
ok -
I noticed that my VEWSTokenService was in the App_Data folder, not the App_WebReferences. I don’t f know how it got up and walked over there. Anyway – deleted it.
Added the web reference again, this time not changing the name. Simply: net.virtualearth.common.staging. & in my code page, Using net.virtualearth.common.staging;
I copied the GetToken code from MSDN, and removed all the TokenWebReference references which was their friendly name for net.virtualearth.common.staging. That worked. The Using statement was enough for the Common Service references to be legal. Joy.
ah, loading the page, it still doesn’t like the Using VirtualEarthWebServices – though it is effective in the code.
try a rebuild.
still doesn’t like the VirtualEarthWebServices.
Can I reference the individual service URL?
opened up the VirtualEarthWebServices.cs file & found the namespace for geocode. It is dev.virtualearth.net.webservices.v1.geocode
plugged that in the Using statement.
Page Loads. Holla.
But I get a 401 error. which is fine, cuz I’ve seen that mentioned somewhere.
Ah – I didn’t have the right userid, password in GetToken() … fix that ….
reload … Fail: The specified IP address is in an invalid format. Argument: tokenSpecification.ClientIPAddress
the code I copied from MSDN had this:
tokenSpec.ClientIPAddress = "ClientIPAddress";
If I had been looking, it would have been an obvious problem … Checked here & he has:
tokenSpec.ClientIPAddress = Page.Request.UserHostAddress …. fix that
Here is what I’m after, BTW:
Oooh … the problems never cease:
Could not find default endpoint element that references contract 'IGeocodeService' 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.
Searching for answers:
& it looks like the gods have decided to stop tormenting me: 2009_01_28
Close enough! hell, i’m not running an ambulance service here :)
………………………………………………………..
I wonder if this stream of consciousness exploration of this project is interesting to anyone
“Stream-of-consciousness writing is usually regarded as a special form of interior monologue and is characterized by associative (and at times--dissociative) leaps in syntax and punctuation that can make the prose difficult to follow, tracing a character's fragmentary thoughts and sensory feelings.” (wikipedia)
I fear it might only be interesting to potential employers as grounds not to hire me.
Think I’ll do a rewrite when all this is done.