maaknplan
asked on
Building a Web Application to consume a WCF Service
I am following a WCF tutorial at http://msdn.microsoft.com/en-us/library/ms734712.aspx. The tutorial itself is straight forward and I have had no issues.
However I am trying to extend the tutorial to a web application, the code for the default.aspx is attached below.
I created the generateProxy.cs and app.Config file as per the tutorial, however when I start the service and try to debug the website, I get the following error:
InvalidOperationException was unhandled by user code
Could not find default endpoint element that references contract 'ICalculator' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element
Is there something different I need to do for a web application as opposed to a console application?
Thanks for any help.
However I am trying to extend the tutorial to a web application, the code for the default.aspx is attached below.
I created the generateProxy.cs and app.Config file as per the tutorial, however when I start the service and try to debug the website, I get the following error:
InvalidOperationException was unhandled by user code
Could not find default endpoint element that references contract 'ICalculator' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element
Is there something different I need to do for a web application as opposed to a console application?
Thanks for any help.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WCFTest._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>calculator test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtN1" Columns="4" runat="server"></asp:TextBox> +
<asp:TextBox ID="txtN2" Columns="4" runat="server"></asp:TextBox> =
<asp:TextBox ID="txtTotal" runat="server" Columns="8"></asp:TextBox>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
onclick="btnSubmit_Click" />
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WCFTest._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>calculator test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtN1" Columns="4" runat="server"></asp:TextBox> +
<asp:TextBox ID="txtN2" Columns="4" runat="server"></asp:TextBox> =
<asp:TextBox ID="txtTotal" runat="server" Columns="8"></asp:TextBox>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
onclick="btnSubmit_Click" />
</div>
</form>
</body>
</html>
protected void btnSubmit_Click(object sender, EventArgs e)
{
CalculatorClient client = new CalculatorClient();
double n1 = Convert.ToDouble(txtN1.Text);
double n2 = Convert.ToDouble(txtN2.Text);
double total = client.Add(n1, n2);
txtTotal.Text = string.Format("{0}", total);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
BTW: don't forget to call Close() on your client once finished :)