WCF/WF - Consume WCF Service return JSON from a web application codebehind only (No JQUERY)

Asked By ananda shankar on 20-Apr-13 03:19 AM

Hi ,

I am facing some problem in consuming a function written in a WCF service (returning JSON string) from a web application code behind. (added the wcf service as service reference to this web application).

Here is my wcf service web.config

<system.serviceModel>

<services>
<service name="Tranzila.wcfVendingWeb" behaviorConfiguration="DefaultBehavior">

   <endpoint name="HttpsEP" address="" behaviorConfiguration="AjaxBehavior" binding="webHttpBinding" bindingConfiguration="webBindingHTTPS" contract="Tranzila.IwcfVendingWeb">
    </endpoint>

<endpoint contract="IMetadataExchange" binding="mexHttpsBinding" address="mex" />

</service>
</services>


<behaviors>

<serviceBehaviors>
<behavior name="DefaultBehavior">
    <serviceMetadata httpGetEnabled="false" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>

<endpointBehaviors>
<behavior name="AjaxBehavior">
<!--<enableWebScript />-->
<webHttp/>
</behavior>
</endpointBehaviors>

</behaviors>

<bindings>
  <webHttpBinding>

<binding name="webBindingHTTPS">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>

</webHttpBinding>
</bindings>

<serviceHostingEnvironment aspNetCompatibilityEnabled="true">
</serviceHostingEnvironment>

</system.serviceModel>

And Here comes my web.application (Client) web.config

<system.serviceModel>

<client>

<endpoint name="HttpsEP" address="https://test-tranzila.azurewebsites.net/wcfVendingWeb.svc" behaviorConfiguration="AjaxBehavior" binding="webHttpBinding" bindingConfiguration="webBindingHTTPS" contract="WCFVendingWeb.IwcfVendingWeb">
<!--<identity>
<dns value="localhost" />
</identity>-->
</endpoint>
</client>

<behaviors>

<serviceBehaviors>
<behavior name="DefaultBehavior">

<serviceMetadata httpGetEnabled="false" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>

<endpointBehaviors>
<behavior name="AjaxBehavior">
<enableWebScript />
<!--<webHttp/>-->
</behavior>
</endpointBehaviors>

</behaviors>

<bindings>
<webHttpBinding>
<binding name="webBindingHTTPS">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>

</webHttpBinding>
</bindings>

</system.serviceModel>

I am consuming the service from the code behind as

Dim obj As WCFVendingWeb.IwcfVendingWebClient = New WCFVendingWeb.IwcfVendingWebClient("HttpsEP")
      

Dim test = obj.SendTransaction("1234432112344321", "12", "2013", "2", "t", "tt", "cmpny")

The service returns the result as json string as below

Dim oSerializer As New JavaScriptSerializer
Dim jsonResultString = oSerializer.Serialize(clsResponse)
Return jsonResultString

but the problem i am facing is when i try to call the SendTransaction funtion it is always displaying me the error as..

I am unable to fix it and struggling. please anyone can give me solution..

Thanks in advance.

Danasegarane Arunachalam replied to ananda shankar on 20-Apr-13 03:20 AM
This article explains creating and consuming web service from code behind C#

http://www.codeproject.com/Articles/8257/How-to-make-a-simple-WebService-and-consume-it
ananda shankar replied to Danasegarane Arunachalam on 20-Apr-13 03:22 AM

Hi ,

Already calling the web service from code behind is working very well. but my problem is with WCF service returning JSON.

Danasegarane Arunachalam replied to ananda shankar on 21-Apr-13 06:04 AM
I doubt the return is JSON. Try parsing the return xml using XmlSerializer. It may solve your problem.