From: Charles Hottel on

"Charles Hottel" <chottel(a)earthlink.net> wrote in message
news:GPp5i.13254$Ut6.2582(a)newsread1.news.pas.earthlink.net...
>
> "Charles Hottel" <chottel(a)earthlink.net> wrote in message
> news:%g45i.18421$3P3.8338(a)newsread3.news.pas.earthlink.net...
>>
>> "Pete Dashwood" <dashwood(a)removethis.enternet.co.nz> wrote in message
>> news:5bhj8jF2rrq02U1(a)mid.individual.net...
>>>
>>> "Charles Hottel" <chottel(a)earthlink.net> wrote in message
>>> news:6iM4i.12447$Ut6.3969(a)newsread1.news.pas.earthlink.net...
>>>>
>>> <snip>
>>>>
>>>> I have learned far more about OO from learning Java than from C++ or OO
>>>> COBOL books. It is no silver bullet but I can see how it improves some
>>>> things.
>>>
>>> Yes, I had exactly the same experience. OO is such an innate part of
>>> Java that it just seems completely natural.
>>>
>>> For me, OO opens the way to component based design and programming. The
>>> code posted in this thread is a concrete example of what I have been
>>> talking about; the web service is simply a component exposed to the
>>> Internet. You can plug it into your applications and not need to
>>> maintain it or worry about it. (Conceptually it is just like an
>>> extension of the OS; you use it every day and expect it to work as
>>> specified. It does what it does.)
>>>
>>> Components may be the keys to the kingdom, unlocking Lamba functions and
>>> functional programming and helping to move us toward Kurzweil's
>>> Singularity.
>>>
>>> If you have a COBOL compiler on your home system, that supports OO, I
>>> would urge you to try the code. (We will have a MicroFocus version any
>>> time now, as well as the original Fujitsu NetCOBOL version which will
>>> work with ANY version of Fujitsu COBOL, right back to version 3.)
>>>
>>> Why not attempt a Java Class to access it? (Kinda cool to have COBOL
>>> being invoked by Java across thousands of miles :-))
>>>
>>> Researching how to access web services from Java is probably very useful
>>> for both your Java and your web services learning.
>>>
>>> If you get stuck, I can help.
>>>
> <snip>
>
> Well I made an attempt at invoking your web service from Java, but I did
> not have much spare time so it was not completely successful.
>
> I only have one book that talk about Java and web services: Just Java 2
> 6th edition and it is a little dated (2004). Chapter 28, mostly talks
> about two beta programs through Amazon ans Google. While they looked
> straightforward enough I decided I did not have time for that approach.
>
> There is also the Apache Axis package. I think when I have more time I
> will try using it.
>
> Basically they all process the WSDL and generate Java you can use in you
> program to access the web servive.
>
> I googled on "java invoke web service" and got more than 54 million hits
> and there is lots of good stuff but most of it too long for the remaining
> time I had left. At http://www.codeproject.com/soap/WSfromJava.asp I found
> what looked like something short enough to try. It was a simple applet
> that invoked a web service called ConcatWithSpace. It takes two string as
> input and returns them concatenated with a space in the middle. One
> drawback is it is for JDK 1.1. The entire web article is pretty short.
>
> I downloaded the code, a Java program for the applet, which also has a
> SoapRequestBuilder class, and a html page that invokes the applet and
> passes the required parameters. I thought I could figure out the parms
> from your WSDL and just change the web page to invoke your web service,
> but I must be doing something wrong. I tried many variations but I always
> get: "Error: access denied (java.net.SocketPermission)". Well I realize I
> am not knowledgeable yet in this area of Java which is one reason for
> making the attempt. Anyway I am sure this approach is not the best in
> general and Axis is a better way to go. I see O''Reilly has a Java Web
> Services book. Just what I need, another book added to my already very
> long list.
>
> Here is the original html code for invoking the ConcatWithSpace service,
> which I assume worked:
>
> <HTML><HEAD>
> <TITLE>Applet HTML Page</TITLE>
> </HEAD>
>
> <BODY>
> <H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
>
> <applet code="SOAPexample" width=400 height=50>
> <param name="server" value="127.0.0.1">
> <param name="method" value="ConcatWithSpace">
> <param name="xmlnamespace" value="http://tempuri.org/">
> <param name="webservicepath" value="/SimpleService/Service1.asmx">
> <param name="string1" value="David">
> <param name="string2" value="Hobbs">
> </applet>
>
> <HR WIDTH="100%">
> </BODY></HTML>
>
> Here is the modified version of the html:
>
> <HTML><HEAD>
> <TITLE>Applet HTML Page</TITLE>
> </HEAD>
>
> <BODY>
> <H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
>
> <applet code="SOAPexample" width=400 height=50>
> <param name="server" value="http://primacomputing.co.nz/AVSWebService/">
> <param name="method" value="ValidateNZAddress">
> <param name="xmlnamespace"
> value="http://primacomputing.co.nz/AVSWebService/">
> <param name="webservicepath" value="/AVSWebService.asmx?WSDL">
> <param name="string1" value="97 21ST AVE TAURANGA">
> </applet>
>
> <HR WIDTH="100%">
> </BODY></HTML>
>
> Here is the original Java code for the applet. I ran out of time ( I got
> interrupted) before I could try to modify it. One change it needs for
> certain is to comment out the logic for the second parameter being passed
> as your web service only expects one input paramter. I did try running it
> anyway in the hope that it would just ignore the second parameter. Perhaps
> you or someone here can get it running. I am so sure that it is not the
> best approach in general that I will wait until I can devote proper time
> to the Axis approach. Well there might be even better ways, after all I am
> just a couple hours into my investigations.
>
> import java.applet.Applet;
> import java.awt.*;
> import java.net.*;
> import java.util.*;
> import java.io.*;
>
> public class SOAPexample extends Applet {
>
> private String response = "Nothing";
>
> public void init() {
> SoapRequestBuilder s = new SoapRequestBuilder();
> s.Server = getParameter("server");
> s.MethodName = getParameter("method");
> s.XmlNamespace = getParameter("xmlnamespace");
> s.WebServicePath = getParameter("webservicepath");
> s.SoapAction = s.XmlNamespace+s.MethodName;
> s.AddParameter("one", getParameter("string1"));
> //s.AddParameter("two", getParameter("string2"));
> response = s.sendRequest();
> repaint();
> }
>
> public void paint(Graphics g) {
> g.setColor(Color.black);
> Font f = new Font("TimesRoman", 0, 20);
> g.setFont(f);
> g.drawString(response, 10, 20);
> }
>
> public void start() {
> repaint();
> }
> }
>
> class SoapRequestBuilder {
> String Server = "";
> String WebServicePath = "";
> String SoapAction = "";
> String MethodName = "";
> String XmlNamespace = "";
> private Vector ParamNames = new Vector();
> private Vector ParamData = new Vector();
>
> public void AddParameter(String Name, String Data) {
> ParamNames.addElement( (Object) Name);
> ParamData.addElement( (Object) Data);
> }
>
> public String sendRequest() {
> String retval = "";
> Socket socket = null;
> try {
> socket = new Socket(Server, 80);
> }
> catch (Exception ex1) {
> return ("Error: "+ex1.getMessage());
> }
>
> try {
> OutputStream os = socket.getOutputStream();
> boolean autoflush = true;
> PrintWriter out = new PrintWriter(socket.getOutputStream(),
> autoflush);
> BufferedReader in = new BufferedReader(new InputStreamReader(socket.
> getInputStream()));
>
> int length = 295 + (MethodName.length() * 2) + XmlNamespace.length();
> for (int t = 0; t < ParamNames.size(); t++) {
> String name = (String) ParamNames.elementAt(t);
> String data = (String) ParamData.elementAt(t);
> length += name.length();
> length += data.length();
> }
>
> // send an HTTP request to the web service
> out.println("POST " + WebServicePath + " HTTP/1.1");
> out.println("Host: localhost:80");
> out.println("Content-Type: text/xml; charset=utf-8");
> out.println("Content-Length: " + String.valueOf(length));
> out.println("SOAPAction: \"" + SoapAction + "\"");
> out.println("Connection: Close");
> out.println();
>
> out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
> out.println("<soap:Envelope
> xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
> xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
> xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
> out.println("<soap:Body>");
> out.println("<" + MethodName + " xmlns=\"" + XmlNamespace + "\">");
> //Parameters passed to the method are added here
> for (int t = 0; t < ParamNames.size(); t++) {
> String name = (String) ParamNames.elementAt(t);
> String data = (String) ParamData.elementAt(t);
> out.println("<" + name + ">" + data + "</" + name + ">");
> }
> out.println("</" + MethodName + ">");
> out.println("</soap:Body>");
> out.println("</soap:Envelope>");
> out.println();
>
> // Read the response from the server ... times out if the response
> takes
> // more than 3 seconds
> String inputLine;
> StringBuffer sb = new StringBuffer(1000);
>
> int wait_seconds = 3;
> boolean timeout = false;
> long m = System.currentTimeMillis();
> while ( (inputLine = in.readLine()) != null && !timeout) {
> sb.append(inputLine + "\n");
> if ( (System.currentTimeMillis() - m) > (1000 * wait_seconds))
> timeout = true;
> }
> in.close();
>
> // The StringBuffer sb now contains the complete result from the
> // webservice in XML format. You can parse this XML if you want to
> // get more complicated results than a single value.
>
> if (!timeout) {
> String returnparam = MethodName + "Result";
> int start = sb.toString().indexOf("<" + returnparam + ">") +
> returnparam.length() + 2;
> int end = sb.toString().indexOf("</" + returnparam + ">");
>
> //Extract a singe return parameter
> retval = sb.toString().substring(start, end);
> }
> else {
> retval="Error: response timed out.";
> }
>
> socket.close();
> }
> catch (Exception ex) {
> return ("Error: cannot communicate.");
> }
>
> return retval;
> }
> }
>
>

Sorry the web service is SimpleService/Service1.asmx and the method name is
ConcatWithSpace.


From: Rene_Surop on
On May 24, 12:59 pm, "James J. Gavan" <jgavandeletet...(a)shaw.ca>
wrote:
>
> Give it a shot Rene and confirm that it works for you !
>

It worked! Well... you did my homework. Thanks Jimmy.

But then I have to build my site for it.... data, COMs, WSDL for you
to view or experiment. I'm going to "emboss" your code and format it
as my template. After reading Price's OO Cobol book it teaches me OO
in Cobol, since then I never really look at procedural programming
anymore (in concept). Though procedurally speaking, all codes are
interpreted by the computer in sequence anyway.

I download the MS SOAP toolkit as well.... got it before it is posted
here from the PDF docs of Microfocus site. Got a few problems with the
COMxxx.OCX files which is "not" included in the downloaded file... but
you can download those OCXs from other sites anyway.

Great job Cobol coders!! Well, for some :)

I'm very thankful really.

From: Pete Dashwood on
Hi Charlie,

I had a quick look at this but there are too many things wrong with it for
me to fix it at the moment.

The Web Page is fine (I have one question on it but don't have time to check
it out) but there are problems in the Java Applet. If the SOAP Class is
invoked it shouldn't require a socket connection (it will make its own) and
it looks to me as if you are doing something that is very low level (and
unnecessary, if the SOAP COM server is used, as Jimmy and I did.)

I'm flat out this weekend doing a major address conversion with the AVS
engine, but I'll have a look at it next week if none of the Java experts
here have picked it up meanwhile, or if you haven't been able to do it
yourself...

Thanks for having a go... I bet you learned something :-)

Pete.

TOP POST - nothing new below.



"Charles Hottel" <chottel(a)earthlink.net> wrote in message
news:GPp5i.13254$Ut6.2582(a)newsread1.news.pas.earthlink.net...
>
> "Charles Hottel" <chottel(a)earthlink.net> wrote in message
> news:%g45i.18421$3P3.8338(a)newsread3.news.pas.earthlink.net...
>>
>> "Pete Dashwood" <dashwood(a)removethis.enternet.co.nz> wrote in message
>> news:5bhj8jF2rrq02U1(a)mid.individual.net...
>>>
>>> "Charles Hottel" <chottel(a)earthlink.net> wrote in message
>>> news:6iM4i.12447$Ut6.3969(a)newsread1.news.pas.earthlink.net...
>>>>
>>> <snip>
>>>>
>>>> I have learned far more about OO from learning Java than from C++ or OO
>>>> COBOL books. It is no silver bullet but I can see how it improves some
>>>> things.
>>>
>>> Yes, I had exactly the same experience. OO is such an innate part of
>>> Java that it just seems completely natural.
>>>
>>> For me, OO opens the way to component based design and programming. The
>>> code posted in this thread is a concrete example of what I have been
>>> talking about; the web service is simply a component exposed to the
>>> Internet. You can plug it into your applications and not need to
>>> maintain it or worry about it. (Conceptually it is just like an
>>> extension of the OS; you use it every day and expect it to work as
>>> specified. It does what it does.)
>>>
>>> Components may be the keys to the kingdom, unlocking Lamba functions and
>>> functional programming and helping to move us toward Kurzweil's
>>> Singularity.
>>>
>>> If you have a COBOL compiler on your home system, that supports OO, I
>>> would urge you to try the code. (We will have a MicroFocus version any
>>> time now, as well as the original Fujitsu NetCOBOL version which will
>>> work with ANY version of Fujitsu COBOL, right back to version 3.)
>>>
>>> Why not attempt a Java Class to access it? (Kinda cool to have COBOL
>>> being invoked by Java across thousands of miles :-))
>>>
>>> Researching how to access web services from Java is probably very useful
>>> for both your Java and your web services learning.
>>>
>>> If you get stuck, I can help.
>>>
> <snip>
>
> Well I made an attempt at invoking your web service from Java, but I did
> not have much spare time so it was not completely successful.
>
> I only have one book that talk about Java and web services: Just Java 2
> 6th edition and it is a little dated (2004). Chapter 28, mostly talks
> about two beta programs through Amazon ans Google. While they looked
> straightforward enough I decided I did not have time for that approach.
>
> There is also the Apache Axis package. I think when I have more time I
> will try using it.
>
> Basically they all process the WSDL and generate Java you can use in you
> program to access the web servive.
>
> I googled on "java invoke web service" and got more than 54 million hits
> and there is lots of good stuff but most of it too long for the remaining
> time I had left. At http://www.codeproject.com/soap/WSfromJava.asp I found
> what looked like something short enough to try. It was a simple applet
> that invoked a web service called ConcatWithSpace. It takes two string as
> input and returns them concatenated with a space in the middle. One
> drawback is it is for JDK 1.1. The entire web article is pretty short.
>
> I downloaded the code, a Java program for the applet, which also has a
> SoapRequestBuilder class, and a html page that invokes the applet and
> passes the required parameters. I thought I could figure out the parms
> from your WSDL and just change the web page to invoke your web service,
> but I must be doing something wrong. I tried many variations but I always
> get: "Error: access denied (java.net.SocketPermission)". Well I realize I
> am not knowledgeable yet in this area of Java which is one reason for
> making the attempt. Anyway I am sure this approach is not the best in
> general and Axis is a better way to go. I see O''Reilly has a Java Web
> Services book. Just what I need, another book added to my already very
> long list.
>
> Here is the original html code for invoking the ConcatWithSpace service,
> which I assume worked:
>
> <HTML><HEAD>
> <TITLE>Applet HTML Page</TITLE>
> </HEAD>
>
> <BODY>
> <H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
>
> <applet code="SOAPexample" width=400 height=50>
> <param name="server" value="127.0.0.1">
> <param name="method" value="ConcatWithSpace">
> <param name="xmlnamespace" value="http://tempuri.org/">
> <param name="webservicepath" value="/SimpleService/Service1.asmx">
> <param name="string1" value="David">
> <param name="string2" value="Hobbs">
> </applet>
>
> <HR WIDTH="100%">
> </BODY></HTML>
>
> Here is the modified version of the html:
>
> <HTML><HEAD>
> <TITLE>Applet HTML Page</TITLE>
> </HEAD>
>
> <BODY>
> <H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
>
> <applet code="SOAPexample" width=400 height=50>
> <param name="server" value="http://primacomputing.co.nz/AVSWebService/">
> <param name="method" value="ValidateNZAddress">
> <param name="xmlnamespace"
> value="http://primacomputing.co.nz/AVSWebService/">
> <param name="webservicepath" value="/AVSWebService.asmx?WSDL">
> <param name="string1" value="97 21ST AVE TAURANGA">
> </applet>
>
> <HR WIDTH="100%">
> </BODY></HTML>
>
> Here is the original Java code for the applet. I ran out of time ( I got
> interrupted) before I could try to modify it. One change it needs for
> certain is to comment out the logic for the second parameter being passed
> as your web service only expects one input paramter. I did try running it
> anyway in the hope that it would just ignore the second parameter. Perhaps
> you or someone here can get it running. I am so sure that it is not the
> best approach in general that I will wait until I can devote proper time
> to the Axis approach. Well there might be even better ways, after all I am
> just a couple hours into my investigations.
>
> import java.applet.Applet;
> import java.awt.*;
> import java.net.*;
> import java.util.*;
> import java.io.*;
>
> public class SOAPexample extends Applet {
>
> private String response = "Nothing";
>
> public void init() {
> SoapRequestBuilder s = new SoapRequestBuilder();
> s.Server = getParameter("server");
> s.MethodName = getParameter("method");
> s.XmlNamespace = getParameter("xmlnamespace");
> s.WebServicePath = getParameter("webservicepath");
> s.SoapAction = s.XmlNamespace+s.MethodName;
> s.AddParameter("one", getParameter("string1"));
> //s.AddParameter("two", getParameter("string2"));
> response = s.sendRequest();
> repaint();
> }
>
> public void paint(Graphics g) {
> g.setColor(Color.black);
> Font f = new Font("TimesRoman", 0, 20);
> g.setFont(f);
> g.drawString(response, 10, 20);
> }
>
> public void start() {
> repaint();
> }
> }
>
> class SoapRequestBuilder {
> String Server = "";
> String WebServicePath = "";
> String SoapAction = "";
> String MethodName = "";
> String XmlNamespace = "";
> private Vector ParamNames = new Vector();
> private Vector ParamData = new Vector();
>
> public void AddParameter(String Name, String Data) {
> ParamNames.addElement( (Object) Name);
> ParamData.addElement( (Object) Data);
> }
>
> public String sendRequest() {
> String retval = "";
> Socket socket = null;
> try {
> socket = new Socket(Server, 80);
> }
> catch (Exception ex1) {
> return ("Error: "+ex1.getMessage());
> }
>
> try {
> OutputStream os = socket.getOutputStream();
> boolean autoflush = true;
> PrintWriter out = new PrintWriter(socket.getOutputStream(),
> autoflush);
> BufferedReader in = new BufferedReader(new InputStreamReader(socket.
> getInputStream()));
>
> int length = 295 + (MethodName.length() * 2) + XmlNamespace.length();
> for (int t = 0; t < ParamNames.size(); t++) {
> String name = (String) ParamNames.elementAt(t);
> String data = (String) ParamData.elementAt(t);
> length += name.length();
> length += data.length();
> }
>
> // send an HTTP request to the web service
> out.println("POST " + WebServicePath + " HTTP/1.1");
> out.println("Host: localhost:80");
> out.println("Content-Type: text/xml; charset=utf-8");
> out.println("Content-Length: " + String.valueOf(length));
> out.println("SOAPAction: \"" + SoapAction + "\"");
> out.println("Connection: Close");
> out.println();
>
> out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
> out.println("<soap:Envelope
> xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
> xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
> xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
> out.println("<soap:Body>");
> out.println("<" + MethodName + " xmlns=\"" + XmlNamespace + "\">");
> //Parameters passed to the method are added here
> for (int t = 0; t < ParamNames.size(); t++) {
> String name = (String) ParamNames.elementAt(t);
> String data = (String) ParamData.elementAt(t);
> out.println("<" + name + ">" + data + "</" + name + ">");
> }
> out.println("</" + MethodName + ">");
> out.println("</soap:Body>");
> out.println("</soap:Envelope>");
> out.println();
>
> // Read the response from the server ... times out if the response
> takes
> // more than 3 seconds
> String inputLine;
> StringBuffer sb = new StringBuffer(1000);
>
> int wait_seconds = 3;
> boolean timeout = false;
> long m = System.currentTimeMillis();
> while ( (inputLine = in.readLine()) != null && !timeout) {
> sb.append(inputLine + "\n");
> if ( (System.currentTimeMillis() - m) > (1000 * wait_seconds))
> timeout = true;
> }
> in.close();
>
> // The StringBuffer sb now contains the complete result from the
> // webservice in XML format. You can parse this XML if you want to
> // get more complicated results than a single value.
>
> if (!timeout) {
> String returnparam = MethodName + "Result";
> int start = sb.toString().indexOf("<" + returnparam + ">") +
> returnparam.length() + 2;
> int end = sb.toString().indexOf("</" + returnparam + ">");
>
> //Extract a singe return parameter
> retval = sb.toString().substring(start, end);
> }
> else {
> retval="Error: response timed out.";
> }
>
> socket.close();
> }
> catch (Exception ex) {
> return ("Error: cannot communicate.");
> }
>
> return retval;
> }
> }
>
>


From: Charles Hottel on
Top Post not more below

Hi! Pete,

I downloaded Axis 1.4 and if it works as the documentation says I believe it
would not be too difficult to do the few steps required to invoke a web
service.
Not sure when I might get around to it though.

My wife is pregnant and we spent today in the emergency room as she was
experiencing severe pain on her left side. They think the cause of the pain
is not a threat to the baby, but the sonogram showed a possible birth defect
( a hole in the abdominal wall), something like a hernia. Tomorrow they will
give us the name of a specialist. If this is the only problem and if the
baby can develop long enough then he/she may have a chance. However 25% to
40% of the babies with this problem have other birth defects. I am feeling
kind of low and web services will have to take a back seat for quite a
while.

Sorry to lay this on you. I do not have a lot of friends and some of the
ones I did have disapproved of my latest marraige and abandoned our
friendship. I tried calling my two children but they are not home. The
people on this group are pretty much the closest thing I have to friends and
I just had to let this out to someone.

"Pete Dashwood" <dashwood(a)removethis.enternet.co.nz> wrote in message
news:5bnqv4F2rp0c0U1(a)mid.individual.net...
> Hi Charlie,
>
> I had a quick look at this but there are too many things wrong with it for
> me to fix it at the moment.
>
> The Web Page is fine (I have one question on it but don't have time to
> check it out) but there are problems in the Java Applet. If the SOAP Class
> is invoked it shouldn't require a socket connection (it will make its own)
> and it looks to me as if you are doing something that is very low level
> (and unnecessary, if the SOAP COM server is used, as Jimmy and I did.)
>
> I'm flat out this weekend doing a major address conversion with the AVS
> engine, but I'll have a look at it next week if none of the Java experts
> here have picked it up meanwhile, or if you haven't been able to do it
> yourself...
>
> Thanks for having a go... I bet you learned something :-)
>
> Pete.
>
> TOP POST - nothing new below.
>
>
>
> "Charles Hottel" <chottel(a)earthlink.net> wrote in message
> news:GPp5i.13254$Ut6.2582(a)newsread1.news.pas.earthlink.net...
>>
>> "Charles Hottel" <chottel(a)earthlink.net> wrote in message
>> news:%g45i.18421$3P3.8338(a)newsread3.news.pas.earthlink.net...
>>>
>>> "Pete Dashwood" <dashwood(a)removethis.enternet.co.nz> wrote in message
>>> news:5bhj8jF2rrq02U1(a)mid.individual.net...
>>>>
>>>> "Charles Hottel" <chottel(a)earthlink.net> wrote in message
>>>> news:6iM4i.12447$Ut6.3969(a)newsread1.news.pas.earthlink.net...
>>>>>
>>>> <snip>
>>>>>
>>>>> I have learned far more about OO from learning Java than from C++ or
>>>>> OO COBOL books. It is no silver bullet but I can see how it improves
>>>>> some things.
>>>>
>>>> Yes, I had exactly the same experience. OO is such an innate part of
>>>> Java that it just seems completely natural.
>>>>
>>>> For me, OO opens the way to component based design and programming. The
>>>> code posted in this thread is a concrete example of what I have been
>>>> talking about; the web service is simply a component exposed to the
>>>> Internet. You can plug it into your applications and not need to
>>>> maintain it or worry about it. (Conceptually it is just like an
>>>> extension of the OS; you use it every day and expect it to work as
>>>> specified. It does what it does.)
>>>>
>>>> Components may be the keys to the kingdom, unlocking Lamba functions
>>>> and functional programming and helping to move us toward Kurzweil's
>>>> Singularity.
>>>>
>>>> If you have a COBOL compiler on your home system, that supports OO, I
>>>> would urge you to try the code. (We will have a MicroFocus version any
>>>> time now, as well as the original Fujitsu NetCOBOL version which will
>>>> work with ANY version of Fujitsu COBOL, right back to version 3.)
>>>>
>>>> Why not attempt a Java Class to access it? (Kinda cool to have COBOL
>>>> being invoked by Java across thousands of miles :-))
>>>>
>>>> Researching how to access web services from Java is probably very
>>>> useful for both your Java and your web services learning.
>>>>
>>>> If you get stuck, I can help.
>>>>
>> <snip>
>>
>> Well I made an attempt at invoking your web service from Java, but I did
>> not have much spare time so it was not completely successful.
>>
>> I only have one book that talk about Java and web services: Just Java 2
>> 6th edition and it is a little dated (2004). Chapter 28, mostly talks
>> about two beta programs through Amazon ans Google. While they looked
>> straightforward enough I decided I did not have time for that approach.
>>
>> There is also the Apache Axis package. I think when I have more time I
>> will try using it.
>>
>> Basically they all process the WSDL and generate Java you can use in you
>> program to access the web servive.
>>
>> I googled on "java invoke web service" and got more than 54 million hits
>> and there is lots of good stuff but most of it too long for the remaining
>> time I had left. At http://www.codeproject.com/soap/WSfromJava.asp I
>> found what looked like something short enough to try. It was a simple
>> applet that invoked a web service called ConcatWithSpace. It takes two
>> string as input and returns them concatenated with a space in the middle.
>> One drawback is it is for JDK 1.1. The entire web article is pretty
>> short.
>>
>> I downloaded the code, a Java program for the applet, which also has a
>> SoapRequestBuilder class, and a html page that invokes the applet and
>> passes the required parameters. I thought I could figure out the parms
>> from your WSDL and just change the web page to invoke your web service,
>> but I must be doing something wrong. I tried many variations but I always
>> get: "Error: access denied (java.net.SocketPermission)". Well I realize
>> I am not knowledgeable yet in this area of Java which is one reason for
>> making the attempt. Anyway I am sure this approach is not the best in
>> general and Axis is a better way to go. I see O''Reilly has a Java Web
>> Services book. Just what I need, another book added to my already very
>> long list.
>>
>> Here is the original html code for invoking the ConcatWithSpace service,
>> which I assume worked:
>>
>> <HTML><HEAD>
>> <TITLE>Applet HTML Page</TITLE>
>> </HEAD>
>>
>> <BODY>
>> <H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
>>
>> <applet code="SOAPexample" width=400 height=50>
>> <param name="server" value="127.0.0.1">
>> <param name="method" value="ConcatWithSpace">
>> <param name="xmlnamespace" value="http://tempuri.org/">
>> <param name="webservicepath" value="/SimpleService/Service1.asmx">
>> <param name="string1" value="David">
>> <param name="string2" value="Hobbs">
>> </applet>
>>
>> <HR WIDTH="100%">
>> </BODY></HTML>
>>
>> Here is the modified version of the html:
>>
>> <HTML><HEAD>
>> <TITLE>Applet HTML Page</TITLE>
>> </HEAD>
>>
>> <BODY>
>> <H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
>>
>> <applet code="SOAPexample" width=400 height=50>
>> <param name="server" value="http://primacomputing.co.nz/AVSWebService/">
>> <param name="method" value="ValidateNZAddress">
>> <param name="xmlnamespace"
>> value="http://primacomputing.co.nz/AVSWebService/">
>> <param name="webservicepath" value="/AVSWebService.asmx?WSDL">
>> <param name="string1" value="97 21ST AVE TAURANGA">
>> </applet>
>>
>> <HR WIDTH="100%">
>> </BODY></HTML>
>>
>> Here is the original Java code for the applet. I ran out of time ( I got
>> interrupted) before I could try to modify it. One change it needs for
>> certain is to comment out the logic for the second parameter being passed
>> as your web service only expects one input paramter. I did try running it
>> anyway in the hope that it would just ignore the second parameter.
>> Perhaps you or someone here can get it running. I am so sure that it is
>> not the best approach in general that I will wait until I can devote
>> proper time to the Axis approach. Well there might be even better ways,
>> after all I am just a couple hours into my investigations.
>>
>> import java.applet.Applet;
>> import java.awt.*;
>> import java.net.*;
>> import java.util.*;
>> import java.io.*;
>>
>> public class SOAPexample extends Applet {
>>
>> private String response = "Nothing";
>>
>> public void init() {
>> SoapRequestBuilder s = new SoapRequestBuilder();
>> s.Server = getParameter("server");
>> s.MethodName = getParameter("method");
>> s.XmlNamespace = getParameter("xmlnamespace");
>> s.WebServicePath = getParameter("webservicepath");
>> s.SoapAction = s.XmlNamespace+s.MethodName;
>> s.AddParameter("one", getParameter("string1"));
>> //s.AddParameter("two", getParameter("string2"));
>> response = s.sendRequest();
>> repaint();
>> }
>>
>> public void paint(Graphics g) {
>> g.setColor(Color.black);
>> Font f = new Font("TimesRoman", 0, 20);
>> g.setFont(f);
>> g.drawString(response, 10, 20);
>> }
>>
>> public void start() {
>> repaint();
>> }
>> }
>>
>> class SoapRequestBuilder {
>> String Server = "";
>> String WebServicePath = "";
>> String SoapAction = "";
>> String MethodName = "";
>> String XmlNamespace = "";
>> private Vector ParamNames = new Vector();
>> private Vector ParamData = new Vector();
>>
>> public void AddParameter(String Name, String Data) {
>> ParamNames.addElement( (Object) Name);
>> ParamData.addElement( (Object) Data);
>> }
>>
>> public String sendRequest() {
>> String retval = "";
>> Socket socket = null;
>> try {
>> socket = new Socket(Server, 80);
>> }
>> catch (Exception ex1) {
>> return ("Error: "+ex1.getMessage());
>> }
>>
>> try {
>> OutputStream os = socket.getOutputStream();
>> boolean autoflush = true;
>> PrintWriter out = new PrintWriter(socket.getOutputStream(),
>> autoflush);
>> BufferedReader in = new BufferedReader(new InputStreamReader(socket.
>> getInputStream()));
>>
>> int length = 295 + (MethodName.length() * 2) +
>> XmlNamespace.length();
>> for (int t = 0; t < ParamNames.size(); t++) {
>> String name = (String) ParamNames.elementAt(t);
>> String data = (String) ParamData.elementAt(t);
>> length += name.length();
>> length += data.length();
>> }
>>
>> // send an HTTP request to the web service
>> out.println("POST " + WebServicePath + " HTTP/1.1");
>> out.println("Host: localhost:80");
>> out.println("Content-Type: text/xml; charset=utf-8");
>> out.println("Content-Length: " + String.valueOf(length));
>> out.println("SOAPAction: \"" + SoapAction + "\"");
>> out.println("Connection: Close");
>> out.println();
>>
>> out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
>> out.println("<soap:Envelope
>> xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
>> xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"
>> xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
>> out.println("<soap:Body>");
>> out.println("<" + MethodName + " xmlns=\"" + XmlNamespace + "\">");
>> //Parameters passed to the method are added here
>> for (int t = 0; t < ParamNames.size(); t++) {
>> String name = (String) ParamNames.elementAt(t);
>> String data = (String) ParamData.elementAt(t);
>> out.println("<" + name + ">" + data + "</" + name + ">");
>> }
>> out.println("</" + MethodName + ">");
>> out.println("</soap:Body>");
>> out.println("</soap:Envelope>");
>> out.println();
>>
>> // Read the response from the server ... times out if the response
>> takes
>> // more than 3 seconds
>> String inputLine;
>> StringBuffer sb = new StringBuffer(1000);
>>
>> int wait_seconds = 3;
>> boolean timeout = false;
>> long m = System.currentTimeMillis();
>> while ( (inputLine = in.readLine()) != null && !timeout) {
>> sb.append(inputLine + "\n");
>> if ( (System.currentTimeMillis() - m) > (1000 * wait_seconds))
>> timeout = true;
>> }
>> in.close();
>>
>> // The StringBuffer sb now contains the complete result from the
>> // webservice in XML format. You can parse this XML if you want to
>> // get more complicated results than a single value.
>>
>> if (!timeout) {
>> String returnparam = MethodName + "Result";
>> int start = sb.toString().indexOf("<" + returnparam + ">") +
>> returnparam.length() + 2;
>> int end = sb.toString().indexOf("</" + returnparam + ">");
>>
>> //Extract a singe return parameter
>> retval = sb.toString().substring(start, end);
>> }
>> else {
>> retval="Error: response timed out.";
>> }
>>
>> socket.close();
>> }
>> catch (Exception ex) {
>> return ("Error: cannot communicate.");
>> }
>>
>> return retval;
>> }
>> }
>>
>>
>
>


From: Pete Dashwood on

"Charles Hottel" <chottel(a)earthlink.net> wrote in message
news:6dL6i.16043$j63.2521(a)newsread2.news.pas.earthlink.net...
> Top Post not more below
>
> Hi! Pete,
>
> I downloaded Axis 1.4 and if it works as the documentation says I believe
> it would not be too difficult to do the few steps required to invoke a web
> service.
> Not sure when I might get around to it though.
>
> My wife is pregnant and we spent today in the emergency room as she was
> experiencing severe pain on her left side. They think the cause of the
> pain is not a threat to the baby, but the sonogram showed a possible birth
> defect ( a hole in the abdominal wall), something like a hernia. Tomorrow
> they will give us the name of a specialist. If this is the only problem
> and if the baby can develop long enough then he/she may have a chance.
> However 25% to 40% of the babies with this problem have other birth
> defects. I am feeling kind of low and web services will have to take a
> back seat for quite a while.
>
> Sorry to lay this on you.

Absolutely do NOT apologise... :-) There isn't much any of us here can do,
apart from give you moral support. Speaking only for myself, you have it.


> I do not have a lot of friends and some of the ones I did have disapproved
> of my latest marraige and abandoned our friendship.

With "friends" like that, you don't need enemies. People who would judge you
for your personal actions, which have nothing to do with anyone else, are
people who you are probably better off without.

> I tried calling my two children but they are not home. The people on this
> group are pretty much the closest thing I have to friends and I just had
> to let this out to someone.

I understand. Glad you did. I'm sure some here will know what you are going
through, and most can empathise with the stress you are under.

Don't worry at all about the web services :-)

My exercise over the weekend went very successfully and I am under less
pressure now than I was, although I still have a huge amount of work to do
on the AVS web site. (I spent most of this morning furthering my education
via a Web Cast on Master Pages and Themes (all really good stuff; I am
persuaded to stop with CSS and go to themes instead :-)))

On the web service from Java...
I see the real problem as being able to access COM from Java (Once you
establish connection to the SOAP COM proxy, the rest is just stamp
collecting :-)). Bearing this in mind, I found that IBM are offering an
approach that is free and looks very useful. I have downloaded their
Bridge2Java software from the article "Bridging the gap to COM"

http://www.ibm.com/developerworks/java/library/j-bridge/

From my web searches I found a number of offerings that did the same; some
of them were really excellent, but expensive...

If I can find some time and need a break from C# and Web stuff, I'll attempt
to implement the Java link to the web service.

However, it might be interesting to compare the IBM approach with the Axis
one, so please do it if you have time or need to bury yourself in something
that may help to take your mind off your immmediate problems. (In the course
of my life I have found working to be a very useful therapy when trauma
strikes...but that might just be me.)

Meantime, very best wishes for a safe delivery with mother and child both
fine. Try not to let it get you down.

Pete.



<previous unreferenced snipped>


First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8
Prev: Microfocus Cobol "SLEEP" routine
Next: Help with Tcal