views:

211

answers:

1

hi, i am going crazy i have read like 10s of articles also on stackoverflow about that i am calling webservice in restful way and should enable this in service and in webconfig, so i did that but as soon as i add the [WebGet()] Attribute i get this crazy error if i remove it then the service get called seamlessly

i am using

  • VS 2010 RC 1
  • IIS 7
  • Windows 7

here is my code

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode    
=AspNetCompatibilityRequirementsMode.Allowed)]
public class Service2
{

[OperationContract]
[WebGet()]
public List<Table1> GetCustomers(string numberToFetch)
{
    using (DataClassesDataContext context = new DataClassesDataContext())
    {

        return context.Table1s.Take(numberToFetch).ToList( );
    }
}

}

and my ASPX page Code

<body xmlns:sys="javascript:Sys"   
    xmlns:dataview="javascript:Sys.UI.DataView">  
  <div id="CustomerView"   
      class="sys-template"  
      sys:attach="dataview"  
      dataview:autofetch="true"  
      dataview:dataprovider="Service2.svc"  
      dataview:fetchParameters="{{ {numberToFetch: 2} }}"  
      dataview:fetchoperation="GetCustomers">  
      <ul>  
          <li>{{name}}</li>  
      </ul>  
  </div> 

and my Web.config code

    <system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="Service2AspNetAjaxBehavior">
                <enableWebScript />
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
        multipleSiteBindingsEnabled="true" />
    <services>
        <service name="Service2">
            <endpoint address="" behaviorConfiguration="Service2AspNetAjaxBehavior"
                binding="webHttpBinding" contract="Service2" />             
        </service>
    </services>
</system.serviceModel>

totally appreciate the help

A: 

Try adding the method decoration:

[WebInvoke(Method = "GET")]

Also, you will run into cross-domain issues in Firefox if you attempt to make a request to a service on a different domain or port. So, if your web application is running at localhost:80 and your WCF service is setup at localhost:10305, Firefox will return a 405.

Phil Scholtes

related questions