简体   繁体   中英

simple WCF REST client - Add Service Reference bug?

I want to make a simple WCF Hello world client which could connect to a WCF REST service.

But I've got the following error:

"Could not find default endpoint element that references contract 'ServiceReference1.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."

What I did:

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

-My web.config is 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 started a new instance of my WCFerror service (via "Start Debugging"), it is hosted, I tried it out in a web browser ( like: http://localhost:58475/Service1.svc/GetData?value=4 ), it worked fine.

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

-So my client not works:

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

-I tried to run the svcutil via the command prompt like this:

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

But it generates the same empty app.config.

What did I do wrong? :(

Add Service Reference uses WSDL or WS-MetadataExchange. Both of these are SOAP constructs. REST does not have a metadata standard. You will have to roll the messages yourself, preferably using a framework. Have you looked at HttpClient that is part of the new Web API? Its available via Nuget

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM