WCF REST Simple Client - Add Service Link Error?

I want to create a simple WCF Hello World client that can connect to the WCF REST service.

But I have the following error:

"Could not find the default endpoint element that refers to the ServiceReference1.IService1 contract in the ServiceModel client configuration section. This may be because the configuration file was not found for your application or because no endpoint element matched this contract cannot be found in the client element. "

What I've done:

-I created a new project called "WCFerror" with the template "WCF Service Application"

-My web.config looks like this: http://pastebin.com/KEGqRgPr

-My service interface is also simple:

[ServiceContract] public interface IService1 { [OperationContract] [WebGet(UriTemplate = "GetData?value={value}", ResponseFormat = WebMessageFormat.Json)] string GetData(int value); } 

-I created a new console application.

-I launched a new instance of my WCFerror service (via "Start Debugging"), it is hosted, I tried it in a web browser (for example: http://localhost:58475/Service1.svc/GetData?value=4 ), it worked fine.

-Then I added a service link to the Console application (address: http://localhost:58475/Service1.svc ), and in the background svcutil generated client code and app.config - but empty app.config!

- My client does not work:

 ServiceReference1.Service1Client client = new ServiceReference1.Service1Client(); Console.WriteLine(client.GetData(4)); 

-I tried to run svcutil through the command line as follows:

 svcutil.exe /language:cs /out:GeneratedProxy.cs /config:app.config http://localhost:58475/Service1.svc 

But it generates the same empty app.config file.

What did I do wrong?: (

+4
source share
1 answer

Add Service Reference uses WSDL or WS-MetadataExchange. Both are SOAP constructs. REST does not have a metadata standard. You will have to manually send messages, preferably using the framework. Have you looked at the HttpClient, which is part of the new web API? Accessed via Nuget

+5
source

Source: https://habr.com/ru/post/1412171/


All Articles