IsEmpty error when calling a method without WCF parameters from Flex

I have a WCF web service (using basicHTTPBinding) that I am connecting to from a Flex application. I am using FlexBuilder code generation to generate a proxy for a web service.

This works great until I tried to call a method in the web service that has no parameters. Here is the interface declaration:

    [OperationContract]
    DateTime GetCurrentDateTime();

      

Then I started getting HTTP 500 code responses from the service.

Checking the HTTP response with Fiddler reveals that WCF is reporting the following error:

Error in deserializing body of request message for operation 'GetCurrentDateTime'. 
The OperationFormatter could not deserialize any information from the Message because the Message is empty (IsEmpty = true)

      

So there seems to be an incompatibility between Flex and WCF, calling methods that have no parameters: Flex doesn't contain anything in the message, but WCF expects something in there.

Is there a way to configure Flex or WCF to work around this, or will I have to include dummy parameters in such contracts on operations?

+2


source to share


1 answer


I can call a web request without parameters just fine.

WCF:

[ServiceContract]
public interface ICurrentDateTimeService
{
    [OperationContract]
    DateTime GetCurrentDate();
}

public class Service1 : ICurrentDateTimeService
{
    public DateTime GetCurrentDate()
    {
        return DateTime.Now;
    }
}

      

Flex:



<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" applicationComplete="init()">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
    <![CDATA[
        import mx.rpc.events.FaultEvent;
        import mx.rpc.events.ResultEvent;
        import services.currentdatetimeservice.CurrentDateTimeService;

        private var service:CurrentDateTimeService = new CurrentDateTimeService();

        public function init():void {
            service.addEventListener(ResultEvent.RESULT, serviceResult);
            service.addEventListener(FaultEvent.FAULT, serviceFault);
            service.GetCurrentDate();
        }

        public function serviceResult(e:ResultEvent):void {
            trace(e.result);
        }

        public function serviceFault(e:FaultEvent):void {
            trace("Oh no! :(");
        }

    ]]>
</fx:Script>
</s:Application>

      

Result Thu Aug 4 01:11:12 GMT-0600 2011

Do you have a listener for the crash event?

0


source







All Articles