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: CS0103: The name 'getProduct' does not exist in the current context
Source Error:
Line 7: else Line 8: { Line 9: var product = getProduct.GetProduct(price); Line 10: Json.Write(product, Response.Output); Line 11: }
Source File: c:\Documents and Settings\ininsuma\My Documents\My Web Sites\WebServices\Page2.cshtml
Line: 9
My Directory structure is in this way :
->Webservices
-> App_Code
->Page.cshtml
->App_Data
->webservices.sdf
->page2.cshtml
Code in
page.cshtml :
@functions {
public class Product
{
public string Name {get; set;}
public int Price {get; set;}
}
public static Product GetProduct(string price) {
var db = Database.Open("WebServices");
var selectQueryString = "SELECT Name, price FROM FirstTable WHERE Price >= " + @price;
var data = db.Query(selectQueryString);
Product product = new Product();
foreach (var row in data) {
product.Name = @row.Name;
product.Price = @row.Price;
}
return product;
}
}
page2.cshtml:
@{
var price = Request.QueryString["price"];
if (price == null || price == string.Empty)
{
<p>Please enter a Price value</p>
}
else
{
actual problem was i need to use following line in this way
correct way to use :
var product = Page.GetProducts(price);
"Page" is my file in which I have GetProducts function.
Ex : filename.functionname(arg);
but after that chnaging iam getting another error :
Cannot perform runtime binding on a null reference
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
Source Error:
Line 9: { Line 10: Line 11: var Product = Page.GetProducts(price); Line 12: Json.Write(Product, Response.Output); Line 13: }
Source File: c:\Documents and Settings\ininsuma\My Documents\My Web Sites\WebServices\Page2.cshtml Line: 11
sumanthmara
Member
8 Points
5 Posts
Creating webservices using webmatrix
Sep 14, 2011 10:11 AM|LINK
Hi all,
I followed below link to develop webservice .As iam completey new for this kind of environment.
http://www.microsoft.com/web/post/creating-a-webservice-with-webmatrix-and-consuming-it-with-a-windows-7-phone-application
Iam getting following error :
Server Error in '/' Application.
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: CS0103: The name 'getProduct' does not exist in the current context
Source Error:
Source File: c:\Documents and Settings\ininsuma\My Documents\My Web Sites\WebServices\Page2.cshtml Line: 9
My Directory structure is in this way :
->Webservices
-> App_Code
->Page.cshtml
->App_Data
->webservices.sdf
->page2.cshtml
Code in
page.cshtml :
@functions {
public class Product
{
public string Name {get; set;}
public int Price {get; set;}
}
public static Product GetProduct(string price) {
var db = Database.Open("WebServices");
var selectQueryString = "SELECT Name, price FROM FirstTable WHERE Price >= " + @price;
var data = db.Query(selectQueryString);
Product product = new Product();
foreach (var row in data) {
product.Name = @row.Name;
product.Price = @row.Price;
}
return product;
}
}
page2.cshtml:
@{
var price = Request.QueryString["price"];
if (price == null || price == string.Empty)
{
<p>Please enter a Price value</p>
}
else
{
var product = getProduct.GetProducts(price);
Json.Write(product, Response.Output);
}
}
Mikesdotnett...
All-Star
155593 Points
19979 Posts
Moderator
MVP
Re: Creating webservices using webmatrix
Sep 14, 2011 12:33 PM|LINK
Looks like a typo in the tutorial to me. Try the following:
@{ var price = Request.QueryString["price"]; if (price == null || price == string.Empty) { <p>Please enter a Price value</p> } else { var product = Product.GetProducts(price); Json.Write(product, Response.Output); } }Web Pages CMS | My Site | Twitter
sumanthmara
Member
8 Points
5 Posts
Re: Creating webservices using webmatrix
Sep 15, 2011 06:50 AM|LINK
Hi,
Thanks for reply.
actual problem was i need to use following line in this way
correct way to use :
Cannot perform runtime binding on a null reference
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
Source Error:
Line 9: {Line 10:
Line 11: var Product = Page.GetProducts(price);
Line 12: Json.Write(Product, Response.Output);
Line 13: }
Source File: c:\Documents and Settings\ininsuma\My Documents\My Web Sites\WebServices\Page2.cshtml Line: 11
Stack Trace:
Mikesdotnett...
All-Star
155593 Points
19979 Posts
Moderator
MVP
Re: Creating webservices using webmatrix
Sep 15, 2011 03:06 PM|LINK
Change it to prevent collisions with the Page object. You should also check to see if any data is returned.
Web Pages CMS | My Site | Twitter