简体   繁体   中英

WCF web library 405 error

I have been fighting IIS for about a week now to get this web service running and it has been fighting back tooth and nail in an attempt to get me to quit my job (thank god my job doesn't involve IIS for the most part). I created a WCF service and a client to talk to it. When running them on my local system they love eachother; no errors at all. When I host the service on IIS however, the story turns...

I've mounted the service as a web page, I think. I've been taking multiple tutorials and none of them can give a straight answer on how to mount a web service. What I have done is used the Publish function in Visual Studio to publish the service on my desktop (using the "to file" option or whatever it's called). I then move that folder to the IIS server and put it in the wwwroot folder. After that I attempt to create a new webpage with that folder for the base. It contains the .svc file, a web.config file, and the \\bin directory with the .dll in it.

After configuring the endpoints (I know they are configured correctly because the error message changes from a "cannot find endpoints one" to this 405), running the client program will cause me to get a 405 error every time. I created a log for the exception to be dumped to, and here it is:

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

If any more information would be helpful please let me know. I have tried multiple solutions for 405 errors and I have gotten no where. While I've taken a few online courses regarding IIS, I'm still very much a beginner. In any case if anyone has some ideas please let me know.

Edit: Here is the web.config which includes the code Lex Li asked be added to it. On a side note I was unable to locate svctraceviewer.exe on either my local system nor the server system. I'm looking around for a solution now.

<?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>

I believe there are 2 possibilities for this issue:

  1. Issue Server Side: WCF is not properly installed in you server:

"run" type this: "%WINDIR%\\Microsoft.Net\\Framework\\v3.0\\Windows Communication Foundation\\ServiceModelReg.exe" -r

Or

Open admin cmd prompt, and execute ServiceModelreg -i in c:\\Windows\\Microsoft.NET\\Framework\\v3.0\\Windows Communication Foundation folder.

You can find additional help about this here to confirm if WCF is properly installed in the server:

2 -- Issue Client Side Depending of the type of application you are building you may need to enable cross domain calls: crossDomainScriptAccessEnabled="true" http://msdn.microsoft.com/en-us/library/ee834511(v=vs.110).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM