Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 30th, 2005, 12:05 PM
Registered User
 
Join Date: Oct 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help with a web service

Hi,

I've just started learning to create/consume web services using VS2005 and C#. I've written a program that consumes this service:http://www.webservicex.net/CurrencyConvertor.asmx

Code:
namespace SOAPDemo
{
    class MyService
    {
        static void Main(string[] args)
        {

            ConvertorService.CurrencyConvertor _Service = 
                new ConvertorService.CurrencyConvertor();

            String s1 = "USD";
            String s2 = "QAR";

            double rate = _Service.ConversionRate(
                SOAPDemo.ConvertorService.Currency.USD,
                SOAPDemo.ConvertorService.Currency.QAR); 

            Console.WriteLine( "The current rate is : " + rate );
            Console.ReadKey();

        }
    }
}
As you can see the remote method "ConversionRate" only accepts parameters of type "ConvertorService.Currency.xxx". But I want to take the parameters as inputs from the user which will be stored in the form of strings. So how can I pass them to the method??

This is my first program and I'm really new to this.

Any sorta help wud be gr8ly appreciated.

________________________
There is no patch for ignorance
 
Old January 2nd, 2006, 04:27 PM
Registered User
 
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

as you noticed already, you need some way to convert from the userinput-type (string), to the webservices' Currency-type (an enumeration to be precise).

For this, you can use the Parse-method of the Enum-type

ps: also note the line "using CurrencyConvertorWebServiceDemo.ConvertorService;" so you don't need to explicitly name the namespace throughout your code all the time.

hth,
michaël

using System;
using CurrencyConvertorWebServiceDemo.ConvertorService;

namespace CurrencyConvertorWebServiceDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            CurrencyConvertor _Service = new CurrencyConvertor();

            String s1 = "USD";
            String s2 = "QAR";

            Currency fromCurrency = String2Currency(s1);
            Currency toCurrency = String2Currency(s2);

            double rate = _Service.ConversionRate(fromCurrency, toCurrency);

            Console.WriteLine("The current rate is : " + rate);
            Console.ReadKey();
        }

        private static Currency String2Currency(string currency)
        {
            return (Currency) Enum.Parse(typeof(Currency), currency, true);
        }
    }
}






Similar Threads
Thread Thread Starter Forum Replies Last Post
Web Service Consuming another web service CraigWhitfield EJB 0 January 10th, 2008 08:38 AM
web service ajaytiwarilic ASP.NET 2.0 Basics 0 February 24th, 2007 10:40 AM
Web Service kumanan ASP.NET 1.0 and 1.1 Basics 0 December 7th, 2006 10:26 AM
Error to Add Web Reference from a Web service jdjbarrios ASP.NET 2.0 Professional 0 July 18th, 2006 02:58 PM
Service Oriented Web Service aldwinenriquez .NET Web Services 2 September 15th, 2005 03:25 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.