I need to access Wcf service methods without adding Service Reference?how to do this?
Step 1:I create a WCF Service.
Step 2:Add Service Reference to my application.
Step 3:And Access the WCF Service methods into app.
like this way,
ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client();
protected void Button1_Click(object sender, EventArgs e)
{
UserDetails userInfo = new UserDetails();
userInfo.UserName = TextBoxUserName.Text;
userInfo.Password = TextBoxPassword.Text;
userInfo.Country = TextBoxCountry.Text;
userInfo.Email = TextBoxEmail.Text;
string result = obj.InsertUserDetails(userInfo);
LabelMessage.Text = result;
}
With the service running, right click the project that will contain the WCF client proxy and select Add > Service Reference. In the Add Service Reference Dialog, type in the URL to the service you want to call and click the Go button. The dialog will display a list of services available at the address you specify.
The WCF Web Service Reference tool retrieves metadata from a web service in the current solution, on a network location, or from a WSDL file, and generates a source file containing Windows Communication Foundation (WCF) client proxy code that your . NET app can use to access the web service.
In Solution Explorer, right-click the name of the project to which you want to add the service, and then click Add Service Reference. The Add Service Reference dialog box appears. Click Discover. All services (both WCF Data Services and WCF services) in the current solution are added to the Services list.
You can use as follows. Just make sure to add the Service contract reference.
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress("http://localhost:4684/Service1.svc");
ChannelFactory factory = new ChannelFactory<ServiceContract>(binding, address);
ServiceContract channel = factory.CreateChannel();
string resturnmessage = channel.YourMethod("test");
From here you can get fully workout regarding on that.
Yes, it is possible to invoke as WCF service without adding a service reference.
As a first step, I assume that you have your service contact interface as a separate class library.
Step 2: Create your WCF service and host it in IIS
Step 3: Refer your service contract library in the client application and then follow this code
ChannelFactory<IYourServiceContract> factory = new ChannelFactory<IYourServiceContract>("EndpointNameOfYourService");
factory.Endpoint.Address = new EndpointAddress("http://example.com/service");
IYourServiceContract client = factory.CreateChannel();
var result = client.YourMethodtoInvoke(serviceArguments);
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With