【问题标题】:why web service can't be accessed为什么无法访问网络服务
【发布时间】:2012-08-25 05:46:26
【问题描述】:

当我尝试从开发服务器访问 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)

【问题讨论】:

  • 方法签名改变了吗?
  • 不,方法签名没有改变。
  • 它在同一个地方为 Web 服务提供相同的代码。只是与代码网站相同的不同位置在调用它。
  • 如何调用 WCF 服务?
  • 如果服务已部署,但您的客户端脚本仍在本地主机上运行,​​您可能遇到了跨域问题。有关如何启用跨域访问的信息,请参见此处的答案:stackoverflow.com/questions/5686059/how-to-avoid-cross-domain-policy-in-jquery-ajax-for-sumption-wcf-service

标签: c# asp.net-mvc-3 wcf


【解决方案1】:

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

可以在此处找到启用跨域脚本的一个很好的示例: how to avoid cross domain policy in jquery ajax for consuming wcf service?

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-16
    • 2019-08-04
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多