【发布时间】:2013-06-19 20:47:53
【问题描述】:
我尝试过同步和异步方法。我已经测试了许多线程中建议的所有不同的东西,但我仍然不断收到上述错误。
对于 IE,我得到“No transport”,而在 FF 中,我得到一个可怕的“Exception...“Failure”nsresult:“0x80004005 (NS_ERROR_FAILURE)”。 p>
当我从浏览器中的 URL 行访问该服务时,我会看到返回的文本,表明该服务已启动并正在运行。 (MyCloud.azurewebsites.net/MyService.svc/Ping)
但是当我尝试使用这个 JS 访问它时它不起作用。
$.ajax({
cache: false,
async: false, //have tried true too
type: "GET",
url: "http://MyCloud.azurewebsites.net/MyService.svc/Ping",
datatype: "text",
success: function (response) { ... },
error: function (xhr, requestStatus, errorText) { ... }
});
我测试了不同的浏览器(Chrome 除外)。由于 CORS 问题,我测试了声明一个不同的端点,并对安全性进行了一些更改(transport 而不是 none)。我仍然会遇到错误。而寻找那些只会带来更多的困惑。
现在,我已经解决这个问题超过一天了,我决定安排故障排除。
- 上面的JS完全正确吗?
- 以下端点定义和服务声明是否也正确?
- 我还能测试什么?我该如何调查这个问题?
<endpoint name="UrlEndPoint"
behaviorConfiguration="UrlEndPointBehavior"
address=""
binding="webHttpBinding"
contract="MyNamespace.IMyService"/>
<behavior name="UrlEndPointBehavior">
<webHttp helpEnabled="true"/>
</behavior>
[OperationContract]
[WebInvoke(UriTemplate = "Ping", Method = "GET")]
String Ping();
此刻我完全迷失了,又病又累。朝着正确的方向前进会很棒。
【问题讨论】:
-
这是跨域请求吗?
-
@MikeBrant 是的。该服务在 Azure 上,呼叫可以来自任何地方。我读到有些人对 CORS 有问题,但正如我在问题中提到的那样,这让我很头疼。 :)