on 03-09-2005 9:29 AM
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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
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
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
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
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?
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
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
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...)
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
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?
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
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
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
User | Count |
---|---|
81 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.