`

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

    博客分类:
  • Flex
阅读更多
今天在做新项目时碰到了一个问题,我在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=&#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
设置完后,重器应用。
  • 大小: 49.6 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics