2010-04-12 55 views
2

我有一個WCF Web服務(使用basicHTTPBinding),我正在從Flex應用程序連接到這個Web服務。我正在使用FlexBuilder代碼生成器爲Web服務創建代理。從Flex調用無參數WCF方法時發生IsEmpty錯誤

直到我試圖在沒有參數的Web服務上調用方法時,這一直很好。這是它的界面聲明:

[OperationContract] 
    DateTime GetCurrentDateTime(); 

然後我開始從服務獲取HTTP 500代碼響應。

檢查與小提琴手的HTTP響應表明,WCF是報告以下錯誤:

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) 

如此看來,有一些沒有PARAMATERS Flex和WCF煥調用方法之間的不相容性 - Flex不包括消息中的任何內容,但WCF期望有東西在那裏。

有什麼辦法來配置Flex或WCF來解決這個問題,還是我將不得不在這些操作合同中包含虛擬參數?

回答

0

我可以調用一個沒有參數的web請求就好了。

WCF:

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

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

軟硬度:

<?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> 

結果Thu Aug 4 01:11:12 GMT-0600 2011

你有故障事件監聽器?

相關問題