locked
How can I force my Silverlight WCF proxy client to use HTTP GET instead of POST? RRS feed

  • Question

  • I think I must be missing something very obvious, but I've tried a few things (which I'll outline below), and still my service proxy class uses HTTP POST to make requests to my WCF service on the server.  I know it's using POST by checking the IIS logs.  I want the service to make the request using HTTP GET so that method name and arguments are stored in the IIS log (plus there are caching benefits from using GET, but my client is using the web-server logs to determine usage patterns).

    In the code-behind for the service (.svc), I'm decorating with WebGet(), like so:

    <ServiceContract(Namespace:="")> _
    <AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
    Public Class SilverLightStatData
    
      <OperationContract()> _
      <WebGet()> _
      Public Function getMapData( ... my args here ... ) As XElement
       .... create and fill an XElement ....
       Return myXElement
      End Function
    
    End Class

    In the web.config file, I've tried setting the binding to basicHttpBinding, webHttpBinding, and wsHttpBinding (by adding different bindings to <system.serviceModel><bindings> node, and modifying the <service> element's attributes).

    On the client (Silverlight 4) side, I'm instantiating the client proxy like this:

    Dim proxy As New SilverLightStatDataClient()
    proxy.Endpoint.Address = myEndpointAddress

    In the client project, there is a ServiceReferences.ClientConfig, the binding created by the add-service wizard is <customBinding>, with binaryMessageEncoding.

    I'm not sure if this needs to be set to <basicHttpBinding>, or some other configuration change, in order to force the client to use HTTP GET.  After making the changes to the service (on the server), I re-built the server solution, then used "Update Service Reference" in the client project, then re-built that.

    So - does anyone know what I'm missing?  Do I need to specify additional decorations on the service methods, beyond just WebGet?  Thanks in advance!

     


    Technology Applied
    Wednesday, May 5, 2010 9:45 AM

Answers

  • The auto-generated proxy doesn't contain information for webHttpBehavior endpoints. In SL4, you can use the [WebGet/WebInvoke] attributes, but you need to share the contract yourself between the client and the server.

    The post at http://blogs.msdn.com/carlosfigueira/archive/2010/04/29/consuming-rest-pox-services-in-silverlight-4.aspx contains information on how to consume REST/POX services in SL4.

    • Proposed as answer by Carlos Figueira Monday, May 10, 2010 4:57 PM
    • Marked as answer by Mog Liang Tuesday, May 11, 2010 2:03 AM
    Wednesday, May 5, 2010 4:38 PM
  • Hi Kirkaiya,

    Since you want to build http get style REST  service, you should use WebHttpBinding since that is the binding for REST service in WCF. Also, are you using self-hosting or IIS hosting? If using IIS hosting, in addition to adding proper attribute on ServiceContract and behavior elements in app.config, you also need to change the ServiceHostFactory to "WebServiceHostFactory" in .svc file's @serviceHost directive.

    The following reference mentioned all the steps:

    #How to: Create a Basic WCF Web HTTP Service
    http://msdn.microsoft.com/en-us/library/bb412178.aspx



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Proposed as answer by Carlos Figueira Monday, May 10, 2010 4:57 PM
    • Marked as answer by Mog Liang Tuesday, May 11, 2010 2:03 AM
    Thursday, May 6, 2010 7:05 AM

All replies

  • The auto-generated proxy doesn't contain information for webHttpBehavior endpoints. In SL4, you can use the [WebGet/WebInvoke] attributes, but you need to share the contract yourself between the client and the server.

    The post at http://blogs.msdn.com/carlosfigueira/archive/2010/04/29/consuming-rest-pox-services-in-silverlight-4.aspx contains information on how to consume REST/POX services in SL4.

    • Proposed as answer by Carlos Figueira Monday, May 10, 2010 4:57 PM
    • Marked as answer by Mog Liang Tuesday, May 11, 2010 2:03 AM
    Wednesday, May 5, 2010 4:38 PM
  • Hi Kirkaiya,

    Since you want to build http get style REST  service, you should use WebHttpBinding since that is the binding for REST service in WCF. Also, are you using self-hosting or IIS hosting? If using IIS hosting, in addition to adding proper attribute on ServiceContract and behavior elements in app.config, you also need to change the ServiceHostFactory to "WebServiceHostFactory" in .svc file's @serviceHost directive.

    The following reference mentioned all the steps:

    #How to: Create a Basic WCF Web HTTP Service
    http://msdn.microsoft.com/en-us/library/bb412178.aspx



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Proposed as answer by Carlos Figueira Monday, May 10, 2010 4:57 PM
    • Marked as answer by Mog Liang Tuesday, May 11, 2010 2:03 AM
    Thursday, May 6, 2010 7:05 AM