cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

HTTP method not allowed error from Gateway

steven_chen2
Advisor
Advisor
0 Likes
10,045

Hi,

When I test my odata service in GW Client(/IWFND/GW_CLIENT), it always says “The specified HTTP method is not allowed for the resource identified by the Data Service Request URI”. (it works well with sdata). I cannot figure it out and we are blocked. can anyone help me here? thanks.

 

here are the information about my implementation and testing env, I implemented an action to save counting document.

Here is the CountingDoc entity and return entity

*----------------------------------------------------------------------------------
* Entity: Counting Document header
*----------------------------------------------------------------------------------
  lo_entity_type = model->create_entity_type( 'CountingDoc' )"#EC NOTEXT
  lo_property = lo_entity_type->create_property( iv_property_name = 'countingID'      iv_abap_fieldname = 'PHYSINVENTORY'                   ).
  lo_property->set_is_key( ).
  lo_property = lo_entity_type->create_property( iv_property_name = 'fiscalYear'      iv_abap_fieldname = 'FISCALYEAR'        ).
  lo_property->set_is_key( ).
  lo_property = lo_entity_type->create_property( iv_property_name = 'siteID'          iv_abap_fieldname = 'PLANT'   ).
  lo_property = lo_entity_type->create_property( iv_property_name = 'stgeLocID'       iv_abap_fieldname = 'STGE_LOC'        ).

     .....
  lo_entity_type->bind_structure( '/SRSMOB/STOP_COUNTING_DOC' ).

 

  lo_entity_type->set_creatable( abap_true ).

  lo_entity_type->set_updatable( abap_true ).

  lo_entity_type->set_deletable( abap_true ).

   *----------------------------------------------------------------------------------
* Entity: ExecutionMessage
*----------------------------------------------------------------------------------
  lo_entity_type = model->create_entity_type( 'ExecutionMessage' ). "#EC NOTEXT
  lo_property = lo_entity_type->create_property( iv_property_name = 'type'  iv_abap_fieldname = 'TYPE'         ).
  lo_property->set_is_key( ).
  lo_property = lo_entity_type->create_property( iv_property_name = 'id'  iv_abap_fieldname = 'ID'         ).
  lo_property->set_is_key( ).
  lo_property = lo_entity_type->create_property( iv_property_name = 'number'  iv_abap_fieldname = 'NUMBER'         ).
  lo_property->set_is_key( ).
  ...

 

Note:

Here is the POST action in the model,

lo_action = model->create_action( 'SaveCountingLineItemList' ). "#EC NOTEXT
  lo_action
->SET_HTTP_METHOD( /iwbep/if_mgw_med_odata_types=>gcs_med_http_methods-POST ).
  lo_action
->set_return_entity_type( 'ExecutionMessage' ).
  lo_action
->set_action_for('CountingDoc').
  lo_action
->set_return_multiplicity( /iwbep/if_mgw_med_odata_types=>gcs_cardinality-cardinality_1_n ).

  lo_parameter
= lo_action->create_input_parameter( iv_parameter_name = 'countingID' iv_abap_fieldname = 'PHYSINVENTORY').
  lo_parameter
->bind_data_element( '/SRSMOB/STOP_VALUE_CHAR' ).

  lo_parameter
= lo_action->create_input_parameter( iv_parameter_name = 'fiscalYear' iv_abap_fieldname = 'FISCAL_YEAR').
  lo_parameter
->bind_data_element( '/SRSMOB/STOP_VALUE_CHAR' ).

I didn’t paste the runtime code here since the request never reaches there and sdata works.

I am using GW Client (/IWFND/GW_CLIENT) to do the testing.  No ~CHECK_CSRF_TOKEN  is set. So CSRF security is enabled and I don’t need to worry about this security token since I am using GW Client. My url and error looks as below.

url: /sap/opu/odata/SRSMOB/STORE_OPERATIONS/SaveCountingLineItemList?docId='300000314'&fiscalYear='2013'

here is the meata data for this function import:

- <FunctionImport Name="SaveCountingLineItemList" ReturnType="Collection(STORE_OPERATIONS.ExecutionMessage)" EntitySet="ExecutionMessageCollection" m:HttpMethod="POST" sap:action-for="STORE_OPERATIONS.CountingDoc">

- <Parameter Name="countingID" Type="Edm.String" Mode="In">

- <Documentation>

<Summary />

<LongDescription>Value</LongDescription>

</Documentation>

</Parameter>

- <Parameter Name="fiscalYear" Type="Edm.String" Mode="In">

- <Documentation>

<Summary />

<LongDescription>Value</LongDescription>

</Documentation>

</Parameter>

</FunctionImport>

thanks.

regards,

Steven

View Entire Topic
arunchembra1
Participant

Hi Steven,

Check the same in REST client

1. For POST you don't have to pass any value with the service  /sap/opu/odata/SRSMOB/STORE_OPERATIONS/SaveCountingLineItemList

2. Add CSRF token

3. Pass values in Body

{

"docId":"300000314",

"fiscalYear":"2013"

}

Regards,

Arun

former_member182048
Active Contributor
0 Likes

Arun's answer is correct, I was thinking of the similar question asked last week.

steven_chen2
Advisor
Advisor
0 Likes

thanks John and Arun's for your reply. Unfortunately, it's still not working.

@John, for your answer, "You are trying to POST to a query, you can only POST to a single entity.". I think this is for standard (or default) POST implementation. I am not using the standard UPDATE_ENTITY or CREATE_ENTITY methods. I am using function import. and in my action definition, I have this line "

lo_action->set_action_for('CountingDoc').". so the action is for one entity. I agree the action name (SaveCountingLineItemList) is a bit misleading though.

@Arun, I am using GW Client. This tool takes care of CSRF token. So I don't need to manually add any token. I removed the two parameters and pass them in the body as you described. but still no luck. the same error message. anything I missed?

Help is still needed. thanks.

regards,

Steven

former_member195242
Active Participant
0 Likes

Hi Steven,

You need to execute HTTP GET for function imports. I don't think POST is a valid operation if it is function imports.

Best regards,

Aakash

steven_chen2
Advisor
Advisor
0 Likes

Hi Aakash,

POST is a valid operation for function imports. If you check this document "How to write an OData Channel Gateway Service Part 2", there is an example there. but it is in SData. and in my case, my code works well with SData, but not with OData. It seems there's some differences when implementing the POST type of function import in OData. but I couldn't figure out.

regards,

Steven

0 Likes

Thanks Arun. I searched a lot for Post Method.

But your answer is perfect.