Server Error in '/' Application - Novice

  • Thread starter Thread starter sean
  • Start date Start date
S

sean

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(object sender, System.EventArgs e)
Line 8: {
Line 9: Service1 currSvc = new Service1();
Line 10: double dRate = currSvc.ConversionRate(currFrom.CurrencyCode,
currTo.CurrencyCode);
Line 11: if (dRate < 0)

Source File: e:\inetpub\wwwroot\Currency1\currconv.aspx Line: 9




!--- aspx page

private void Button1_Click(object sender, System.EventArgs e)
{
Service1 currSvc = new Service1();
double dRate = currSvc.ConversionRate(currFrom.CurrencyCode,
currTo.CurrencyCode);
if (dRate < 0)
lblConversion.Text = "Error Occured";
else
lblConversion.Text = "" + txtAmount.Text + " " + currFrom.CurrencyCode +
"(s) =" + Convert.ToString(dRate * Convert.ToDouble(txtAmount.Text)) + " " +
currTo.CurrencyCode;

}

!--------------- web service


<%@ WebService Language="c#" Class="CurrencyNS.Service1" %>
using System;
using System.Web;
using System.Web.Services;
using System.Net;
using System.IO;
using System.Text;
namespace CurrencyNS
{
[WebService]
public class Service1 : System.Web.Services.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.com/d/quotes.csv?s=" + From + To +
"=X&f=sl1d1t1c1ohgv&e=.csv";

try
{
req = (HttpWebRequest) WebRequest.Create(fullpath);
res = (HttpWebResponse) req.GetResponse();
sr = new StreamReader(res.GetResponseStream(), 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.ToDouble(strRate);

}
}
catch(Exception )
{
dRate = -1;
}
return dRate;
}
}

}
 
try instantiating Service1 as below in Button1_Click(object sender,
System.EventArgs e) as below.

CurrencyNS.Service1 currSvc = new CurrencyNS.Service1();

Ur code will look some thing like...

private void Button1_Click(object sender, System.EventArgs e)
{
CurrencyNS.Service1 currSvc = new CurrencyNS.Service1();
double dRate = currSvc.ConversionRate(currFrom.CurrencyCode,
currTo.CurrencyCode);
if (dRate < 0)
lblConversion.Text = "Error Occured";
else
lblConversion.Text = "" + txtAmount.Text + " " + currFrom.CurrencyCode
+
"(s) =" + Convert.ToString(dRate * Convert.ToDouble(txtAmount.Text)) +
" " +
currTo.CurrencyCode;
}

HTH

sswalia
MCSD, MCAD, OCA


sean said:
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(object sender, System.EventArgs e)
Line 8: {
Line 9: Service1 currSvc = new Service1();
Line 10: double dRate = currSvc.ConversionRate(currFrom.CurrencyCode,
currTo.CurrencyCode);
Line 11: if (dRate < 0)

Source File: e:\inetpub\wwwroot\Currency1\currconv.aspx Line: 9




!--- aspx page

private void Button1_Click(object sender, System.EventArgs e)
{
Service1 currSvc = new Service1();
double dRate = currSvc.ConversionRate(currFrom.CurrencyCode,
currTo.CurrencyCode);
if (dRate < 0)
lblConversion.Text = "Error Occured";
else
lblConversion.Text = "" + txtAmount.Text + " " + currFrom.CurrencyCode +
"(s) =" + Convert.ToString(dRate * Convert.ToDouble(txtAmount.Text)) + " " +
currTo.CurrencyCode;

}

!--------------- web service


<%@ WebService Language="c#" Class="CurrencyNS.Service1" %>
using System;
using System.Web;
using System.Web.Services;
using System.Net;
using System.IO;
using System.Text;
namespace CurrencyNS
{
[WebService]
public class Service1 : System.Web.Services.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.com/d/quotes.csv?s=" + From + To +
"=X&f=sl1d1t1c1ohgv&e=.csv";

try
{
req = (HttpWebRequest) WebRequest.Create(fullpath);
res = (HttpWebResponse) req.GetResponse();
sr = new StreamReader(res.GetResponseStream(), 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.ToDouble(strRate);

}
}
catch(Exception )
{
dRate = -1;
}
return dRate;
}
}

}
 
Hi there,

I tried to add the code as you recommended CurrencyNS.Service1 currSvc = new
CurrencyNS.Service1(); the program still give me an error. I have pasted the
code from the aspx page into the post, could you tell me if I am missing
something?

Sean

!----------------------------------------------

<%@ Import Namespace="System.Drawing" %>

<%@ Register TagPrefix="uc1" TagName="CurrCodes" Src="currcodes.ascx" %>


<script Language="C#" runat="server">
private void Button1_Click(object sender, System.EventArgs e)
{
CurrencyNS.Service1 currSvc = new CurrencyNS.Service1();
double dRate = currSvc.ConversionRate(currFrom.CurrencyCode,
currTo.CurrencyCode);
if (dRate < 0)
lblConversion.Text = "Error Occured";
else
lblConversion.Text = "" + txtAmount.Text + " " + currFrom.CurrencyCode +
"(s) =" + Convert.ToString(dRate * Convert.ToDouble(txtAmount.Text)) + " " +
currTo.CurrencyCode;

}
</script>
<html>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<form id="Form1" method="post" runat="server">
<table style="WIDTH: 685px; HEIGHT: 160px">
<tr>
<td colspan="2" align="left"><asp:Label id="Label4" runat="server"
Font-Bold="True">Currency Conversion Tool</asp:Label></td>
</tr>
<tr>
<td style="WIDTH: 269px"><asp:Label id="Label1" runat="server"
Width="193px">Convert From:</asp:Label></td>
<td><uc1:CurrCodes id="currFrom" runat="server"></uc1:CurrCodes></td>
</tr>
<tr>
<td style="WIDTH: 269px"><asp:Label id="Label2" runat="server"
Width="177px">Convert To:</asp:Label></td>
<td><uc1:CurrCodes id="currTo" runat="server"></uc1:CurrCodes></td>
</tr>
<tr>
<td style="WIDTH: 269px"><asp:Label id="Label3" runat="server"
Width="155px">Amount:</asp:Label></td>
<td><asp:TextBox id="txtAmount" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" align="middle"><asp:Button id="Button1" runat="server"
Text="Convert" OnClick="Button1_Click"></asp:Button></td>
</tr>
<tr>
<td colspan="2" align="middle"><asp:Label id="lblConversion" runat="server"
Width="451px"></asp:Label></td>
</tr>
</table>
</form>
</body>
</html>





SSW said:
try instantiating Service1 as below in Button1_Click(object sender,
System.EventArgs e) as below.

CurrencyNS.Service1 currSvc = new CurrencyNS.Service1();

Ur code will look some thing like...

private void Button1_Click(object sender, System.EventArgs e)
{
CurrencyNS.Service1 currSvc = new CurrencyNS.Service1();
double dRate = currSvc.ConversionRate(currFrom.CurrencyCode,
currTo.CurrencyCode);
if (dRate < 0)
lblConversion.Text = "Error Occured";
else
lblConversion.Text = "" + txtAmount.Text + " " + currFrom.CurrencyCode
+
"(s) =" + Convert.ToString(dRate * Convert.ToDouble(txtAmount.Text)) +
" " +
currTo.CurrencyCode;
}

HTH

sswalia
MCSD, MCAD, OCA


sean said:
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(object sender, System.EventArgs e)
Line 8: {
Line 9: Service1 currSvc = new Service1();
Line 10: double dRate = currSvc.ConversionRate(currFrom.CurrencyCode,
currTo.CurrencyCode);
Line 11: if (dRate < 0)

Source File: e:\inetpub\wwwroot\Currency1\currconv.aspx Line: 9




!--- aspx page

private void Button1_Click(object sender, System.EventArgs e)
{
Service1 currSvc = new Service1();
double dRate = currSvc.ConversionRate(currFrom.CurrencyCode,
currTo.CurrencyCode);
if (dRate < 0)
lblConversion.Text = "Error Occured";
else
lblConversion.Text = "" + txtAmount.Text + " " + currFrom.CurrencyCode +
"(s) =" + Convert.ToString(dRate * Convert.ToDouble(txtAmount.Text)) + "
"
+
currTo.CurrencyCode;

}

!--------------- web service


<%@ WebService Language="c#" Class="CurrencyNS.Service1" %>
using System;
using System.Web;
using System.Web.Services;
using System.Net;
using System.IO;
using System.Text;
namespace CurrencyNS
{
[WebService]
public class Service1 : System.Web.Services.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.com/d/quotes.csv?s=" + From + To +
"=X&f=sl1d1t1c1ohgv&e=.csv";

try
{
req = (HttpWebRequest) WebRequest.Create(fullpath);
res = (HttpWebResponse) req.GetResponse();
sr = new StreamReader(res.GetResponseStream(), 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.ToDouble(strRate);

}
}
catch(Exception )
{
dRate = -1;
}
return dRate;
}
}

}
 
Back
Top