The ABR web service is handy, but it has a really annoying hidden gotcha.
Say you are doing a search of some kind with the REST style url...
ABRXMLSearch.asmx/ABRSearchByNameAdvancedSimpleProtocol2006?name=steve&postcode=&legalName=&tradingName=&NSW=&SA=&ACT=&VIC=&WA=&NT=&QLD=&TAS=&authenticationGuid=&searchWidth=&minimumScore=&maxSearchResults=
... will work, but should you not pass in some of the query params it breaks messily...
For instance:
ABRXMLSearch.asmx/ABRSearchByNameAdvancedSimpleProtocol2006?name=steve
Surely you can make it so you don't have to pass in everything!
Them:
Thanks for the feedback. As you are no doubt aware, web methods cannot be defined with optional input parameters. Therefore if you call the web method and omit some parameters then you will probably get a HTTP 500 error. I guess the theory is that web services are called from within an application and therefore ensuring the correct and complete parameter list is always supplied by the web service consumer is not such a big deal as when you have to type it by hand.
Me (to self):
WTF. You obviously are pulling my leg you lazy government red tape machine. I know: I'll google up a basic how-to-build-web-services tutorial in C# and paste it to you. Hah! That'll show you.
At this point, I ran into troubles, not knowing enough of C#'s standard ways of doing things to save my life.
Me to IRC:
Q: What am I trying to find on MSDN
(much confusion and milling about)
A: You are looking for WebMethods
A: You are looking for Overloading methods to supply default arguments
Q: AH! I remember using a language that made me do that once. So I should be able to do...?
//Tacky, Tacky psuedocode
[WebMethod]
void KillAllHumans(int N) {
KillAllHumans(N, true);
}
void KillAllHumans(int N, bool everybody) {
/* Get all Dalek on somebody's ass*/
}
A: Yes
A: No
A: We're confused.
A: Use properties!
Q: Like this?
// dalek.aspx?method=KillAllHumans&N=1000
class Dalek {
private int n;
public int N {
get { return x; }
set { if (value == null) { x = 99; } else { x = value; } }
}
private bool every1;
public bool every1 {
get { return x; }
set { if (value == null) { x = true; } else { x = value; } }
}
[WebMethod]
public void KillAllHumans() {
//Magically inspect the request varibles / web method arguments
//and try to set all of Dalek's properties
//this.N = MagicallyGetArgument("N");
//this.every1 = MagicallyGetArgument("every1");
//Get all whoopass on Dr Who.
}
}
A: *Silence...*
How the hell do you (if at all) do this, and if you can't, why the fuck not! What kind of retarded design decision is it to be so very narrow in defining what you can take in?
So off I go to read MSDN. Voila.
public class Service1 : System.Web.Services.WebService
{
[System.Web.Services.WebMethod(MessageName="AddDoubles")]
public double Add(double dValueOne, double dValueTwo)
{
return dValueOne + dValueTwo;
}
[System.Web.Services.WebMethod(MessageName="AddIntegers")]
public int Add(int iValueOne, int iValueTwo)
{
return iValueOne + iValueTwo;
}
}
So it is possible. Somewhat. But it's still shocking.
But most annoying, are the helpful drunks:
sabiancrash: right now your trying to build a house with a screwdriver
sabiancrash: you need to learn more tools
sabiancrash: suppose i wanted to get to florida
sabiancrash: and the only way i knew how was walking
sabiancrash: would i get to florida?
sabiancrash: sure, but it should would take me longer and be a lot more inefficient than if i explored other alternatives
sabiancrash: c# is really powerful, don't just look for quick hacks
sabiancrash: what i would like to see is a searcher class
sabiancrash: that you can instance and set some properties
sabiancrash: and then call a method and it can return results in a way you want
sabiancrash: that way you only write the code once
sabiancrash: and if you need to change it you can update it in a single location
sabiancrash: but you can utilize it everywhere
Rrr. That's... really nice, but I'm not trying to build a web service, I'm trying to find out why it's "impossible" make WebMethods that are human friendly. I told you that at the start.
Trying... not to stab... people with aforementioned... screwdriver.
No comments:
Post a Comment