Friday, June 25, 2010

Access WCF Service by WEBGet from Browser

If you want to expose a simple web service (WCF) so that it can be accessed by a web get or browser you need to first insure that the input and output are simple data types like strings or integers.

1.Create the web site project

2.  Add a reference to System.ServiceModel.Web (so we can access the WebGet decleration.

3.  Add your function and decerate it with the following;

<OperationContract()> _
    <WebGet()> _
    Function Dosmothing(ByVal pValue As String) As String

4.  Add the following to your web.config file;

        <add name="HttpGet"/>
        <add name="HttpPost"/>


5.  Update your service model to reflect the one below. 

    <behavior name="NewBehavior">
     <webHttp />
    <behavior name="my.Application.Behavior1">
     <serviceMetadata httpGetEnabled="true" />
     <serviceDebug includeExceptionDetailInFaults="false" />
   <service behaviorConfiguration="Behavior1"
    <endpoint behaviorConfiguration="NewBehavior" binding="webHttpBinding"
     bindingConfiguration="" contract="myInterface" />

6.Now you can access the function like this;


No comments: