Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

paramaterising a webservice call

Status
Not open for further replies.

Sarky78

Programmer
Oct 19, 2000
878
GB
Hi all,

Hoping someone will be able to help me with this. i am trying to use a webservice to get the conversion rate between currencies. this is the service:


now i have manaed to get the service working with hard coded values:

Code:
            CurrencyConvert.CurrencyConvertor currencyService = new CurrencyConvert.CurrencyConvertor();
            currencyService.ConversionRate(Currency.CurrencyConvert.Currency.GBP, Currency.CurrencyConvert.Currency.USD);

but i want to be able to paramaterise it. i have tried casting, concatenating and trying to use new on the currency.currencyconvert method but nothing.

Can anyone help me? i want to be able to do something like:

Code:
CurrencyConvert.CurrencyConvertor currencyService = new CurrencyConvert.CurrencyConvertor();

string conFrom = "GBP";
string conTo = "USD";

currencyService.ConversionRate(conFrom,conTo);


Anyone got any ideas?

Thanks in advance

Tony
 
hey,

The error that i get when i try and use conFrom/conTo is:

Argument '1': cannot convert from 'string' to 'Currency.CurrencyConvert.Currency'

So what i need is someway of being able to define this. i thought of using a load of if statements but we are looking to use about 20 currency types so i don't think this will be that efficient.

thanks

Tony
 
Not sure why you need to parameterize this, but, you would have to conver the type. I guess you can load the types into an enum of that type, but I'm not sure of anything you would gain by this.
 
I'm guessing Currency.CurrencyConvert.Currency is an enum. this that case you need to parse the text (or value) to the enum type.
Code:
var currency = (Currency)Enum.Parse(typeof(Currency), "GBP");
you would do something very similar if you passed the numeric value of the enum rather than the text.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
>currencyService.ConversionRate(conFrom,conTo);

[1] You should capture the return value say xrate.
[2] Use the Parse of Enum of type Currency, like this.
[tt]
double xrate=currencyService.ConversionRate(
(CurrencyConvert.Currency)Enum.Parse(typeof(CurrencyConvert.Currency),conFrom),
(CurrencyConvert.Currency)Enum.Parse(typeof(CurrencyConvert.Currency),conTo));
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top