开发者

IsEmpty error when calling parameterless WCF method from Flex

开发者 https://www.devze.com 2022-12-26 18:50 出处:网络
I have a WCF web service (using basicHTTPBinding)which I am connecting to from a Flex application. I am using the FlexBuilder code generation to make a proxy for the web service.

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

This has been working great until I开发者_运维技巧 tried to call a method on the web service that has no parameters. Here is it's interface declaration:

    [OperationContract]
    DateTime GetCurrentDateTime();

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

Inspecting the HTTP response with Fiddler shows 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 it seems that there is an incompatability between Flex and WCF whan calling methods that have no paramaters - Flex doesn't include anything in the message but WCF is expecting something to be there.

Is there any way to configure either Flex or WCF to work around this or am I going to have to include dummy parameters in such operation contracts?


I can invoke 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 fault event?

0

精彩评论

暂无评论...
验证码 换一张
取 消