Flex应用BlazeDS时报错:[RPC Fault faultString="发送失败" faultCode="Client.Error.MessageSend" faultDetail="Cha

在flex项目的根目录下,有个.flexProperties的配置文件,里面有个serverContextRoot属性配置默认是"/WebContent“,手工改为"/项目名"

========================================================================

刚接触Flex,在学习BlazeDS的时候,碰见这个问题,调了一天也不知道为什么

错误[RPC Fault faultString="发送失败" faultCode="Client.Error.MessageSend" faultDetail="Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 404: url: 'http://localhost:8080/WebContent/messagebroker/amf'"]

上网狂搜,终于解决了。

参考http://www.cnblogs.com/adaikiss/archive/2010/08/17/1801231.html

发送请求总是404 NOT FOUND! 后来在网上看到有人提到

http://localhost/WebContent/messagebroker/amf

对比自己的请求,也是这样的...

services-config.xml里明明是

http://{server.name}:{server.port}/{context.root}/messagebroker/amf

的,我的webapp访问用的也是项目名,而不是WebContent呀,然后试着把services-config.xml里的

{context.root}用项目名替换,不成功,然后去项目根目录看,发现

.flexProperties文件里有段

<flexProperties enableServiceManager="false" flexServerFeatures="4" flexServerType="8" flexWarLocation="E:/blazeds.war" serverContextRoot="/WebContent" serverRoot="E:/workspaces/flex/WebContent" serverRootURL="http://localhost:80/flex" toolCompile="true" useServerFlexSDK="false" version="2"/>

真凶终于出来了...就是serverContextRoot="/WebContent"这个,把它改成项目名,问题就解决了...

这个是创建项目时自动生成的,谁知道它会这么傻...

还有一种方法是说在mxml中的RemoteObject对象定义时加上endpoint="messagebroker/amf" 属性。(这个没试过)


=========================================

今天在做新项目时碰到了一个问题,我在MXML文件中声明了一个RemoteObject,然后尝试web端发送请求调用后台方法时,却怎么也发送不出去。因为我设置了如果失败就弹出event.fault.faultString,所以它一直弹出“Send fail”的提示,而JRUN控制台则提示 &#34;Requested resource /messagebroker/amf file not found;,通过firefox差错就是报/messagebroker/amf 404。我就去查帮助,然后检查自己的配置文件是否正确。还好原来做过这样的项目,问题很快定位到了,在此做一笔记,作为总结或者希望能够帮助到出现类似问题的IT民工们。 

问题的最终原因 是因为 编译的时候{context.root} 不会在Eclipse中被设定,如果你要使用Flex Builder在本地编译的话,就需要吧 {context.root} 替换成你的程序的根路径,一般来说就是WEB-INF文件夹的父文件夹。 

原本在 flex-config.xml中是有这么一项的: 
<context-root>/flex</context-root> 

但是Eclipse既然不识别,方法有两种: 
1、直接将web端项目中的service-config.xml做如下更改: 
原配置中有这么一段: 
<channel-definition id=&#34;my-amf&#34; class=&#34;mx.messaging.channels.AMFChannel&#34;> 
<endpoint uri=&#34;http://{server.name}:{server.port}/ {context.root} /messagebroker/amf&#34; class=&#34;flex.messaging.endpoints.AMFEndpoint&#34;/> 
<properties> 
<polling-enabled>false</polling-enabled> 
</properties> 
</channel-definition> 

<channel-definition id=&#34;my-secure-amf&#34; class=&#34;mx.messaging.channels.SecureAMFChannel&#34;> 
<endpoint uri=&#34;https://{server.name}:9100/ {context.root} /messagebroker/amfsecure&#34; class=&#34;flex.messaging.endpoints.SecureAMFEndpoint&#34;/> 
</channel-definition> 

<channel-definition id=&#34;my-polling-amf&#34; class=&#34;mx.messaging.channels.AMFChannel&#34;> 
<endpoint uri=&#34;http://{server.name}:{server.port}/ {context.root} /messagebroker/amfpolling&#34; class=&#34;flex.messaging.endpoints.AMFEndpoint&#34;/> 
<properties> 
<polling-enabled>true</polling-enabled> 
<polling-interval-seconds>8</polling-interval-seconds> 
</properties> 
</channel-definition> 


大家注意红色部分的 {context.root}, 你只要把它改为你的程序根路径就可以了,你可以更改所有的channel,也可以只更改需要用到的channel。比如,我用的是RemoteObject,而RemoteObject使用的是 my-amf channel,我的程序根路径为flex。所以我就做了以下更改: 


<channel-definition id=&#34;my-amf&#34; class=&#34;mx.messaging.channels.AMFChannel&#34;> 
<endpoint uri=&#34;http://{server.name}:{server.port}/flex/messagebroker/amf&#34; class=&#34;flex.messaging.endpoints.AMFEndpoint&#34;/> 
<properties> 
<polling-enabled>false</polling-enabled> 
</properties> 
</channel-definition> 


我的改法就是直接把工程名和主机名写进去。例如//localhost:8080/{flexproject}。 


2、 
flex项目右键——>选择   flex服务器,设置“上下文根目录”,如图所示: 
http://dl.iteye.com/upload/attachment/599343/a7a544a0-cc65-3b14-9e4f-498e129c9f67.png 
设置完后,重器应用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值