在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控制台则提示 "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}/ {context.root} /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/ {context.root} /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}/ {context.root} /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
设置完后,重器应用。