flex 通过BlazeDS 调用服务端方法时报 http://……/messagebroker/amf 404

今天在做新项目时碰到了一个问题,我在MXML文件中声明了一个RemoteObject,然后尝试web端发送请求调用后台方法时,却怎么也发送不出去。因为我设置了如果失败就弹出event.fault.faultString,所以它一直弹出“Send fail”的提示,而JRUN控制台则提示 "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="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint uri="http://{server.name}:{server.port}/[color=red]{context.root}[/color]/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>false</polling-enabled>
</properties>
</channel-definition>

<channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
<endpoint uri="https://{server.name}:9100/[color=red]{context.root}[/color]/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
</channel-definition>

<channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
<endpoint uri="http://{server.name}:{server.port}/[color=red]{context.root}[/color]/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
<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="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint uri="http://{server.name}:{server.port}/flex/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
<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
设置完后,重器应用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值