1

当我尝试从开发服务器访问 Web 服务时,它返回以下错误。当我从本地机器访问相同的服务时,它工作正常。你知道可能是什么原因吗?非常感谢您!

System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (405) Method Not Allowed. ---> System.Net.WebException: The remote server returned an error: (405) Method Not Allowed.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   --- End of inner exception stack trace ---

Server stack trace:
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Portal.ExportSvcReference.IExportDataService.AddDataRequest(ExportData request)
4

1 回答 1

2

405 错误通常是由跨域问题引起的。如果你已经部署了你的服务,但是在 localhost(或另一个部署)上的客户端进行测试,那么一切都不再在同一个 localhost 域下运行,所以你需要启用跨域调用。

可以在此处找到启用跨域脚本的一个很好的示例: 如何避免在 jquery ajax 中使用跨域策略来使用 wcf 服务?

正如@Monkieboy 所说,如果不查看您的 web.config 文件就很难诊断,但尝试通过添加来更改您正在使用的任何绑定crossDomainScriptAccessEnabled="true",看看是否有帮助。

于 2012-08-30T13:37:51.467 回答