none
WCF Error (405) Method not allowed. I tried aspnet_regiis -I -enable, ServiceModelReg -r...

    Question

  • I have made sure the following are mapped:

    svc-Integrated - *.svc
    svc-ISAPI-2.0 - *.svc

    Here is my service:

    IUserService.cs:

    using System.Collections;
    using System.ServiceModel;

    namespace WebService {
    [ServiceContract]
    public interface IUserService {
            [OperationContract]
    string Test();
    }

    UserService.cs:

    namespace WebService {
    public class UserService : IUserService {
            public string Test() {
    return "Test";
     }
    }

    I have used WCF Text Client, and I can add the service. It is when I try and invoke it, I get the error.
    I have been working on this for 5 days straight and it is killing me.

    Please, does anyone have any ideas?

    Thanks in advance

    Monday, August 03, 2009 4:27 PM

Answers

All replies

  • Oh, I am running IIS 7 under Vista.

    Thanks!
    Monday, August 03, 2009 4:28 PM
  • I am not able to repro your problem.  Are you able to see the metadata when you use any browser and browse to the wsdl page? eg: http://xxx/test/Service1.svc?wsdl

    please compare your files with mine below. 

    service1.svc.cs
    using System.ServiceModel;
    
    namespace IISHosted
    {
        [ServiceContract]
        public interface IUserService
        {
            [OperationContract]
            string Test();
        }
    
        public class UserService : IUserService
        {
            public string Test()
            {
                return "Test";
            }
        }
    }


    service1.svc

    <%@ ServiceHost Language="C#" Debug="true" Service="IISHosted.UserService" CodeBehind="Service1.svc.cs" %>

    Web.config

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.serviceModel>
        <services>
          <service name="IISHosted.UserService" behaviorConfiguration="IISHosted.Service1Behavior">
            <endpoint address="" binding="wsHttpBinding" contract="IISHosted.IUserService">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="IISHosted.Service1Behavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>
    

    Amit Sharma
    Monday, August 03, 2009 4:49 PM
  • Thank you for the prompt response, it is very much appreciated.

    Yes, I can see the meta data in the browser.

    I tried your code and web.config, and still received the same error. I did make one change:
    <endpoint address="http://x.x.x.x/WebServices" binding="wsHttpBinding" contract="IISHosted.IUserService">

    The remote server returned an unexpected response: (405) Method Not Allowed.

    Server stack trace: 
       at System.ServiceModel.Security.IssuanceTokenProviderBase`1.DoNegotiation(TimeSpan timeout)
       at System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Security.CommunicationObjectSecurityTokenProvider.Open(TimeSpan timeout)
       at System.ServiceModel.Security.SecurityUtils.OpenTokenProviderIfRequired(SecurityTokenProvider tokenProvider, TimeSpan timeout)
       at System.ServiceModel.Security.SymmetricSecurityProtocol.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.SecurityChannelFactory`1.ClientSecurityChannel`1.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout)
       at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
       at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
       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 IUserService.Test()
       at UserServiceClient.Test()
    Monday, August 03, 2009 5:21 PM
  • lets try couple things here.

    1) empty the address value in your config file (like in my sample) and try again.  Does it work?
    2) verify allowed verbs in your IIS handler mappings
       - open IIS
       - go to your service's virtual directory
       - click on Handler Mappings
       - double click on svc-integrated
       - click on Request Restrictions
      - in the Reques Restrictions dialog, select the Verbs tab
     - make sure that "All verbs" is checked.

    verify the same from svc-ISAPI-2.0

    please post back your results from 1 and 2.


    Amit Sharma
    Monday, August 03, 2009 6:59 PM
  • 1) Removing the address causes this error: 

    There was no endpoint listening at http://WebServices/Service1.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.


    2) "All Verbs" is checked for both svc-Integrated & svc-ISAPI-2.0
    Monday, August 03, 2009 8:06 PM
  • Jodogger,

    Is the address attribute for your endpoint referencing something outside the vdir/application where the .svc file is located? I may be wrong, but I think you can only have endpoints which are "under" the .svc file (i.e., if your .svc file is at http://your_server/vdir/Service.svc, the endpoint address has to be something at http://your_server/vdir/Service.svc/endpoint), which is why I usually use relative addresses in the "address" attribute of the <endpoint> element for the services.

    You mentioned that you can see the help page after browsing to http://your-server/vdir/service.svc; on WcfTestClient, can you go to File -> Add Service, then add a reference to the address listed there (after "svcutil")? If that succeeds, then try invoking the operation to see whether it works.

    Yet another thing to try: after changing the address attribute to empty, you mentioned that you now get the error "there was no endpoint listening at..."; did you try closing/reopening WcfTestClient to see if that helped (or right-click the service address, then select "refresh service")

    Monday, August 03, 2009 11:59 PM
  • Ok, I re-installed IIS and everything works. Not sure what exactly was wrong.
    Thank you very much for the prompt help.
    Thursday, August 06, 2009 7:34 PM