in the c...">

Tests wcf service in browser

I cannot invoke the basic wcf web method in the browser even with <ServiceMetadata httpGetEnabled="True"/>in the configuration file.

For source code, this is very simple:

For the interface:

[ServiceContract]
    public interface IService1
    {

        [OperationContract]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
        string GetData();

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        // TODO: ajoutez vos opérations de service ici
    }

And for implementation:

 public string GetData()
        {
            return ("{'code':'yes'}");
        }

This method works fine in visual studio wcf built-in service test and returns {'code':'yes'}.

In the browser, when I call http://localhost:54421/Service1.svc/GetData, a blank page is displayed. How can i solve this?

+3
source share
3 answers

I do this by creating additional endpoint behavior for REST calls, so I can have different clients. Take a look at this configuration:

  <endpointBehaviors>
    <behavior name="RESTFriendly">
      <webHttp />
    </behavior>
  </endpointBehaviors>

in the service definition add an endpoint that uses this behavior

<endpoint address="/easy" behaviorConfiguration="RESTFriendly" ...

, wcf-. :

http://localhost:54421/Service1.svc/easy/GetData

ServiceMetadata . , , -.

+1

json . , ( ), .

Firefox, JSON -.

Google Chrome, Pretty JSON

+1
0
source

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


All Articles