Reputation: 9080
I have created a simple WCF by following several tutorials. I have modified my web.config file to add the endpoint (whatever that is). I added a ServiceReference to my solution... Now I just want to call the darn thing to see if it works...
I found this code when I viewed the service in the browser:
ServiceClient client = new ServiceClient();
// Use the 'client' variable to call operations on the service.
// Always close the client.
client.Close();
But when I plug it into my default.aspx on my website I get errors:
The type or namespacen anme 'ServiceClient' could not be found. All I want to do is call it to see how I reference the method (with parameters) and how it returns the data. I just need a jumping point to start working with WCF.
Please help.
Answered!
SnOrfus - His answer did the trick. As soon as I added the ServiceReference to the project then when I hovered over the client variable it prompted me to add ServiceReference name (which was ServiceReference1).
I was then able to call my method and display the results.
Thanks!
Upvotes: 0
Views: 1384
Reputation: 17909
When you added the Service Reference, what namespace did you type in ?
Normally, to access it via code you'd just have to use code that looks like this:
NameSpace.ClientName client = new NameSpace.ClientName();
Upvotes: 0
Reputation: 17196
What is your service interface called and what namespace did you give it when you added it? For instance, if you defined it thusly:
[OperationContract]
public interface IMyService
{
[OperationMethod]
void MyServiceMethod();
}
public class MyService : IMyService
{
}
if you imported it using the Add Service Reference dialog and gave it a namespace of JeffService... it would look like:
var client = new JeffService.MyServiceClient();
client.MyServiceMethod();
client.Close();
Upvotes: 3