1 Reply Latest reply: Dec 8, 2009 12:21 PM by learningflex RSS

    Calling a WCF service from Flex

    learningflex Community Member

      I was given a WCF AJAX Enabled Service providing data in JSON and XML

       

      http://dev1/ytn/StatService.svc  which when open has a wsdl file

       

      svcutil.exe http://dev1.choice.com/YTN/StatService.svc?wsdl

       

      <?xml version="1.0" encoding="utf-8" ?>

      - <wsdl:definitions name="StatService" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:i0="YTN" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex">

      <wsdl:import namespace="YTN" location="http://dev1.choice.com/YTN/StatService.svc?wsdl=wsdl0" />

      <wsdl:types />

      - <wsdl:binding name="WebHttpBinding_StatService" type="i0:StatService">

      - <wsdl:operation name="GetDataJSON">

      <wsdl:input />

      <wsdl:output />

      </wsdl:operation>

      - <wsdl:operation name="GetDataListJSON">

      <wsdl:input />

      <wsdl:output />

      </wsdl:operation>

      - <wsdl:operation name="GetDataXML">

      <wsdl:input />

      <wsdl:output />

      </wsdl:operation>

      - <wsdl:operation name="GetDataListXML">

      <wsdl:input />

      <wsdl:output />

      </wsdl:operation>

      </wsdl:binding>

      - <wsdl:service name="StatService">

      <wsdl:port name="WebHttpBinding_StatService" binding="tns:WebHttpBinding_StatService" />

      </wsdl:service>

      </wsdl:definitions>

       

       

      How do i call this wsdl from my flex application. The WCF service is in .NET. webHttpBinding and Restful Services and pure http. Please help

        • 1. Re: Calling a WCF service from Flex
          learningflex Community Member

          namespace

           

           

          YTN

          {

          [ServiceContract(Name =

          "StatService", Namespace = "YTN")]

           

          interface IStatService

          {

          [OperationContract]

          [WebInvoke(ResponseFormat = WebMessageFormat.Json)]

           

           

          int GetDataJSON(string queueName);

           

          [OperationContract]

          [WebInvoke(ResponseFormat = WebMessageFormat.Json)]

           

          List<int> GetDataListJSON(List<string> queues);

          [OperationContract]

          [WebInvoke(ResponseFormat = WebMessageFormat.Xml)]

           

          int GetDataXML(string queueName);

          [OperationContract]

          [WebInvoke(ResponseFormat = WebMessageFormat.Xml)]

           

          List<int> GetDataXML(List<string> queues);

          }

           

           

          The web.config has

           

          <

           

          system.serviceModel>

          <

           

          behaviors>

          <

           

          endpointBehaviors>

          <

           

          behavior name="StatServiceAspNetAjaxBehavior">

          <

           

          enableWebScript/>

          </

           

          behavior>

          </

           

          endpointBehaviors>

          <

           

          serviceBehaviors>

          <

           

          behavior name="YTN.StatServiceBehavior">

          <!--

           

          To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->

          <

           

          serviceMetadata httpGetEnabled="true"/>

          <!--

           

          To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->

          <

           

          serviceDebug includeExceptionDetailInFaults="false"/>

          </

           

          behavior>

          </

           

          serviceBehaviors>

          </

           

          behaviors>

           

          <

           

          serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>

          <

           

          services>

          <

           

          service name="YTN.StatService" behaviorConfiguration="YTN.StatServiceBehavior">

          <

           

          endpoint address="" behaviorConfiguration="StatServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="YTN.IStatService"/>

          <

           

          endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

          </

           

          service>

          </

           

          services>

          </

           

          system.serviceModel>

           

          StatService.svc has

          <%

          @ ServiceHost Language="C#" Debug="true" Service="YTN.StatService" CodeBehind="~/App_Code/StatService.cs" %>

           

           

           

          my mxml is

           

          <?xml version="1.0" encoding="utf-8"?>

          <mx:Application

           

          xmlns:mx="http://www.adobe.com/2006/mxml"

          xmlns:xs="

          http://www.w3.org/2001/XMLSchema"

          layout="

          absolute" height="1124">

           

           

           

          <mx:Script>

           

          <![CDATA[

           

          import mx.controls.Alert;

           

          import mx.rpc.events.ResultEvent;

           

          import mx.rpc.events.FaultEvent;

           

          import mx.utils.ObjectUtil;

           

          //import com.adobe.serialization.json.JSON;

           

           

           

          private function httpServiceResultHandler(event:ResultEvent):void {

           

          var rawData:String = String(event.result);

          lbl.text = rawData;

           

          //var person:int = JSON.decode(rawData); -- do i need to do this

           

           

          }

           

          private function httpServiceResultHandler_fault(evt:FaultEvent):void {

          Alert.show(evt.type);

          }

           

           

           

          ]]>

           

          </mx:Script>

           

           

          <mx:HTTPService id="httpService"

          url="

          http://dev1/ytn/StatService.svc" useProxy="false" method="POST"

          resultFormat = "

          text"

          result="httpServiceResultHandler(event)" fault="httpServiceResultHandler_fault(event);"

          >

           

          <mx:request xmlns="">

           

          <queueName>myText.text</queueName>

           

          </mx:request>

          </mx:HTTPService>

           

          <mx:Button id="xmlbutton" x="75" y="388" label="Get Data  JSON" click="httpService.send();" />

           

           

          <mx:Label id="lbl" x="426" y="622" width="180" fontWeight="bold" fontSize="24"/>

           

          <mx:TextInput id = "myText" x="426" y="517" width="223" height="34"/>

           

          </mx:Application>

           

          But this does not work, where do i call the method name? please let me know.