Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is possible to access WCF Service without adding Service Reference?

Tags:

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;
}
like image 453
User Avatar asked Oct 30 '13 06:10

User


People also ask

How can I access WCF service?

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.

What is a WCF service reference?

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.

How do I change my WCF service reference?

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.


2 Answers

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.

like image 93
Thilina H Avatar answered Oct 01 '22 08:10

Thilina H


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

like image 21
wizzardz Avatar answered Oct 01 '22 09:10

wizzardz