cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a Model based on an SQL Server?

Former Member
0 Kudos

Hello,

Can someone please guide me how can I create a Model which takes it's Data from a table in an SQL Server?

Can I make such a Model that will connect directly to a Datasource on the Application Server?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi again Roy,

if your WAS is based on MS SQL then u dont need to create any extra datasource as one will be by default created. So you can use that. Though if the default db is not MS SQL and something else then u need to create your own datasource which u can do from Visual Admin.

You cannot create a model directly to a datasource. Though u can achieve the requirement by creating an EJB project where your enterprise beans will be connecting to the DB using the datasource. Create some business methods which will return your required data. Now u can access the bean by just referencing the EJB project or by exposing the bean as local web service and create a Web Service model out of it.

Both will suffice the requirement of accessing database.

you can see the following tutorial to find out how to access local web services and to access data from DB through it ...

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/using car rental web service with web dynpro.pdf

Regards,

Shubhadip

Message was edited by: Shubhadip Ghosh

Former Member
0 Kudos

10X Shubhadip, helpful as usual

I thought so, I simply wanted to avoid the Bean "mediation".

Is it possible to simply connect from the doInit() method for example to a System I've configured on the Portal and connected to a certain SQL Server and make my Queries through this System? If yes, Can I see a Code example please?

Former Member
0 Kudos

Hi Roy,

not sure about portal system access. Will definitely look into that. Though one thing u can do, you can definitely access already created portal services from WebDynpro. From any method. Suppose you have an already created Service in ur portal where u r displaying the WD app too. And this portal service is connecting to the DB through method of your choice. So you can access this portal service and achieve ur requirements. How to access portal services from WD? Like below... )

IMyPortalService portalService = (IMyPortalService)WDPortalUtils.getServiceReference("ParName.ServiceName");

portalService.yourBusinessMethod();

Two more things to be taken care in this approach..

add the service api.jar file (<servicename>api.jar is there inside ur <service>.par file) to the WD project build path as External Library. Add a Web Dynpro sharing reference by going Project>Properties>Web Dynpro References --> Sharing References. Add a new entry with the value as PORTAL:sap.com/<Portal Service Application Name>

You can try it out.. though about acessing some system directly I will try to learn it for myself too... )

regards,

Shubhadip

Former Member
0 Kudos

Hey Shubhadip,

When you are talking about a Service do you mean Web Service? If not than I will be happy to see of a simple example of a Service as you described it...

Former Member
0 Kudos

Hi Roy,

though it shuld be part of the portal forum, but still. Portal Services are not web service. You simply develop a java class or a set of classes in a portal project for serving some generic purpose. You will have methods for accessing these generic purposes. You upload it to portal as a service and register it through System Admin-->System Config --> Services.. After that from any portal component and from WD components also u can access the functionalities provided by Portal Services just by calling the business methods...

From NWDS portal perspective u can easily create a portal service through the wizards itself. Please see the NWDS help and help.sap.com for detailed description of how to create portal service.

Hope it helps!!!

Shubhadip

Former Member
0 Kudos

Hey Shubhadip,

Altough it is part of the portal forum I am asking you this since I see you are familiar with this issue.

I've created a Simple Service and deployed it as PAR file to the Portal but I can't see it under System Admin--> System Config --> Services. Any idea why?

Former Member
0 Kudos

Hi Roy,

its perfect with me if u ask the question here. Well, while you have created the service have u done all the required things like from service interface inheriting from IService, in this interface mentioning one KEY for your service object, implementing the business methods in the implemetation class of the service, mentioning a service name in portalapp.xml etc and then deploy the corresponding par file in portal. If everything has been done as per the portal development rules then you should your service under System Admin --> System Config --> Service Config --> Applications --> Your service application name. Right Click on your application folder here and say Administer. It will open your service here, you have to restart the service for making it accessible from other components...

regards,

shubhadip

Former Member
0 Kudos

Hey,

Let me describe you what I did.

Using the Netweaver Developer Studio I've created new portal project then new portal object->Portal Service.

This automaticly generated the required Interface and implemented class.

Than I've declared a simple function at the interface:

public String sayHello(String name) and implemented it at the class to simply return new String("Hello " + name)

I assume that by doing so the Netweaver Developer Studio created the required records at the xmls.

Then I deployed this project as a PAR file to my Portal which is NW 04. Should I have done anything different?

Former Member
0 Kudos

Hi Roy,

suppose you have created a service object called MyService. Then in your portal project tree under src.api/package_name you will find an interface with name IMyService and in src.core/package_name you will find the actual class MyService. That you know I think. Now in this IMyService interface you can see a public static final String KEY variable is there. Just give any name for your service as a value of this variable. The rest like service name in portalapp.xml should be automatically created. Now this IMyService interface is like a remote interface of an ejb.. means it should contain signatures of the business methods u have created in the actual MyService class. Check whether thats there or not. After this everything should be ok... please check these things and let us know...

hope it helps!!!

Shubhadip

Former Member
0 Kudos

Hi,

I've set the KEY String as "RoyService", there are no error while deploying the project as a PAR file but I still can't see it under Services. Is there anything else I should configure manually and it is not being automaticly configured by the NW?

Former Member
0 Kudos

Hi Roy,

you will get your service listed under your application name in the Applications node under System Admin>System Config>Service Config. Are you not even getting the application name also? Normally just for uploading a service and making it available you should only have the implementation of IService by your Service interface, a key, <service></service> entires in portalapp.xml. Among these only the key value is not generated automatically, the rest are. I am Not getting the problem properly I suppose.

shubhadip

Former Member
0 Kudos

Hi,

Thats really weird than since I did all these steps yet I can't even get the application name under: System Admin>System Config>Service Config.

Perhaps it shouldn't be deployed as a PAR file?

Any other ideas why this could happen? Maybe the J2EE Engine should be restarted (But that doesn't make sence that after every Service deployment a restart should be made...)

Former Member
0 Kudos

By the way, I can see the Application under the "Java Development" Role as an application but nothing under System Admin>System Config>Service Config

Former Member
0 Kudos

The strangest thing!

I've restarted the Netweaver Developer and redeployed it and now I can see the Service!

With your premission let's go now one step forward.

Can you please explain me how do I use the simple Service I've created and contains one business method in a WebDynPro Application?

Former Member
0 Kudos

Well Roy,

I was also facing some similar problem, just now got my service displayed in portal. Thanks a lot that you could solve it urself. Anyway, now for using this service from another portal component do the following

1. Add SharingReference value in Deployment Descriptor of the portal app from where u want to access this service

example:

<application-config>

<property name="SharingReference" value="com.customer.training.MyFirstPortalApp">

</property>

</application-config>

2. Add libraries of the Portal Service (xxxapi.jar)

in your par file u can see one jar file as <servicename>api.jar . extract this to some other location and in the client portal app project add this .jar to its build path.

3. Write code to access the Portal Service

a. Import package of the Portal Service

b. Get instance of the Portal Service

c. Call methods of the Portal Service

example:IPortalRuntimeResources runtimeResources = PortalRuntime.getRuntimeResources();

IService aService = runtimeResources.getService("com.customer.training.MyFirstPortalApp.MyService");

// OR

IService aService = runtimeResources.getService(IMyService.KEY);

// Cast the Service

IMyService myService = (IMyService)aService;

// call methods of the service

response.write(myService.getWelcomeString(aName));

thats how it should be...

regards,

Shubhadip

Former Member
0 Kudos

Hey,

I got your explanation from above:

IMyPortalService portalService = (IMyPortalService)WDPortalUtils.getServiceReference("ParName.ServiceName");

portalService.yourBusinessMethod();

I am getting stuck at this line:

portalService.yourBusinessMethod();

Even though I've added the relevant jar file to the DynPro Project and set Sharing referance the portalService which represents an instance of my service doesn't recognize any business method although I've created one. Any ideas?

Former Member
0 Kudos

Most probably u havent added this method's signature in the IMyService interface under src.api/package_name. Just check it once.

Shubhadip

Former Member
0 Kudos

Checked it, it has been added...

Former Member
0 Kudos

I even opened the Interface file inside the external jar mapped to my DynPro Application with decompiler and I see the business method there. Any other idea?

Former Member
0 Kudos

As far as I can understand there must be referencing problem we are facing. Have you added the proper api.jar file? Inside the par file this api.jar should reside under the PORTAL-INF\lib folder. I just created one test WD project where I could access the business method. I couldnot check the things running in portal as didnt find time but things are getting compiled. If you have added the proper api.jar and mentioned the proper Application name as PORTAL:sap.com/<app_name> then its really strange. Well in that case you can just give me your mail id, I will send you these two test projects tomorrow...

today.. its end of a long day..

regards,

Shubhadip

Former Member
0 Kudos

Just one quick thing, u also need to add a jar called prtapi.jar in the WD project classpath. This jar u will find somewhere under your portal installation folder. Forgot to mention this totally..

shubhadip

Former Member
0 Kudos

Hey,

After adding the prtapi.jar it is working!

But why? why do I need this jar in order to expose a Business method on a different jar?

Former Member
0 Kudos

Roy,

this jar is not required for accessing the business method. Its for accessing the Service itself. When we say WDPortalUtils.getServiceReference("ServiceName") it basically calls the same PortalRuntime.getRuntimeResources().getService("ServiceName"); thats why.. in order to get the handle for the service instance we need this jar.

Regards,

Shubhadip

Former Member
0 Kudos

And another question...

Lets say I want now to use an embedded SAP service on the Portal. How do I retreive it's relevant jar file into my project?

Former Member
0 Kudos

Hi Roy,

you have to know the full name of that service and you will be able to find out the default folder for that service as per its folder name in your portal installation directory itself. Like for TransformationService the folder is com.sap.portal.transformationservice. So you have to find this folder and inside it you will find a lib folder which includes the xxxapi.jar you are looking for. Just include this jar to your WD classpath as you already know. You will find these folders for services & other applications in the following path of your portal installation

\usr\sap\<instance id>\JC00\j2ee\cluster\server0\apps\sap.com\irj\servlet_jsp\irj\root\WEB-INF\portal\portalapps\

hope this helps!!!

Regards,

Shubhadip

Message was edited by: Shubhadip Ghosh

Former Member
0 Kudos

Hey Shubhadip,

Thanx alot, it does.

I thought they should come with the NW Developer Stusio installation. Buy they way, is there any way to communicate with you directly through email?

Former Member
0 Kudos

Hi Roy,

you can contact me in shubhadip.ghosh@sap.com . Any time. But who will give me points then? ) ...Just Kiddin

Thanks & Regards,

Shubhadip

Answers (0)