Getting "The service method is not found error" in Bing Maps - asp.net

We are using geocoding service to get geocodeAddress (latitude/longitude) but we are getting the "The service method is not found" error. Below are my code.
public static double[] GeocodeAddress(string address, string virtualearthKey)
{
net.virtualearth.dev.GeocodeRequest geocodeRequest = new net.virtualearth.dev.GeocodeRequest
{
// Set the credentials using a valid Bing Maps key
Credentials = new net.virtualearth.dev.Credentials { ApplicationId = virtualearthKey },
// Set the full address query
Query = address
};
// Set the options to only return high confidence results
net.virtualearth.dev.ConfidenceFilter[] filters = new net.virtualearth.dev.ConfidenceFilter[1];
filters[0] = new net.virtualearth.dev.ConfidenceFilter
{
MinimumConfidence = net.virtualearth.dev.Confidence.High
};
// Add the filters to the options
net.virtualearth.dev.GeocodeOptions geocodeOptions = new net.virtualearth.dev.GeocodeOptions { Filters = filters };
geocodeRequest.Options = geocodeOptions;
// Make the geocode request
net.virtualearth.dev.GeocodeService geocodeService = new net.virtualearth.dev.GeocodeService();
net.virtualearth.dev.GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);
if (geocodeResponse.Results.Length > 0)
{
return new[] { geocodeResponse.Results[0].Locations[0].Latitude, geocodeResponse.Results[0].Locations[0].Longitude };
}
return new double[] { };
} // GeocodeAddress
Key is used for URL for bing map geocode service in we.config
<add key="net.virtualearth.dev.GeocodeService" value="http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc" />

Looks like you are trying to use the old Virtual Earth SOAP Services which were deprecated and shut down last year. These were replaced by the Bing Maps REST services 7 or 8 years ago. Since you are working in .NET, take a look at the Bing Maps .NET REST Toolkit. It makes it easy to use the REST services in .NET. There is a NuGet package available as well. You can find details here: https://github.com/Microsoft/BingMapsRESTToolkit
Once you have the NuGet package added to your project, you can geocode like this:
//Create a request.
var request = new GeocodeRequest()
{
Query = "New York, NY",
IncludeIso2 = true,
IncludeNeighborhood = true,
MaxResults = 25,
BingMapsKey = "YOUR_BING_MAPS_KEY"
};
//Execute the request.
var response = await request.Execute();
if(response != null &&
response.ResourceSets != null &&
response.ResourceSets.Length > 0 &&
response.ResourceSets[0].Resources != null &&
response.ResourceSets[0].Resources.Length > 0)
{
var result = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location;
//Do something with the result.
}

Related

Meteor-Dwolla Bulk create customer accounts

Requirement here is I wants to add number of customers on dwolla in one shot. By running dwolla create customer in loop. But things is some customer addition is failing with error,
Error: {“code”:“ServerError”,“message”:“A server error occurred. Error ID: 6188070b-8a1b-4d94-90a5-eb1333d3cd9e.”}
Code:
const client = new dwolla.Client({
key : dwollaCredentials.appKey,
secret : dwollaCredentials.appSecret,
environment : 'sandbox' // optional - defaults to production
});
client.auth.client().then(Meteor.bindEnvironment(function(appToken) {
var spaceProviders = getListofSpaceProvidersWithNoDwollaAcc();
console.log(spaceProviders.length);
for (var i = 0 ; i<spaceProviders.length ; i++) {
var spaceProviderId = spaceProviders[i].id;
var routingNumberUser = spaceProviders[i].routingNo;
var accountNumberUser = spaceProviders[i].accountNumber;
var bankName = spaceProviders[i].firstName+' '+spaceProviders[i].lastName+' Bank';
if (spaceProviders[i]) {
var requestBody = {
firstName : spaceProviders[i].firstName,
lastName : spaceProviders[i].lastName,
email : spaceProviders[i].email
};
console.log('requestBody: ',requestBody);
appToken
.post('customers', requestBody)
.then((res)=> {
var dwollaLocation = res.headers.get('location');
return Promise.resolve(dwollaLocation);
})
.then(Meteor.bindEnvironment((dloc) => {
console.log("dloc"+i+' '+dloc);
return Promise.resolve(dloc);
}))
.catch(error => console.log("Handled Exceptions user",i+' - '+error));
}
}//i
})
);
Somehow bulk customers account creation is failing, may be this is creating continues calls at dwolla and it is unable to handle this much big number, may be one request starts processing and another one is reaching like wise, so finally I am settling for individual "ADD" button for each customer and calling create dwolla customer api on click event.

How to post Special character tweet using asp.net API?

I m using Given below code to post the tweet on twitter. But when we upload it on the server then special character (!,:,$ etc) tweets not published on twitter. this code is working fine in the local system
string key = "";
string secret = "";
string token="";
string tokenSecret="";
try
{
string localFilename = HttpContext.Current.Server.MapPath("../images/").ToString();
using (WebClient client = new WebClient())
{
client.DownloadFile(imagePath, localFilename);
}
var service = new TweetSharp.TwitterService(key, secret);
service.AuthenticateWith(token, tokenSecret);
// Tweet wtih image
if (imagePath.Length > 0)
{
using (var stream = new FileStream(localFilename, FileMode.Open))
{
var result = service.SendTweetWithMedia(new SendTweetWithMediaOptions
{
Status = message,
Images = new Dictionary<string, Stream> { { "name", stream } }
});
}
}
else // just message
{
var result = service.SendTweet(new SendTweetOptions
{
Status = HttpUtility.UrlEncode(message)
});
}
}
catch (Exception ex)
{
throw ex;
}
The statuses/update_with_media API endpoint is actually deprecated by Twitter and shouldn't be used (https://dev.twitter.com/rest/reference/post/statuses/update_with_media).
TweetSharp also has some issues with using this method when the tweet contains both a 'special character' AND an image (works fine with either, but not both). I don't know why and I haven't been able to fix it, it's something to do with the OAuth signature I'm pretty sure.
As a solution I suggest you use TweetMoaSharp (a fork of TweetSharp). It has been updated to support the new Twitter API's for handling media in tweets, and it will work in this situation if you use the new stuff.
Basically you upload each media item using a new UploadMedia method, and that will return you a 'media id'. You then use the normal 'SendTweet' method and provide a list of the media ids to it along with the other status details. Twitter will attach the media to the tweet when it is posted, and it will work when there are both special characters and images.
In addition to TweetMoaSharp you can use Tweetinvi with the following code:
var binary = File.ReadAllBytes(#"C:\videos\image.jpg");
var media = Upload.UploadMedia(binary);
var tweet = Tweet.PublishTweet("hello", new PublishTweetOptionalParameters
{
Medias = {media}
});

Cancel a complete PNR

I'm writing a service which automtically cancels a PNR left on a certain queue. This sounds pretty straight forward with the OTA_CancelLLSRQ request, however it appears I have to loop through each segment individually, or is there a way I can cancell ALL segments at once?
In the application we defined a PNR class, this class contains all of the information we can obtain with the "" call.
To cancel the PNR I currently use the following code:
MessageHeader msgHeader = new MessageHeader
{
ConversationId = "TestSession",
CPAId = licenseId,
Action = "OTA_CancelLLSRQ",
Service = new Service { Value = "OTA_CancelLLSRQ" },
MessageData = new MessageData
{
MessageId = "xxx",
Timestamp = DateTime.UtcNow.ToString("s") + "Z"
},
From = new From()
{
PartyId = new PartyId[]
{
new PartyId { Value = "WebServiceClient"}
}
},
To = new To()
{
PartyId = new[]
{
new PartyId { Value = "WebServiceSupplier"}
}
}
};
var segmentList = new List<OTA_CancelRQSegment>();
foreach (var segment in pnrObject.Segments)
{
var requestSegment = new OTA_CancelRQSegment
{
Number = segment.SegmentNumber.ToString()
};
segmentList.Add(requestSegment);
}
var request = new OTA_CancelRQ()
{
Version = "2.0.0",
TimeStamp = DateTime.UtcNow,
TimeStampSpecified = true,
Segment = segmentList.ToArray()
};
OTA_CancelRS response = null;
Policy.Handle<SoapException>()
.Or<WebException>()
.WaitAndRetry(new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(1)
})
.Execute(() =>
{
using (OTA_CancelService serviceObj = new OTA_CancelService())
{
serviceObj.MessageHeaderValue = msgHeader;
serviceObj.Security = new Security1 { BinarySecurityToken = token };
response = serviceObj.OTA_CancelRQ(request);
}
});
It compiles & builds, but I haven't gotten around testing it just yet. :-)
In the documentation I found the following request:
<OTA_CancelRQ Version="2.0.0">
<Segment Type="entire"/>
</OTA_CancelRQ>
How do I encode this using the object model the webservice expects?
Steps for cancelling PNR is as follows.
STEP1: SessionCreateRQ
STEP2: TravelItineraryReadRQ
STEP3: OTA_CancelRQ
STEP4: EndTransactionRQ
STEP5: SessionCloseRQ
In case of SOAP SERVICES your request XML for STEP3 (i.e OTA_CancelRQ)will be as follows.
<OTA_CancelRQ EchoToken="String" TimeStamp="2001-12-17T09:30:47-05:00" Target="Production" Version="2003A.TsabreXML1.0.1" SequenceNmbr="1" PrimaryLangID="en-us" AltLangID="en-us" xmlns="http://webservices.sabre.com/sabreXML/2003/07" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<POS>
<Source PseudoCityCode="PCC"/>
</POS>
<TPA_Extensions>
<SegmentCancel Type="Entire">
</SegmentCancel>
</TPA_Extensions>
</OTA_CancelRQ>
I hope this will make your knowledge more clear.
You can specify "entire" type like the below to cancel the entire Itinerary of a PNR.
<OTA_CancelRQ Version="2.0.0">
<Segment Type="entire"/>
</OTA_CancelRQ>
here is the request part of my code in c#, hope this help add a refrence to proxy class for OTA_CancelRQ.
OTA_CancelRQ rq = new OTA_CancelRQ();
List<OTA_CancelRQSegment> segmentCancelList = new List<OTA_CancelRQSegment>();
OTA_CancelRQSegment segmentCancel = new OTA_CancelRQSegment();
OTA_CancelRQSegmentType segmentType = new OTA_CancelRQSegmentType();
segmentType = OTA_CancelRQSegmentType.entire;
segmentCancel.Type = segmentType;
segmentCancel.TypeSpecified = true;
segmentCancelList.Add(segmentCancel);
rq.Segment = segmentCancelList.ToArray();
Thanks.
cancelRQ.tPA_ExtensionsField = new CancelRequest.TPA_Extensions
{
segmentCancelField = new CancelRequest.TPA_Extensions.SegmentCancel
{
typeField = "Entire"
}
};
call OTA_CancelLLSRQ Perform a transaction after the original booking was completed (cancel the itinerary that was booked, in this case).

Updated Google Analytic API and older version

Before Google Analytic Update there api this code works.
string userName = GAEmailAddress.ToString();//Its From Database
string passWord = GAPassword.ToString();//Its From Database
const string dataFeedUrl = "https://www.google.com/analytics/feeds/data";
AccountQuery query = new AccountQuery();
AnalyticsService service = new AnalyticsService("AnalyticsApp");
if (!string.IsNullOrEmpty(userName))
{
service.setUserCredentials(userName, passWord);
}
string str = "";
try
{
AccountFeed accountFeed = service.Query(query);
foreach (AccountEntry entry in accountFeed.Entries)
{
str = entry.ProfileId.Value;
}
DataQuery query1 = new DataQuery(dataFeedUrl);
// Bounce Rate Calculations
query1.Ids = str;
query1.Metrics = "ga:visits,ga:bounces";//visitors
query1.Sort = "ga:visits";
query1.GAStartDate = DateTime.Now.AddMonths(-1).AddDays(-2).ToString("yyyy-MM-dd");
query1.GAEndDate = DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd");
query1.StartIndex = 1;
//Others code and other data for bound
I search in SO and and Find this link.
gapi account data url goes to 404
I replace this link :
const string dataFeedUrl = "https://www.google.com/analytics/feeds/data";
with:
https://www.googleapis.com/analytics/v2.4/management/accounts?start-index=1&max-results=100&key=API_KEY
But I still I gett error:
Execution of request failed: https://www.google.com/analytics/feeds/accounts/default
I still search and find this link:
https://developers.google.com/analytics/devguides/reporting/core/v2/#register
As link says I replace :
https://www.googleapis.com/analytics/v2.4/data
But still I got error ? What I am missing here? Thanks.

Http Passthrough Pluggable Protocol for Firefox

How can I make an http passthrough pluggable protocol for IE work in Firefox?
Alternatively, how to develop one for Firefox? Any examples would be appreciated.
Thanks.
On Firefox, if you would like to bypass a default behavior in a "pluggable" manner, you could write an NPAPI based plugin. Let's say that the documentation is thin on this subject... but to get you started, you could consult this.
With an NPAPI plugin, you have access to the whole OS and thus are free to expose any other resources to Firefox.
Write an XPCOM object that implements nsIObserver. Then create listener for http-on-modify-request and http-on-examine-response.
var myObj = new MyObserver(); //implements nsIObserver
var observerService = Components.classes["#mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.addObserver(myObj "http-on-modify-request", false);
observerService.addObserver(myObj, "http-on-examine-response", false);
Write an XPCOM object that implements nsIProtocolHandler. For example, you can access local images from web pages:
const Cu = Components.utils;
const Ci = Components.interfaces;
const Cm = Components.manager;
const Cc = Components.classes;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");+
Cu.import("resource://gre/modules/FileUtils.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");
/***********************************************************
class definition
***********************************************************/
function sampleProtocol() {
// If you only need to access your component from JavaScript,
//uncomment the following line:
this.wrappedJSObject = this;
}
sampleProtocol.prototype = {
classDescription: "LocalFile sample protocol",
classID: Components.ID("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"),
contractID: "#mozilla.org/network/protocol;1?name=x-localfile",
QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),
//interface nsIProtocolHandler
allowPort :function(port, scheme)
{
if ((port == 80)&&(scheme == x-localfile)) {
return true;
}
else
{
return false;
}
},
newChannel: function(aURI)
{
// Just example. Implementation must parse aURI
var file = new FileUtils.File("D:\\temp\\getImage.jpg");
var uri = NetUtil.ioService.newFileURI(file);
var channel = NetUtil.ioService.newChannelFromURI(uri);
return channel;
},
newURI(aSpec, aOriginCharset, aBaseURI)
{
//URI looks like x-localfile://example.com/image1.jpg
var uri = Cc["#mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI);
uri.spec = aSpec;
return uri;
},
scheme: "x-localfile",
defaultPort: 80,
protocolFlags: 76
};
var components = [sampleProtocol];
if ("generateNSGetFactory" in XPCOMUtils)
var NSGetFactory = XPCOMUtils.generateNSGetFactory(components); // Firefox 4.0 and higher
else
var NSGetModule = XPCOMUtils.generateNSGetModule(components); // Firefox 3.x
Be carefull! This approach can create vulnerability

Resources