locked
The HTTP method 'OPTIONS' is not allowed RRS feed

  • Question

  • Hello,

    I'm calling a http wcf service with XmlHTTPRequest as follows:

    var jsondata = "{\"url\":\"http://google.com\",\"contents\":\"<html></html>\"}";
        var xhr = new XMLHttpRequest();
        xhr.open( "POST", "http://localhost:8731/Design_Time_Addresses/Scraper/AdBusterService/SendPageContents", false);
        xhr.setRequestHeader( 'Content-Type', 'application/json; charset=utf-8');
        xhr.setRequestHeader( 'Content-Length', jsondata.length+'');
        xhr.send(jsondata);

     

    However the service host throws:

     

    The HTTP method 'OPTIONS' of the incoming request (with URI 'http://localhost:8731/Design_Time_Addresses/Scraper/AdBusterService/SendPageContents') is not allowed.

     

    I have no idea why this happens, a GET call (on another method) works fine.

    Please help! Thanks

    Friday, March 19, 2010 12:56 PM

All replies

  • The service is hosted in Windows Forms, here's the config:

     

    <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="Scraper.AdBusterServiceBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="Scraper.AdBusterEndpointBehavior">
                <enableWebScript />
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <services>
          <service behaviorConfiguration="Scraper.AdBusterServiceBehavior"
            name="Scraper.AdBusterService">
            <endpoint address="" binding="webHttpBinding" contract="Scraper.IAdBusterService" behaviorConfiguration="Scraper.AdBusterEndpointBehavior">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8731/Design_Time_Addresses/Scraper/AdBusterService/" />
              </baseAddresses>
            </host>
          </service>
        </services>
      </system.serviceModel>

     

    and the service:

     

    public class AdBusterService : IAdBusterService
        {
            [WebGet]
            public string GetNextUrl()
            {
                return "http://google.com";
            }
           
            [WebInvoke(Method="POST")]
            public void SendPageContents( string url, string contents)
            {
               
            }
        }

     

    The GET method works, the POST one doesn't. I have been working a lot with WCF however haven't got this error until now.

    Please help! Thanks

    Saturday, March 20, 2010 7:57 AM
  • The service is hosted in Windows Forms, here's the config:

     

    <SYSTEM.SERVICEMODEL>
        <BEHAVIORS>
          <SERVICEBEHAVIORS>
            <BEHAVIOR name="Scraper.AdBusterServiceBehavior">
              <SERVICEMETADATA httpGetEnabled="true" />
              <SERVICEDEBUG includeExceptionDetailInFaults="true" />
            </BEHAVIOR>
          </SERVICEBEHAVIORS>
          <ENDPOINTBEHAVIORS>
            <BEHAVIOR name="Scraper.AdBusterEndpointBehavior">
                <ENABLEWEBSCRIPT />
            </BEHAVIOR>
          </ENDPOINTBEHAVIORS>
        </BEHAVIORS>
        <SERVICES>
          <SERVICE
    nbsp;       name="Scraper.AdBusterService">
            <ENDPOINT behaviorConfiguration="Scraper.AdBusterEndpointBehavior" contract="Scraper.IAdBusterService" binding="webHttpBinding" address="">
              <IDENTITY>
                <DNS value="localhost" />
              </IDENTITY>
            </ENDPOINT>
            <ENDPOINT contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
            <HOST>
              <BASEADDRESSES>
                <ADD baseAddress="http://localhost:8731/Design_Time_Addresses/Scraper/AdBusterService/" />
              </BASEADDRESSES>
            </HOST>
          </SERVICE>
        </SERVICES&T;
      </SYSTEM.SERVICEMODEL>

     

    and the service:

     

    public class AdBusterService : IAdBusterService
        {
            [WebGet]
            public string GetNextUrl()
            {
                return "http://google.com";
            }
           
            [WebInvoke(Method="POST")]
            public void SendPageContents( string url, string contents)
            {
               
            }
        }

     

    The GET method works, the POST one doesn't. I have been working a lot with WCF however haven't got this error until now.

    Please help! Thanks


    Is there an rignt answer for the problem? Could you give more details? I'm still concerned about it, It's long time, I've got the same problem.
    Sunday, August 8, 2010 5:08 AM
  • Which browser are you using; it is seems it has to do with cross domain difference and this is chrome way to do it by sending two requests so first request is sent using method options and you have to authorize post 

    if (WebOperationContext.Current.IncomingRequest.Method == "OPTIONS")
    {
       
    WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
       
    WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Methods", "POST");
       
    WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Accept");

       
    return null;
    }

    Friday, December 2, 2011 5:56 PM