I am trying to use the Despatch Bay shipping API within an ASP.NET application, but all their sample code is in PHP.
I've used web services before, but am having trouble passing the credentials to this.
The PHP sample code creates a new instance of the API as follows:
$soapOptions = array ('login' => APIUSER, 'password' => APIKEY);
$DespatchBay = new SoapClient("http://api.despatchbaypro.com/api/soap/v10/addressing?wsdl",$soapOptions);
Using Visual Web developer Express, I have added a service reference to my Project, and can now create an instance like this:
Dim dbService As New DespatchBayAddresses.AddressingServicePortTypeClient
And attempt to write out an address from a post code as follows:
Response.Write(dbService.GetDomesticAddressKeysByPostcode("INSERT POSTCODE").ToString())
But, quite naturally, I get an error:
The remote server returned an error: (401) Unauthorized.
I know why, because I haven't passed in my API_KEY
or API_USER
credentials.
But, I'm being dumb I am sure, but can't figure out how.
I tried
dbService.ClientCredentials.UserName.UserName = MY_USER
dbService.ClientCredentials.UserName.Password = MY_KEY
But same error. I need to be able to pass these values from a variable retrieved from my database, not a static value in web.config, so could someone please point me in the direction of getting these details to the API?
Thanks