on 2013 Mar 01 4:46 PM
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:
</Documentation>
</Parameter>
</Documentation>
</Parameter>
</FunctionImport>
thanks.
regards,
Steven
Request clarification before answering.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
| User | Count |
|---|---|
| 9 | |
| 7 | |
| 7 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.