0
votes

I got this error:

There was no endpoint listening at http://vkalra.in/WCF_SERVICE/RestServiceImpl.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details
InnerException-The remote server returned an error: (404) Not Found.

This is my code:

Binding binding = new BasicHttpBinding();

// Create endpointAddress of the Service
EndpointAddress endpointAddress = new  EndpointAddress("http://vkalra.in/WCF_SERVICE/RestServiceImpl.svc");

ServiceReference1.Leave_Details emp = new ServiceReference1.Leave_Details();
emp.empid = items.empid;
emp.fromdate = "01-04-2019";
emp.todate = "04-06-2019";
emp.tabt = "1";
emp.jdis = "0";

try
{
    ServiceReference1.RestServiceImplClient service = new ServiceReference1.RestServiceImplClient(binding, endpointAddress);
    string levbal = service.Leave_Calculation(emp);
}
catch(Exception ex)
{
}
1
You need to provide a LOT more context and information here!! One thing that stands out: you're using BasicHttpBinding which is the basic SOAP binding, but the URL you're trying to contact seems to be REST - those two don't match, you need to use WebHttpBinding to talk to a REST endpoint.....marc_s
Please provide me some example to get data from rest service in our controller in service Leave_Calculation is method which take 5 parameter and return string data i am new in WCF service?jugal

1 Answers

0
votes

If we want to consume the WCF service created by WebHttpBinding(this type of the WCF service is also called Restful service) by adding service reference, we need to do something special. Generally speaking, if we want to call Restful service (such as the service created by Asp.net WebAPI), we could construct a http request, Get or Post with a request body, then send to the specified service address.
https://code-maze.com/different-ways-consume-restful-api-csharp/
https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/calling-a-web-api-from-a-net-client
This also applies to WCF service created by WebHttpBinding.
consuming a WCF service using simple HttpClient class
But if we want to consume the WCF restful service by adding the service reference, we are supposed to maintain the consistency of binding between the client and server. we should add [WebGet]/[WebInvoke] to the auto-generated method of the service interface, which comes in the form of adding service reference, located in Reference.cs file.
One more thing we need do is add Webhttpbehavior (endpoint behavior) to the client service endpoint. This client configuration comes in the form with adding service reference, located in the System.ServiceModel section of the app.config/web.config.
The remote server returned an unexpected response: (400) Bad Request. wcf
Feel free to let me know if there is anything I can help with.