locked
Consuming a WebGet in Wcf Data Service that returns nothing (void) RRS feed

  • Question

  • Hi,

    I have a WebGet Method in a Wcf Data Service:

    [WebGet]
    
    public void Operation(int abc) {}
    
    
    

     How can I consume this operation at the client side because Execute<> can't be used in this case. A POST request can solve my problem but I am not sure how to proceed.

    An example would be a great help!

     

    Thanks in advance.

    Thursday, December 9, 2010 7:08 AM

Answers

  • Hi,

    If your service operation is marked with WebGet, then you need to issue a GET request (from or Fiddler). Any other verb will end up with 405 "Method Not Allowed".

    If your service operation is maerked with WebInvoke, then you need to issue a POST request, again anything else will fail with 405.

    Sometimes if you're hosting the service in IIS, POST is not allowed by default and you need to allow in it IIS.

    I can't tell which one of the cases above is your problem, for that you would have to show us the method you're exposing and the request you're trying to send, ideally with the response body.

    Thanks,


    Vitek Karas [MSFT]
    Thursday, December 9, 2010 11:46 PM
    Moderator
  • Hi, If you execute your method asynchronely

          HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://server/service.svc/Operation?abc=42");
          request.Method = "POST";
         request.BeginGetRequestStream(new AsyncCallback(YourMetodXXXXX), request);

    private void YourMetodXXXXX(IAsyncResult asynchronousResult)

    {

    //TODO :Get your data

    }

    thank ....

    Good luck.

     

    Wednesday, December 15, 2010 10:28 AM

All replies

  • Hi,

    Unfortunately you can't use the client library for this as it doesn't support service operations yet.

    Another thing is, that your operation should use WebInvoke rather than WebGet. Since the operation doesn't return anything, it is likely to change the state on the server and as such it should not use the GET HTTP verb, POST is more appropriate.

    You can use HttpWebRequest like this:

          HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://server/service.svc/Operation?abc=42");
          request.Method = "POST";
          HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    

    Thanks,


    Vitek Karas [MSFT]
    Thursday, December 9, 2010 1:14 PM
    Moderator
  • I tried doing this in fiddler but it returned an error stating, "Method Not Allowed."
    Thursday, December 9, 2010 2:06 PM
  • Hi,

    If your service operation is marked with WebGet, then you need to issue a GET request (from or Fiddler). Any other verb will end up with 405 "Method Not Allowed".

    If your service operation is maerked with WebInvoke, then you need to issue a POST request, again anything else will fail with 405.

    Sometimes if you're hosting the service in IIS, POST is not allowed by default and you need to allow in it IIS.

    I can't tell which one of the cases above is your problem, for that you would have to show us the method you're exposing and the request you're trying to send, ideally with the response body.

    Thanks,


    Vitek Karas [MSFT]
    Thursday, December 9, 2010 11:46 PM
    Moderator
  • Hi

    First of all not sure why you would need a void method in WCF Data Service.

    The whole basis of why WCF data Service was evolved in the first place was for data sharing across boundaries and without standards being different. WCF Data Service is the Microsoft answer to oData which is open data protocol. so the primary reason somebody would want to move to WCF data service will be when you want the data from your side to be exposed to outside world. Since oData is built up on prooven standards like ATOM + HTTP + VERBS - any client on earth will know how to interpret that.

    So not sure what you are trying to achieve by exposing a void methid. Can you be more specific ?


    kashyapa
    Tuesday, December 14, 2010 8:34 PM
  • Hi, If you execute your method asynchronely

          HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://server/service.svc/Operation?abc=42");
          request.Method = "POST";
         request.BeginGetRequestStream(new AsyncCallback(YourMetodXXXXX), request);

    private void YourMetodXXXXX(IAsyncResult asynchronousResult)

    {

    //TODO :Get your data

    }

    thank ....

    Good luck.

     

    Wednesday, December 15, 2010 10:28 AM