sephora 0 Newbie Poster

I am trying to create a WCF service for a Windows mobile smart device using a tutorial that I found. It suggested that I go the way of using

netcfSvcUtil.exe intead of SvcUtil to generate the files that I would need. After writing the tutorial, I was successful in publising my service, but when I tried to get my client to use it it gave me the following error:-

{"There was no endpoint listening at http://localhost:8000/calculator that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details."} System.Exception {System.ServiceModel.EndpointNotFoundException}

The code for the service is

using System;

using System.ServiceModel;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace OpenNETCF.WCF.Sample

{

[ServiceContract(Namespace = "http://opennetcf.wcf.sample")]

 

public interface ICalculator

{

[OperationContract]

 

int Add(int a, int b);

}

}

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace OpenNETCF.WCF.Sample

{

 

public class CalculatorService : ICalculator

{

 

public int Add(int a, int b)

{

 

Console.WriteLine(string.Format(

 

"Received 'Add({0}, {1})' returning {2}", a, b, a + b));

 

return a + b;

}

}

using

 

System;

using

 

System.ServiceModel;

using

 

System.ServiceModel.Description;

using

 

System.Net;

namespace

 

OpenNETCF.WCF.Sample

{

 

public class Server

{

 

protected static Uri address;

 

protected static ServiceHost serviceHost;

 

static void Main(string[] args)

{

 

 

 

address = new Uri("http://localhost:8000/calculator");

 

serviceHost =

new ServiceHost(typeof(CalculatorService), address);

 

 

serviceHost.AddServiceEndpoint(typeof(ICalculator), new BasicHttpBinding(), address);

 

 

ServiceMetadataBehavior smb = new ServiceMetadataBehavior();

smb.HttpGetEnabled =

true;

serviceHost.Description.Behaviors.Add(smb);

serviceHost.Open();

 

Console.WriteLine(

 

"CalculatorService is running at " + address.ToString());

 

Console.WriteLine("Press <ENTER> to terminate");

 

Console.ReadLine();

 

// Close the ServiceHostBase to shutdown the service.

serviceHost.Close();

}

}

}

The following is my client.

using System;

using System.Linq;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.ServiceModel;

using SMC = System.ServiceModel.Channels;

using System.Runtime.Serialization;

using System.Drawing;

using System.Text;

using System.Net;

using System.Windows.Forms;

namespace WCFClient

{

 

public partial class Form1 : Form

{

 

 

public Form1()

{

InitializeComponent();

 

try{

localIP.Text =

Dns.GetHostEntry(

 

Dns.GetHostName()).AddressList[0].ToString();

}

 

catch (Exception ex)

{

 

MessageBox.Show("No NIC found?");

}

}

 

private void textBox1_TextChanged(object sender, EventArgs e)

{

}

 

private void button1_Click(object sender, EventArgs e)

{

 

MessageBox.Show("The button was clicked");

 

int a = 0;

 

int b = 0;

 

try

{

 

//a = int.Parse(localIP.Text);

 

//b = int.Parse(serviceAddress.Text);

a =

int.Parse(first.Text);

b =

int.Parse(second.Text);

}

 

catch

{

 

// parsing failed, just bail out

 

MessageBox.Show("parsing failed, just bail out");

 

return;

}

SMC.

Binding binding = CalculatorClient.CreateDefaultBinding();

 

string remoteAddress = CalculatorClient.EndpointAddress.Uri.ToString();

 

//remoteAddress = remoteAddress.Replace("localhost", serviceAddress.Text);

 

EndpointAddress endpoint = new EndpointAddress(remoteAddress);

 

CalculatorClient client = new CalculatorClient(binding, endpoint);

 

try

{

answer.Text = client.Add(a, b).ToString();

}

 

catch (Exception ex)

{

 

MessageBox.Show(ex.Message);

}  

 

}

 

private void Form1_Load(object sender, EventArgs e)

{

}

}

}

Can someone please tell me how to solve this error...thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.