cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a Web service

Former Member
0 Kudos

Hi,

I have a web dynpro application that can access an external database via EJB. I also have a web module (JSP). In the web dynpro application there is a button that calls a webpage from my web module.

Supposedly, when I click the button, the values in webpage will be taken from my external database (e.g. the text values of my webpage will come from my database).

I have been told to create a web service using my EJB and have to import that web service to my web module using a java class. Can someone point me to a tutorial on how to do this?

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member751941
Active Contributor
0 Kudos
Former Member
0 Kudos

Hi Mithu,

I have already created my EJBs. I've also created the web service. My problem now is how to consume the web service using java class.

Thanks

junwu
Active Contributor
0 Kudos

if you want to call that ejb in web dynpro , you can create ejb model.

if you want to call ejb in web module, it is quit standard, pure java programming.

why you have to get web service involved?

Former Member
0 Kudos

Hi John Wu,

I need web service because my project requires it. It would really be easy just to call ejb using models but I can't do that.

And you're right, I will be needing pure java programming. I've already created my stubs using wsimport of my wsdl. But now I can't incorporate it on my NWDS web module.

former_member751941
Active Contributor
0 Kudos

Hi mlsaldua,

please check this code

public class WsClnt2 {

static final String userid = "test";

static final String password = "init2you";

static String soapRequestMsg = "<ns1:MaterialGetDetail

xmlns:ns1='urn:sap-com:document:sap:soap:functions:mc-style'><Material>R-1111</Material><Plant>1200</Plant><Valuationarea>1200</Valuationarea></ns1:MaterialGetDetail>"

;

static class TheAuthenticator extends Authenticator {

public PasswordAuthentication getPasswordAuthentication() {

return (new PasswordAuthentication(userid,

password.toCharArray()));

}

}

public static void main(String[] args) {

try{

String url =

"

http://host:port/sap/bc/srt/rfc/sap/ZWS_MATERIAL_DETAIL?sap-client=800

";

Authenticator.setDefault(new TheAuthenticator());

MessageFactory msgf = MessageFactory.newInstance();

SOAPMessage msg = msgf.createMessage();

SOAPBody body =

msg.getSOAPPart().getEnvelope().getBody();

DocumentBuilderFactory dbf =

DocumentBuilderFactory.newInstance();

dbf.setNamespaceAware(true);

DocumentBuilder db = dbf.newDocumentBuilder();

ByteArrayInputStream bis=new

ByteArrayInputStream(soapRequestMsg.getBytes());

org.w3c.dom.Document doc = db.parse(bis);

body.addDocument(doc);

SOAPConnection connection =

SOAPConnectionFactory.newInstance().createConnection();

SOAPMessage reply = connection.call(msg, url);

reply.writeTo(System.out);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

<classpath>

<classpathentry kind="src" path=""/>

<classpathentry kind="con"

path="org.eclipse.jdt.launching.JRE_CONTAINER"/>

<classpathentry kind="lib" path="C:/SAAJ/saaj-api.jar"/>

<classpathentry kind="lib" path="C:/SAAJ/saaj-impl.jar"/>

<classpathentry kind="lib" path="C:/bi_sdk/lib/activation.jar"/>

<classpathentry kind="lib" path="C:/SAAJ/New

Folder/xercesImpl-1.5.jar"/>

<classpathentry kind="lib" path="C:/SAAJ/xerces.jar"/>

<classpathentry kind="lib" path="C:/SAAJ/xmlpublic-2.0.0.jar"/>

<classpathentry kind="lib" path="C:/SAAJ/jaxb-xalan-1.5.jar"/>

<classpathentry kind="lib" path="C:/SAAJ/jaxws-api-2.1-1.jar"/>

<classpathentry kind="lib" path="C:/SAAJ/jaxb-api-1.5.jar"/>

<classpathentry kind="lib" path="C:/jdk1.5.0_12/jre/lib/rt.jar"/>

<classpathentry kind="output" path=""/>

</classpath>

Thanks and Regards,

Mithu

Former Member
0 Kudos

Hi,

Search for EJB webservice in NWDS help.

There is step by step guide there.

Regards,

Himanshu