【问题标题】:WCF web library 405 errorWCF Web 库 405 错误
【发布时间】:2014-01-09 19:12:11
【问题描述】:

为了让这个 Web 服务运行,我已经与 IIS 抗争了大约一个星期,它一直在竭尽全力试图让我辞掉工作(感谢上帝,我的工作不涉及 IIS大部分)。我创建了一个 WCF 服务和一个与之交谈的客户端。在我的本地系统上运行它们时,它们彼此相爱;完全没有错误。然而,当我在 IIS 上托管服务时,情况就变了……

我认为,我已将该服务安装为网页。我一直在学习多个教程,但没有一个可以直接回答如何安装 Web 服务。我所做的是使用 Visual Studio 中的发布功能在我的桌面上发布服务(使用“到文件”选项或其他任何名称)。然后我将该文件夹移动到 IIS 服务器并将其放在 wwwroot 文件夹中。之后,我尝试使用该文件夹为基础创建一个新网页。它包含 .svc 文件、web.config 文件和包含 .dll 的 \bin 目录。

配置端点后(我知道它们配置正确,因为错误消息从“找不到端点”变为此 405),运行客户端程序将导致我每次都收到 405 错误。我为要转储到的异常创建了一个日志,这里是:

12/20/2013 12:44:19 PM - 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 TestWebClient.TestWebService.ITestService.Repeat(String input)
   at TestWebClient.TestWebService.TestServiceClient.Repeat(String input) in c:\Users\x\Documents\Visual Studio 2012\Projects\TestWebClient\TestWebClient\Service References\TestWebService\Reference.cs:line 56
   at TestWebClient.Program.Repeat() in c:\Users\xl\Documents\Visual Studio 2012\Projects\TestWebClient\TestWebClient\Program.cs:line 55
   at TestWebClient.Program.Main(String[] args) in c:\Users\x\Documents\Visual Studio 2012\Projects\TestWebClient\TestWebClient\Program.cs:line 16

如果有更多信息对我有帮助,请告诉我。我已经为 405 错误尝试了多种解决方案,但我一无所获。虽然我已经参加了一些有关 IIS 的在线课程,但我仍然是一个初学者。无论如何,如果有人有什么想法,请告诉我。

编辑: 这是包含 Lex Li 要求添加到其中的代码的 web.config。在旁注中,我无法在本地系统或服务器系统上找到 svctraceviewer.exe。我现在正在四处寻找解决方案。

<?xml version="1.0"?>
<configuration>

<system.diagnostics> 
    <trace autoflush="true" />
    <sources>
        <source name="System.ServiceModel" 
              switchValue="Information, ActivityTracing" 
              > 
        <listeners> 
          <add name="xml"/> 
        </listeners> 
      </source> 
      <source name="System.ServiceModel.MessageLogging"> 
        <listeners> 
          <add name="xml"/> 
        </listeners> 
      </source> 
    </sources> 
    <sharedListeners> 
      <add name="xml" 
           type="System.Diagnostics.XmlWriterTraceListener" 
  initializeData= "C:\temp\WCFDiagnosticsExample.svclog" /> 
    </sharedListeners> 
  </system.diagnostics>


  <system.web>
    <compilation targetFramework="4.0" />
  </system.web>

  <system.serviceModel>
    <services>
      <service name="TestWebService.TestService">
        <endpoint address="http://www.wsp41.com/" binding="basicHttpBinding"
          bindingConfiguration="" contract="TestWebService.ITestService" />
      </service>
    </services>
    <diagnostics> 
      <messageLogging 
            logEntireMessage="true" 
            logMalformedMessages="true" 
            logMessagesAtServiceLevel="true" 
            logMessagesAtTransportLevel="true" 
            maxMessagesToLog="3000" 
       /> 
    </diagnostics>
  </system.serviceModel>

</configuration>

【问题讨论】:

  • 你能发布你的 web.config 吗?
  • 好的,我找到了跟踪查看器并将链接中的代码插入到 web.config 文件中,如上所示。据我所知,我没有得到任何回报。我可能没有正确完成 web.config,但目前它看起来像上面我编辑的帖子中发布的那个。
  • 更多测试表明,仅当通过 Internet Explorer 访问服务时才会创建跟踪日志。当我运行客户端并尝试访问服务(出现 405 错误)时,不会在 c:\temp 目录中创建跟踪日志。
  • 你有没有想过这个问题?

标签: c# asp.net wcf web-services iis


【解决方案1】:

我认为这个问题有两种可能:

  1. 问题服务器端: WCF 未正确安装在您的服务器中:

“运行”键入:“%WINDIR%\Microsoft.Net\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe”-r

或者

打开 admin cmd 提示符,并在 c:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation 文件夹中执行 ServiceModelreg -i。

您可以找到有关此here 的其他帮助,以确认 WCF 是否已正确安装在服务器中:

2 -- 发布客户端 根据您正在构建的应用程序类型,您可能需要启用跨域调用:crossDomainScriptAccessEnabled="true" http://msdn.microsoft.com/en-us/library/ee834511(v=vs.110).aspx

【讨论】:

  • 感谢您的回复。不幸的是,这两个项目都不起作用。我已经运行了 .net 服务模型,而跨域项目似乎没有这样做。
猜你喜欢
  • 2015-04-07
  • 1970-01-01
  • 2012-10-25
  • 2017-03-25
  • 1970-01-01
  • 2011-01-27
  • 2018-06-02
  • 2012-12-09
  • 1970-01-01
相关资源
最近更新 更多