Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tests wcf service in the browser

I can't invoke a basic wcf web method in the browser even with <ServiceMetadata httpGetEnabled="True"/> in the config file.

For the source, code, it's very basic:

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 the implementation:

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

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

In the browser, when I call the http://localhost:54421/Service1.svc/GetData, it displays a blank page. How can I resolve this?

like image 282
Zakaria Avatar asked Dec 28 '25 01:12

Zakaria


1 Answers

I am doing that 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 your service definition add endpoint which is using this behavior

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

now you can call your service both from browser and from wcf client. To call it from browser:

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

ServiceMetadata is for different purpose here is link to documentation. Basically it means your service will expose information about itself so external developers can create proxy clients.

like image 138
bartosz.lipinski Avatar answered Dec 30 '25 13:12

bartosz.lipinski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!