To reduce the billable transaction in my web form asp.net project, i decided to test it.
I have come across following example on msdn for session key.
Map.CredentialsProvider.GetCredentials(
Function(c)
Dim sessionKey As String = c.ApplicationId
'Generate a request URL for the Bing Maps REST services.
'Use the session key in the request as the Bing Maps key
Return 0
End Function)
My Code example
private String GeocodeAddress(string address)
{ string results = "";
string key = "Bing Maps key";
GeocodeRequest geocodeRequest = new GeocodeRequest();
// Set the credentials using a valid Bing Maps key
geocodeRequest.Credentials = new GeocodeService.Credentials();
geocodeRequest.Credentials.ApplicationId = key;
// Set the full address query
geocodeRequest.Query = address;
// Set the options to only return high confidence results
ConfidenceFilter[] filters = new ConfidenceFilter[1];
filters[0] = new ConfidenceFilter();
filters[0].MinimumConfidence = GeocodeService.Confidence.High;
// Add the filters to the options
GeocodeOptions geocodeOptions = new GeocodeOptions();
geocodeOptions.Filters = filters;
geocodeRequest.Options = geocodeOptions;
// Make the geocode request
GeocodeServiceClient geocodeService = new GeocodeServiceClient();
GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);
if (geocodeResponse.Results.Length > 0)
results = String.Format("Latitude: {0}\nLongitude: {1}",
geocodeResponse.Results[0].Locations[0].Latitude,
geocodeResponse.Results[0].Locations[0].Longitude);
else
results = "No Results Found";
return results;
}
After debugging it, i can't see any difference b/w (application id / session key) and Bing Api key. How can i get sessionkey in above example?
The session key can only be used on the same page as the interactive map. Passing a session key between pages is not allowed. Assuming that you have an AJAX button or something that is processing some code on the server and returning it to the same page as the map, then this would be alright.
The first bit of code looks like you are trying to generate a session key in .NET. This would only be possible if you where using Silverlight or WPF. I'll assume you are not using the Bing Maps WPF control on the server as that's really against the terms of use. If you are using Silverlight, then there is no need to pass a key to the server side.
So lets assuming you generate a key in JavaScript from the Bing Maps v7 control and pass it to AJAX button handler on the server. If this is the case then it's alright.
In your code it looks like you are using the really old legacy SOAP services which is not recommended. In fact I stopped recommending them about 4 or 5 years ago. The documentation was taken offline a couple of years ago. You should be using the Bing Maps REST services which are faster, more accurate and has more features. You can find documentation on how to use them in .NET here: http://msdn.microsoft.com/en-us/library/jj819168.aspx
Also, here are some tips on using the REST services: http://blogs.bing.com/maps/2013/02/14/bing-maps-rest-service-tips-tricks/
ApplicationId and session key are the same thing. The SOAP services are so old it used to have a different name.
You won't see any differences in the reports right away. It can take up to a week for the reports to sync up across all the servers/data centers as it's a low priority job with massive amounts of data.
If your application has decent traffic you will likely end up with a lot more non-billable transactions than billable transactions which will likely cause your account to be flagged and investigated and possibly blocked.
What you should be doing is geocoding your addresses ahead of time and storing the coordinates. This is how most applications handle this type of scenario. The only time you should need to geocode on the fly is if you have a search box for user input, all everything else should be geocoded ahead of time for performance.
Related
Hey all the last time I used IGDB was when it was in version 3 and it was easy to search for a game depending on the platform chosen:
string url = "https://api-v3.igdb.com/games/?search=" + gameNameHere +
"&fields=name,genres,involved_companies,first_release_date,cover";
HttpWebRequest gameRequest = (HttpWebRequest)WebRequest.Create(url);
However, this version 4 is quite compilated since they tie in Twitch Oauth for some reason in order to call the API.
Besides the Oauth issue I am unable to find a simple search for a game using the IGDB-DOTNET wrapper for V4...
Now for this wrapper I start out (like it says on the website) with the following:
var igdb = new IGDBClient(
// Found in Twitch Developer portal for your app
Environment.GetEnvironmentVariable("IGDB_CLIENT_ID"),
Environment.GetEnvironmentVariable("IGDB_CLIENT_SECRET")
);
I place both my Client ID and Secret into the proper spots above. Ok, easy enough.
But now it continues to this - calling it "simple":
// Simple fields
var games = await igdb.QueryAsync<Game>(IGDBClient.Endpoints.Games,
query: "fields id,name; where id = 4;");
var game = games.First();
game.Id; // 4
game.Name; // Thief
So where did this Thief game ID of 4 come from? How do I search for the game "Thief" and get that ID in order to call the above to get the needed name, cover, artwork, etc...?
The other 3 examples below that also do not show how to search for a game.
So is this below what its looking for me to do in order to search?
var games = await igdb.QueryAsync<Game>(IGDBClient.Endpoints.Games,
query: "search \"Thief\"; fields id,name,cover;");
If not then how does one do that for V4?
Yes, you are right,
var r = await IGDBClient.QueryAsync<Game>(IGDBClient.Endpoints.Games,
$"search \"{query}\"; fields id, name,first_release_date,total_rating,summary,cover.*;");
where query = "Thief";
How can i get the country name from latitude and longtitude using c#?
Im using the Bing.Map API
Location location12 = new Location(location.Latitude, location.Longitude);
MapLayer.SetPosition(pin, location12);
Map.Children.Add(pin);
string placeName = GetPlaceNameForCoordinates(location.Latitude, location.Longitude);
You'll want to use a reverse geocoding API of some kind. For example:
The Bing Maps API (the webservice)
The Google Geocoding API
The Geonames API
If you're already using the Bing.Maps SDK, you should use the Map.SearchManager property to get a SearchManager, and then use the ReverseGeocodeAsync method. In particular, as noted in comments, mixing and matching which API you use to show data via other SDKs may well violate the terms and conditions of both: be careful which technologies you use within a single application. (Even though this question gives sample code using the Bing Maps SDK, I've kept the list above in order to help others who may come with a slightly different context.)
For example:
var manager = map.SearchManager;
var request = new ReverseGeocodeRequestOptions(location) {
IncludeEntityTypeFlags = ReverseGeocodeEntityType.CountryRegion
};
var response = await manager.ReverseGeocodeAsync(
new ReverseGeocodeRequestOptions(location) { );
// Use the response
If you decide to use the Geonames API, the data can be downloaded for offline use too.
I've created a github project with sample code that does this without api calls
see here
Very simple country name and id returned
I'm working with windows phone apps and I'm using here rest places api for my data and i retrieving data as json that give me information about location nearby like this
position: [ 37.77704 , -122.39494 ]
distance: 1241
title: Caltrain-San Francisco
averageRating: 0.0
category: { Public transport }
icon: http://download.vcdn.nokia.com/p/d/places2/icons/categories/11.icon
vicinity: 700 4th St<br/>San Francisco, CA 94107
having: [ ]
type: urn:nlp-types:place
href: http://demo.places.nlp.nokia.com/places/v1/places/8409q8yy-a7395cccbfc4474ba469f3ddc03e041b;context=Zmxvdy1pZD00OWQxZDY0Zi0zODc5LTVlNDAtOWY4ZC04ZGFmNWMyMGZhZDFfMTM4OTg4NDQxMzUxNV8wXzM1MjkmcmFuaz0w?app_id=lp3VaO8uhOFe0akZ4J1m&app_code=JwL7MNaSarML92oqEDshAg
id: 8409q8yy-a7395cccbfc4474ba469f3ddc03e041b
and i notice that if i open
href: http://demo.places.nlp.nokia.com/places/v1/places/8409q8yy-a7395cccbfc4474ba469f3ddc03e041b;context=Zmxvdy1pZD00OWQxZDY0Zi0zODc5LTVlNDAtOWY4ZC04ZGFmNWMyMGZhZDFfMTM4OTg4NDQxMzUxNV8wXzM1MjkmcmFuaz0w?app_id=lp3VaO8uhOFe0akZ4J1m&app_code=JwL7MNaSarML92oqEDshAg
i will go into other page that contain much detailed information about that location, so how can i get all of this data?the general and detailed data from that href
method that i using to get general data is using this
WebClient client = new WebClient();
Uri uri = new Uri(transportURL1 + latitude + "%2C" + longitude + transportURL2, UriKind.Absolute);
client.DownloadStringCompleted += (s, e) =>
{
if (e.Error == null)
{
RootObject result = JsonConvert.DeserializeObject<RootObject>(e.Result);
hereRestProperty = new ObservableCollection<Item>(result.results.items);
}
else
{
MessageBox.Show(e.Error.ToString());
}
};
client.DownloadStringAsync(uri);
so my app scenario is mainpage showing general location data and when I tap one of the location data it will navigate to detailpage that contain information from that href
how to do that?
edit: my work around is getting href and using that href to calling http request but i have no idea how to do all that...
edit2: after looking around I come up with idea of having mainpage with list of general information and if I click into one of the item in list it will navigate me to detailpage that will request from that href but i just don't know how to execute that in mvvm aproach...
If it is safe to assume that you are trying to add value to your app by adding a places feature, I would suggest that for Windows Phone 8 you would be better off launching HERE Maps directly using the HERE Maps Launchers API
For example, if your app is about hiking trails it would make sense to add a feature for finding details of places to eat or stay near that hiking trail - but you wouldn't need to create your own code to request, format and display the in-depth places data, just fire up the Maps app already on the device (passing in the href from the initial REST request if necessary). The advantage of doing this is threefold, firstly you can add this feature in four lines of code, secondly the user is presented with the places information in a familiar format, and finally information is retrieved from the device itself which alleviates the need to make additional HTTP requests.
One or more of the following tasks may be useful:
ExploremapsShowPlaceTask allows you to start the Maps application with the map centered to a place shown in the map.
ExploremapsSearchPlacesTask allows you to start the Maps application with the search view.
ExploremapsExplorePlacesTask allows you to start the Maps application where the nearby places of interest are shown.
PlacesShowDetailsByLocationTask allows you to start the Maps application with the places view for the selected place.
PlacesShowDetailsByIdHrefTask allows you to start the Maps application with the places view for the selected place.
Note that if HERE Maps is not installed on the Windows Phone 8 device, the user will be directed to download it for free from the app store.
Where I work, we have two modes of authentication:
CAS (http://www.jasig.org/cas)
LDAP
CAS is the primary method, but it is often unreliable at peak traffic times and so we have been using LDAP as a fallback mode for when we notice that CAS is down. Previously, we were using PHP for doing our LDAP fallback and got reasonable performance. There wasn't a noticeable delay during login other than the expected network lag times. A login took probably ~250-500ms to complete using LDAP.
Now, we are making a new system and have chosen ASP.NET MVC4 as the platform rather than PHP and I am tasked with trying to get this fallback working again. I have been pulling my hair out for about 6 hours now trying different things over and over again, getting the same result (perhaps I am insane). I have finally managed to connect to LDAP, authenticate the user, and get their attributes from LDAP. However, the query consistently takes 4.5 seconds to complete no matter what method I try.
This is very surprising to me seeing as the PHP version was able to do nearly the same thing in 1/8th the time and it would seem that the .NET framework has excellent support for LDAP/ActiveDirectory. Am I doing something incredibly horribly wrong?
Here are the guts of my function as it stands now (this one is the latest iteration that manages to do everything in one 4.5 second query):
public Models.CASAttributes Authenticate(string username, string pwd)
{
string uid = string.Format("uid={0},ou=People,o=byu.edu", username);
LdapDirectoryIdentifier identifier = new LdapDirectoryIdentifier("ldap.byu.edu", 636, false, false);
try
{
using (LdapConnection connection = new LdapConnection(identifier))
{
connection.Credential = new NetworkCredential(uid, pwd);
connection.AuthType = AuthType.Basic;
connection.SessionOptions.SecureSocketLayer = true;
connection.SessionOptions.ProtocolVersion = 3;
string filter = "(uid=" + username + ")";
SearchRequest request = new SearchRequest("ou=People,o=byu.edu", filter, SearchScope.Subtree);
Stopwatch sw = Stopwatch.StartNew();
SearchResponse response = connection.SendRequest(request) as SearchResponse;
sw.Stop();
Debug.WriteLine(sw.ElapsedMilliseconds);
foreach (SearchResultEntry entry in response.Entries)
{
Debug.WriteLine(entry.DistinguishedName);
foreach (System.Collections.DictionaryEntry attribute in entry.Attributes)
{
Debug.WriteLine(attribute.Key + " " + attribute.Value.GetType().ToString());
}
Debug.WriteLine("");
}
}
}
catch
{
Debugger.Break();
}
Debugger.Break();
return null; //debug
}
The PHP version of this follows this sequence:
Bind anonymously and look up the user information using a basedn and cn
Bind again using the username and password of the user to see if they are authentic
It does two binds (connects?) in 1/8th the time it takes the .NET version to do one! Its this sort of thing that makes me thing I am missing something.
I have tried methods based on the following sites:
http://roadha.us/2013/04/ldap-authentication-with-c-sharp/ - Required 2 queries to do what I wanted and was too slow. I went through probably 6 different tries of doing it differently (varying the authentication & connection settings, etc).
http://web.byu.edu/docs/ldap-authentication-0 - One PHP version, but has a small snippet about .NET at the bottom. I needed to get the profile as well and they weren't exactly descriptive.
System.DirectoryServices is slow? - Current version
EDIT:
Using wireshark, I saw that the following requests are made:
bindRequest passing along my uid (delta 0.7ms)
bindResponse success (delta 2ms)
searchRequest "ou=People,o=byu.edu" wholdSubtree (delta 0.2ms)
searchResEntry "uid=my uid,ou=People,o=byu.edu" | searchResDone success 1 result (delta 10.8ms)
unbindRequest (delta 55.7ms)
Clearly, the overhead is coming from .NET and not from the requests. These don't add up to 4.5 seconds in any way, shape, or form.
ldap.byu.edu sure looks like a fully qualified DNS host name. You should change your LdapDirectoryIdentifier constructor to new LdapDirectoryIdentifier("ldap.byu.edu", 636, true, false).
I think you're definitely on the right track using System.DirectoryServices for this, so you may just need to tweak your search request a bit.
You're only looking to get one result back here, correct? Set your size accordingly :
request.SizeLimit = 1;
This is a tricky one, but make also sure you're suppressing referral binds as well. You'll want to set this before you call connection.SendRequest(request) :
//Setting the DomainScope will suppress referral binds from occurring during the search
SearchOptionsControl SuppressReferrals = new SearchOptionsControl(SearchOption.DomainScope);
request.Controls.Add(SuppressReferrals);
Right now I have an app that allows a user to schedule/post a Facebook post and then monitor the likes/comments. One of the problems I foresee is that currently I am pulling every single comment/like whether it's been processed or not. What I would like to do instead is be able to say 'Give me all the NEW comments since XYZdate/XYZcomment.' Is this currently possible?
var accessToken = existingUserNode.Attributes["accessToken"].Value;
var facebookAPIMgr = new FacebookWrapper.FacebookAPIManager();
var msg = new FacebookWrapper.FacebookMessage()
{
AccessToken = accessToken,
FacebookMessageId = facebookPost.FacebookMessageId
};
//Get Facebook Message Comments
// Need to find a way to limit this to only new comments/likes
var comments = facebookAPIMgr.RetrieveComments(msg);
You can do time-based pagination as part of your graph API query. If you keep a unix timestamp of when you polled things last, you can simply do https://graph.facebook.com/{whatever}?since={last run}.
This worked when I was working heavily with the Graph API earlier this year, and is still around on the documentation, but considering how much Facebook loves to change stuff without telling anyone you may still encounter problems. So just a warning, YMMV.