Hi there,
I am trying to call a C# web service from an aspx page, I have the asmx
file, a user control file ascx and the aspx file. I have verified that the
web service is returning correct values from the service, however when I try
to load the aspx page it falls over in a cruumbling heap! Could someone tell
me what I am doing wrong as I know that I am close to getting this thing
working.
Thanks in advance for your answer
Sean
Error messages and source code below ------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.
Compiler Error Message: CS0246: The type or namespace name 'Service1' could
not be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 7: private void Button1_Click(o bject sender, System.EventArg s e)
Line 8: {
Line 9: Service1 currSvc = new Service1();
Line 10: double dRate = currSvc.Convers ionRate(currFro m.CurrencyCode,
currTo.Currency Code);
Line 11: if (dRate < 0)
Source File: e:\inetpub\wwwr oot\Currency1\c urrconv.aspx Line: 9
!--- aspx page
private void Button1_Click(o bject sender, System.EventArg s e)
{
Service1 currSvc = new Service1();
double dRate = currSvc.Convers ionRate(currFro m.CurrencyCode,
currTo.Currency Code);
if (dRate < 0)
lblConversion.T ext = "Error Occured";
else
lblConversion.T ext = "" + txtAmount.Text + " " + currFrom.Curren cyCode +
"(s) =" + Convert.ToStrin g(dRate * Convert.ToDoubl e(txtAmount.Tex t)) + " " +
currTo.Currency Code;
}
!--------------- web service
<%@ WebService Language="c#" Class="Currency NS.Service1" %>
using System;
using System.Web;
using System.Web.Serv ices;
using System.Net;
using System.IO;
using System.Text;
namespace CurrencyNS
{
[WebService]
public class Service1 : System.Web.Serv ices.WebService
{
[WebMethod]
public double ConversionRate( string From, string To)
{
HttpWebRequest req;
HttpWebResponse res;
StreamReader sr;
string strResult;
string fullpath;
char[] separator = {','} ;
double dRate=-1;
fullpath = "http://finance.yahoo.c om/d/quotes.csv?s=" + From + To +
"=X&f=sl1d1t1c1 ohgv&e=.csv";
try
{
req = (HttpWebRequest ) WebRequest.Crea te(fullpath);
res = (HttpWebRespons e) req.GetResponse ();
sr = new StreamReader(re s.GetResponseSt ream(), Encoding.ASCII) ;
strResult = sr.ReadLine();
sr.Close();
string[] temp = strResult.Split (separator) ;
if(temp.Length >1)
{
string strRate = temp[1];
//We only show the relevant portions .
dRate = Convert.ToDoubl e(strRate);
}
}
catch(Exception )
{
dRate = -1;
}
return dRate;
}
}
}