Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call WCF service OperationContract from browser?

I created a WCF 4 web services and hosted it on my IIS 7, I gave the following Service URL: at publish web section in WCF project:

http://localhost:8084/service1.svc.

Then i bind my published web site on port:4567 and Type: http in IIS.

To checked it i clicked on `web site` at `IIS` and click on the browse. 
It open a following page at my browser:

enter image description here

It means that the web service is successfully hosted on IIS. Now i want to call my instances method and return the output at browser. Let me paste you the sample code of Iservice.cs and service.svc.cs

#Iservice.cs:
namespace some.decryption
{
[ServiceContract]
public interface Iservice
{
  [OperationContract, WebInvoke(Method = "GET", UriTemplate = "/getdata", ResponseFormat = WebMessageFormat.Json)]
    string getdata();
}}

Whereas my service.svc.cs:

public bool getdata()
    {
        return somenamespace.getfetcheddll();
    }

and serviceDll.cs:

  namespace somenamespace{
  internal static class UnsafeNativeMethods
   {
   _dllLocation = "some.dll";
   [DllImport(_dllLocation, CallingConvention = CallingConvention.Cdecl)]
   public static extern bool OnDecryption();
   }

  public static string getfetcheddll()
   {
       return UnsafeNativeMethods.OnDecryption();
   }}

how should i call getdata() method from browsers?

I have put the some.dll in the same project folder. Where should i do it?

Edit:

I have forgot to paste my web.config:

<?xml version="1.0"?>
<configuration>
<system.web>
 <compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
  <behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

To do this i followed this blog : walkthrough on creating

like image 432
Amit Pal Avatar asked Oct 05 '22 11:10

Amit Pal


1 Answers

By default - HTTP is translated into wsHttpBinding which is a SOAP service, so you cannot just call that from a browser. The ?wsdl suffix on the help page also seems to point in that direction.

For testing SOAP services, you need a SOAP-capable tool like the Microsoft WCF Test Client or SoapUI.

Try using the WCF Test Client - can you connect to your service at the URL shown on the help page with that tool? Do you see your service?

like image 82
marc_s Avatar answered Oct 13 '22 10:10

marc_s