cancel
Showing results for 
Search instead for 
Did you mean: 

Issues about CREATE_ENTITY method in OData Channel service

Former Member
0 Kudos

Hi Colleagues,

I redefined one method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_ENTITY in the following Gateway Service Class, and use the following URL to test activity create operation via t-code /IWFND/GW_CLIENT(Gateway Client) in Gateway Service system, e.g. PGX system. But get one error message 'CSRF token validation failed' as shown below, please tell me how to solve this issue?

  • /sap/opu/odata/sap/ZS_ESCALATIONS/ActivityList

And there is no problem to do Query operation, e.g., search for activities using the following first URL. But unable to do Create operation using the following second URL, if I set breakpoint in the CREATE_ENTITY method, system cannot jump to there, instead jump to the GET_ENTITYSET method. Could you please tell me how to solve this issue?

https://pgxmain.wdf.sap.corp/sap/opu/odata/sap/ZS_ESCALATIONS/ActivityList?$filter=activity_id%20eq%...

https://pgxmain.wdf.sap.corp/sap/opu/odata/sap/ZS_ESCALATIONS/ActivityList

Kind Regards

Andie

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Andie, please try using the search option before posting queries, this one is quite a common "issue". You'll get answers more quickly

For example: http://scn.sap.com/thread/3424154

Regards

Ron.

Former Member
0 Kudos

Hi Ron,

I did the same as you said, and also I test it using RESTClient in Firefox browser as below. But get error messages as screen shot shown below.

If I use the following URL, will get error message as below.

https://pgxmain.wdf.sap.corp/sap/opu/odata/sap/ZS_ESCALATIONS/ActivityList('0000303019')

If I use the following URL, will get error message as below.

https://pgxmain.wdf.sap.corp/sap/opu/odata/sap/ZS_ESCALATIONS/ActivityList

Kind Regards

Andie

Former Member
0 Kudos

The first "error" is a correct response - you cannot POST to an existing URL, it is a second create request. That format of URL is for a PUT (update).

The second one is related to your request body I suspect. You need to post that here or run it through an XML checker.

Former Member
0 Kudos

Hi Ron,

I define one entity set named 'ActivityList' in the following class, which used for query and create operation.

And redefine method CREATE_ENTITY as below. Please check whether my coding is correct or not? When I set breakpoint in this method, and call the following URL, system cannot jump to this method. Instead, jump to method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITYSET.

https://pgxmain.wdf.sap.corp/sap/opu/odata/sap/ZS_ESCALATIONS/ActivityList

Kind Regards

Andie

Former Member
0 Kudos

Hi Ron,

Here is my XML for this case. Where can I find XML checker or do I need to download this tool from website?

<?xml version="1.0" encoding="utf-8"?>

<entry xml:base="http://pgxmain.wdf.sap.corp:1080/sap/opu/odata/sap/ZS_ESCALATIONS/" xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">

<id>http://pgxmain.wdf.sap.corp:1080/sap/opu/odata/sap/ZS_ESCALATIONS/ActivityList('0000203012')</id>

<title type="text">ActivityList('0000303019')</title>

<updated>2013-10-31T10:31:48Z</updated>

<category term="ZS_ESCALATIONS.Activities" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>

<link href="ActivityList('0000303019')" rel="edit" title="Activities"/>

<link href="ActivityList('0000303019')/PartiesInvolved" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PartiesInvolved" type="application/atom+xml;type=feed" title="PartiesInvolved"/>

<link href="ActivityList('0000203012')/ActivityCases" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ActivityCases" type="application/atom+xml;type=feed" title="ActivityCases"/>

<link href="ActivityList('0000303019')/ActivityNotes" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ActivityNotes" type="application/atom+xml;type=feed" title="ActivityNotes"/>

<content type="application/xml">

  <m:properties>

   <d:activity_id>0000203012</d:activity_id>

   <d:activity_process_type>ZS46</d:activity_process_type>

   <d:activity_process_type_description>Req.Backoff. Assist.</d:activity_process_type_description>

   <d:activity_description>gatewaytest</d:activity_description>

   <d:activity_priority>Medium</d:activity_priority>

   <d:activity_service_team>0004659231</d:activity_service_team>

   <d:activity_status>New</d:activity_status>

   <d:activity_person_resp>0004838920</d:activity_person_resp>

   <d:activity_person_name>Andie Chen</d:activity_person_name>

   <d:activity_activity_partner/>

   <d:activity_reason/>

   <d:activity_reason_desc/>

   <d:activity_result_desc/>

   <d:activity_cat>Z56</d:activity_cat>

   <d:activity_cat_desc>Unassigned</d:activity_cat_desc>

   <d:activity_change_date>2013-04-15T00:00:00</d:activity_change_date>

   <d:activity_create_date>2013-04-15T00:00:00</d:activity_create_date>

   <d:activity_change_time>PT06H23M15S</d:activity_change_time>

   <d:activity_create_time>PT06H19M39S</d:activity_create_time>

   <d:activity_planned_date>2013-04-15T00:00:00</d:activity_planned_date>

   <d:activity_actual_date m:null="true"/>

   <d:activity_date_duration>30</d:activity_date_duration>

   <d:activity_time_unit>MINUTE</d:activity_time_unit>

   <d:activity_external_number/>

   <d:activity_location/>

   <d:activity_sales_org/>

  </m:properties>

</content>

</entry>

Kind Regards

Andie

Former Member
0 Kudos

Andie, you can drop the part:

<id>http://pgxmain.wdf.sap.corp:1080/sap/opu/odata/sap/ZS_ESCALATIONS/ActivityList('0000203012')</id>

<title type="text">ActivityList('0000303019')</title>

<updated>2013-10-31T10:31:48Z</updated>

<category term="ZS_ESCALATIONS.Activities" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>

<link href="ActivityList('0000303019')" rel="edit" title="Activities"/>

<link href="ActivityList('0000303019')/PartiesInvolved" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PartiesInvolved" type="application/atom+xml;type=feed" title="PartiesInvolved"/>

<link href="ActivityList('0000203012')/ActivityCases" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ActivityCases" type="application/atom+xml;type=feed" title="ActivityCases"/>

<link href="ActivityList('0000303019')/ActivityNotes" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ActivityNotes" type="application/atom+xml;type=feed" title="ActivityNotes"/>

from the xml. It's not required, as it's associated feed data rather than the properties.

If you use the Gateway client in SAP, it has an option to check XML posted into the body.

Former Member
0 Kudos

If your GET_ENTITYSET method is being called, please make sure you have used a POST verb rather than GET again. There is no way the OData handler will call a verb handler that isn't indicated by the request verb.

You must also return the entity content back through ER_ENTITY after creating it, otherwise you will most likely get a failure, because you have a lot of dates in the entity.

Former Member
0 Kudos

Hi Ron,

I copy and paste your xml in Gateway Client as below, and click on 'Check Request XML' button, then get error message with 'Function only for XML data available'.

And I also copy it to REST Client in Firefox browser as below, and get error message with '

The specified HTTP method is not allowed for the resource identified by the Data Service Request URI'.

Kind Regards

Andie

kammaje_cis
Active Contributor
0 Kudos

Hi Andie,

For the error "The specified HTTP method is not allowed for the resource identified by the Data Service Request URI'. look at this blog.

http://scn.sap.com/community/netweaver-gateway/blog/2013/08/09/frequent-problems-encountered-in-netw...

Search for the error. Problem is with your URI.

Thanks

Krishna

Former Member
0 Kudos

Hi Krishna,

For a ‘POST’ method URI should point to a Collection.

     Example:  …../sap/opu/odata/<NameSpace>/<ServiceName>/<CollectionName>

Now I use the following URL to create a new activity, does 'ActivityList' belong to collection name? You can see its definition in the class in my reply as below.

https://pgxmain.wdf.sap.corp/sap/opu/odata/sap/ZS_ESCALATIONS/ActivityList('0000303019')

Kind Regards

Andie

kammaje_cis
Active Contributor
0 Kudos

Yes,

Your URI for POST would be

https://pgxmain.wdf.sap.corp/sap/opu/odata/sap/ZS_ESCALATIONS/ActivityList

Note: Key is not mentioned.

Thanks

Krishna

Former Member
0 Kudos

Hi Krishna,

If I use the URL you mentioned, get this error message with 'The server is refusing to process the request because the entity has a unsupported format'.

Kind Regards

Andie

Former Member
0 Kudos

Hi Andie,

I suggested you remove that part, not use it as a request! That part by itself is not XML and won't work. In a full body it has no effect so is wasteful to send.

Post your original body MINUS that part.

Regards

Ron.

Former Member
0 Kudos

Hi Ron,

Now I am using XML checker in SAPGUI to do check, but get error messge with 'Error while parsing an XML stream: '<EOF>'. Do you know how to correct this error?

<?xml version="1.0" encoding="utf-8"?>

<entry xml:base="http://pgxmain.wdf.sap.corp:1080/sap/opu/odata/sap/ZS_ESCALATIONS/" xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">

  <content type="application/xml">

  <m:properties>

   <d:activity_id>0000203012</d:activity_id>

   <d:activity_process_type>ZS46</d:activity_process_type>

   <d:activity_process_type_description>Req.Backoff. Assist.</d:activity_process_type_description>

   <d:activity_description>gatewaytest</d:activity_description>

   <d:activity_priority>Medium</d:activity_priority>

   <d:activity_service_team>0004659231</d:activity_service_team>

   <d:activity_status>New</d:activity_status>

   <d:activity_person_resp>0004838920</d:activity_person_resp>

   <d:activity_person_name>Andie Chen</d:activity_person_name>

   <d:activity_activity_partner/>

   <d:activity_reason/>

   <d:activity_reason_desc/>

   <d:activity_result_desc/>

   <d:activity_cat>Z56</d:activity_cat>

   <d:activity_cat_desc>Unassigned</d:activity_cat_desc>

   <d:activity_change_date>2013-04-15T00:00:00</d:activity_change_date>

   <d:activity_create_date>2013-04-15T00:00:00</d:activity_create_date>

   <d:activity_change_time>PT06H23M15S</d:activity_change_time>

   <d:activity_create_time>PT06H19M39S</d:activity_create_time>

   <d:activity_planned_date>2013-04-15T00:00:00</d:activity_planned_date>

   <d:activity_actual_date m:null="true"/>

   <d:activity_date_duration>30</d:activity_date_duration>

   <d:activity_time_unit>MINUTE</d:activity_time_unit>

   <d:activity_external_number/>

   <d:activity_location/>

   <d:activity_sales_org/>

  </m:properties>

</content>

Former Member
0 Kudos

Hi Ron,

I know how to correct this xml error by adding </entry> at the end of this XML as below. Now there is no error after doing check, XML is well-formed. But I still get error message with 'The server is refusing to process the request because the entity has a unsupported format'. See the below.

I am using the following URL, is it correct?

https://pgxmain.wdf.sap.corp/sap/opu/odata/sap/ZS_ESCALATIONS/ActivityList

<?xml version="1.0" encoding="utf-8"?>

<entry xml:base="http://pgxmain.wdf.sap.corp:1080/sap/opu/odata/sap/ZS_ESCALATIONS/" xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">

<content type="application/xml">

  <m:properties>

   <d:activity_id>0000303019</d:activity_id>

   <d:activity_process_type>ZS46</d:activity_process_type>

   <d:activity_process_type_description>Req.Backoff. Assist.</d:activity_process_type_description>

   <d:activity_description>gatewaytest</d:activity_description>

   <d:activity_priority>Medium</d:activity_priority>

   <d:activity_service_team>0004659231</d:activity_service_team>

   <d:activity_status>New</d:activity_status>

   <d:activity_person_resp>0004838920</d:activity_person_resp>

   <d:activity_person_name>Andie Chen</d:activity_person_name>

   <d:activity_activity_partner/>

   <d:activity_reason/>

   <d:activity_reason_desc/>

   <d:activity_result_desc/>

   <d:activity_cat>Z56</d:activity_cat>

   <d:activity_cat_desc>Unassigned</d:activity_cat_desc>

   <d:activity_change_date>2013-04-15T00:00:00</d:activity_change_date>

   <d:activity_create_date>2013-04-15T00:00:00</d:activity_create_date>

   <d:activity_change_time>PT06H23M15S</d:activity_change_time>

   <d:activity_create_time>PT06H19M39S</d:activity_create_time>

   <d:activity_planned_date>2013-04-15T00:00:00</d:activity_planned_date>

   <d:activity_actual_date m:null="true"/>

   <d:activity_date_duration>30</d:activity_date_duration>

   <d:activity_time_unit>MINUTE</d:activity_time_unit>

   <d:activity_external_number/>

   <d:activity_location/>

   <d:activity_sales_org/>

  </m:properties>

</content>

</entry>

Former Member
0 Kudos

OK Andie, gonna make u work for this one.

XML needs all open tags to be closed - you have an open tag. Clue: it's not in the properties.

Former Member
0 Kudos

what else do you have in the request headers? It should be more than the csrf token id.

e.g.

content-type:application/atom+xml

X-Requested-With:XMLHttpRequest

former_member182372
Active Contributor
Former Member
0 Kudos

Hi Ron,

It works well now, thanks a lot!

Kind Regards

Andie

Former Member
0 Kudos

Hi Ron,

Currently, I am developing one App on iPad device based on IOS. For Query operation, I can only use its URL connecting to Gateway Service to do search in IOS, but for Create and Update operation, except for URL, also need to involved some strings like Token ID as Header values and XML file, how to use it in IOS? Do you know more about it?

Kind Regards

Andie

Former Member
0 Kudos

Hii Ron,

                  I am trying to POST entry but Getting the error:

error message: "Resource not found for the segment 'z_hrms_mobile_rfccollection'.", language code: "en"


I am using  fololowing URL

     

SDMHttpRequest *request = [[SDMHttpRequest alloc] initWithURL:[NSURL URLWithString:@"http://10.9.0.30:8000/sap/opu/odata/sap/ZHRMS/z_hrms_mobile_rfccollection"]];

  

   

    [request setUsername:@"ebutech"];

    [request setPassword:@"initial"];

    request.delegate = self;

    [request addRequestHeader:@"Content-Type" value:@"application/atom+xml;type=entry"];

    [request addRequestHeader:@"X-CSRF-Token" value:[dic objectForKey:@"X-CSRF-Token"]];

   

    [request setDidFailSelector:@selector(PostFailed:)];

    [request setDidFinishSelector:@selector(PostFinished:)];

     [request setRequestMethod:@"POST"];

    [request setPostBody:bodyData];

   

    [request startAsynchronous];



Former Member
0 Kudos

Hi Krishna,

                 I am consuming ODAta services in Ios App...GET operation is working...But getting error while POST operation

error message: "Resource not found for the segment 'z_hrms_mobile_rfccollection'.", language code: "en"


I am using  fololowing URL

    

SDMHttpRequest *request = [[SDMHttpRequest alloc] initWithURL:[NSURLURLWithString:@"http://10.9.0.30:8000/sap/opu/odata/sap/ZHRMS/z_hrms_mobile_rfccollection"]];

 

  

    [request setUsername:@"username"];

    [request setPassword:@"password"];

    request.delegate = self;

    [request addRequestHeader:@"Content-Type"value:@"application/atom+xml;type=entry"];

    [request addRequestHeader:@"X-CSRF-Token" value:[dic objectForKey:@"X-CSRF-Token"]];

  

    [request setDidFailSelector:@selector(PostFailed:)];

    [request setDidFinishSelector:@selector(PostFinished:)];

     [request setRequestMethod:@"POST"];

    [request setPostBody:bodyData];

  

    [request startAsynchronous];

Former Member
0 Kudos

Hi Ravindra

In order to provide a context to this query, can you post up the service metadata please?

Former Member
0 Kudos

here it is metadata

<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"xmlns:sap="http://www.sap.com/Protocols/SAPData" Version="1.0">

<edmx:DataServices m:DataServiceVersion="2.0">

<Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="ZHRMS">

<EntityType Name="z_hrms_mobile_rfc" sap:content-version="1">

<Key>

<PropertyRef Name="pernr"/>

<PropertyRef Name="docnr"/>

</Key>

<Property Name="endda" Type="Edm.DateTime" sap:label="End Date" sap:updatable="false"/>

<Property Name="pernr" Type="Edm.String" Nullable="false" MaxLength="8" sap:label="Personnel number" sap:updatable="false"/>

<Property Name="anrtg" Type="Edm.Decimal" Precision="6" Scale="2" sap:label="Days credited" sap:creatable="false" sap:updatable="false"/>

<Property Name="begda" Type="Edm.DateTime" sap:label="Start Date" sap:updatable="false"/>

<Property Name="employeenumber_1" Type="Edm.String" MaxLength="8" sap:label="Personnel Number" sap:creatable="false" sap:updatable="false"/>

<Property Name="nocommit" Type="Edm.String" MaxLength="1" sap:label="COMMIT flag in BAPI interface" sap:updatable="false"/>

<Property Name="absencetype" Type="Edm.String" MaxLength="4" sap:label="Att./Absence type" sap:creatable="false" sap:updatable="false"/>

<Property Name="abwtg" Type="Edm.Decimal" Precision="6" Scale="2" sap:label="Att./abs. days" sap:creatable="false" sap:updatable="false"/>

<Property Name="awart" Type="Edm.String" MaxLength="4" sap:label="Att./Absence type" sap:updatable="false"/>

<Property Name="iv_docnr" Type="Edm.String" MaxLength="20" sap:label="Document number" sap:creatable="false" sap:updatable="false"/>

<Property Name="status" Type="Edm.String" MaxLength="10" sap:label="status" sap:creatable="false" sap:updatable="false"/>

<Property Name="docnr" Type="Edm.String" Nullable="false" MaxLength="20" sap:label="Document number" sap:creatable="false" sap:updatable="false"/>

<Property Name="subty" Type="Edm.String" MaxLength="4" sap:label="Subtype" sap:creatable="false" sap:updatable="false"/>

<Property Name="kaltg" Type="Edm.Decimal" Precision="6" Scale="2" sap:label="Calendar days" sap:creatable="false" sap:updatable="false"/>

<Property Name="stdaz" Type="Edm.Decimal" Precision="7" Scale="2" sap:label="Absence hours" sap:creatable="false" sap:updatable="false"/>

<Property Name="plans" Type="Edm.String" MaxLength="8" sap:label="Position" sap:creatable="false" sap:updatable="false"/>

<Property Name="reason" Type="Edm.String" MaxLength="30" sap:label="Reason for leave" sap:updatable="false"/>

<NavigationProperty Name="it_ypa2001_r" Relationship="ZHRMS.it_ypa2001_r" FromRole="FromRole_it_ypa2001_r" ToRole="ToRole_it_ypa2001_r"/>

</EntityType>

Former Member
0 Kudos

Hi Ron ,

         let me tell you, i am consuming this service in iOs(iphone)... GET operation is working properly...error cmming while POST

plese help

Former Member
0 Kudos

Thanks,

When creating you POST to an entityset URI , not an entity URI. I do not see any evidence of an entityset in the metadata of the entity type.

Is the collection referenced in the URL actually defined in the model? 

regards

Ron.

Former Member
0 Kudos

thanks,

    I dont have any idea regarding that.... What our SUP admin said is Use this URL for POST..

Former Member
0 Kudos

Do i need to change the URL?

Former Member
0 Kudos

Sorry Ron,previously i sent u incpmlete data





<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"xmlns:sap="http://www.sap.com/Protocols/SAPData" Version="1.0">

<edmx:DataServices m:DataServiceVersion="2.0">

<Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="ZHRMS">

<Association Name="it_ypa2001_r" sap:content-version="1">

<End Type="ZHRMS.z_hrms_mobile_rfc" Multiplicity="0..1" Role="FromRole_it_ypa2001_r"/>

<End Type="ZHRMS.it_ypa2001" Multiplicity="*" Role="ToRole_it_ypa2001_r"/>

</Association>

<EntityContainer Name="ZHRMS" m:IsDefaultEntityContainer="true">

<EntitySet Name="z_hrms_mobile_rfcCollection" EntityType="ZHRMS.z_hrms_mobile_rfc" sap:updatable="false" sap:deletable="false" sap:content-version="1"/>

<EntitySet Name="it_ypa2001Collection" EntityType="ZHRMS.it_ypa2001" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:content-version="1"/>

<AssociationSet Name="AssocSet_it_ypa2001_r" Association="ZHRMS.it_ypa2001_r" sap:creatable="false" sap:updatable="false" sap:deletable="false" sap:content-version="1">

<End EntitySet="z_hrms_mobile_rfcCollection" Role="FromRole_it_ypa2001_r"/>

<End EntitySet="it_ypa2001Collection" Role="ToRole_it_ypa2001_r"/>

</AssociationSet>

</EntityContainer>

<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="self" href="http:///sap/opu/odata/sap/ZHRMS/$metadata"/>

<atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="latest-version" href="http:///sap/opu/odata/sap/ZHRMS/$metadata"/>

</Schema>

</edmx:DataServices>

</edmx:Edmx>

Former Member
0 Kudos

OK, I see the problem now. Your URI is not in the same case - OData URI's are case sensitive, i.e..

http://10.9.0.30:8000/sap/opu/odata/sap/ZHRMS/z_hrms_mobile_rfcCollection

Former Member
0 Kudos

Sir,

     but i am using the same URL

Former Member
0 Kudos

With capital 'C' on 'Collection'?

Former Member
0 Kudos

Thnksss Sir, I posted data successfully...

Former Member
0 Kudos

Hi Ron,

           I want to do PUT(update) operation on odataservice... I am using followin code to get the proper Entry property to update

SDMODataEntry * entry1=((SDMODataEntry *)[ArraySelectedCell objectAtIndex:0]);

   

    SDMODataPropertyValueObject* obj = ((SDMODataPropertyValueObject*)[entry1 getPropertyValueByPath:@"rm_comment"]);



But i am getting following error



__NSDictionaryM getPropertyValueByPath:]: unrecognized selector sent to instance 0x10166620



Please help...



Regards,

Ravindra


Former Member
0 Kudos

this isn't a Gateway problem, there is a problem in your iOS client code.

Former Member
0 Kudos

thnks Ron,

               is there any help available for it?

Answers (0)