Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
HI all,
I have followed the examples on how to write a web service and then compile it.
I used the example at
http://support.ptc.com/cs/help/windchill_hc/wc101_hc/index.jspx?id=IEUG_WSFWriteJavaWS&action=show
And then to connect to this service I have used the example at
However, this is where it falls over. (The client example is for a different service, so I have modified it for the MyJavaService example). I can get it to run from the command line exactly as the example shows, but I need to be able to access it from other places of course.
I have written a simple project in Eclipse to access this example and this is the code
import com.ptc.jws.client.handler.*;
import org.myorg.*;
public class testproj {
public static void main ( String [] args ) throws java.lang.Exception
{
int a = args.length > 0 ? Integer.parseInt ( args[0] ) : 0;
int b = args.length > 1 ? Integer.parseInt ( args[1] ) : 0;
// depending on your security requirements you may need to specify credentials up
// front, or on the command-line where most policies will prompt for them
Credentials.setUsername ( "wcadmin" );
Credentials.setPassword ( "wcadmin" );
// TODO implement your client
MyJavaService4Service service = new MyJavaService4Service();
MyJavaService4 port = service.getMyJavaServicePort ();
//invoke an action
System.out.printf ( "a+b=%d\n", port.add ( a, b ) );
}
}
But I always get a compile error on this line
MyJavaService4Service service = new MyJavaService4Service();
which states that MyJavaService4Service cannot be resolved to a type.
Does anybody know what class or jar I need to include in my build path to make this work. There is no jar for the Service4Service only a class file and if I include that it makes no difference.
Any help on how to make these examples work with Eclipse would be very much appreciated.
Regards
Ben
Ben, I have moved this question to the Windchill Customization space.
Hi Ben,
Have you deployed the service? I believe you might have missed the step. You can examine the jar file in codebase\WEB-INF\lib folder with you <webservicename>.jar.
Regards
Sudhakar
Hi Sudhakar,
Yes I have deployed it and inspected that jar. I'll explain what I have done again.
I have built the service according to the steps at http://support.ptc.com/cs/help/windchill_hc/wc101_hc/index.jspx?id=IEUG_WSFWriteJavaWS&action=show and also run the command in the Windchill shell
ant
And I have then stopped and restarted the Windchill service. At this stage there is the jar file in WEB-INF/lib called MyJavaService.jar
So now I am ready to build a client. I have followed the steps at
These steps say to run ant on an empty main method. I do this.
And then in the file in src_client/org/myorg/MyJavaServiceClient.java I add the code (well take off the comments because the ant script has built in some commented code for you).
I then run
ant compile
ant dist
and it builds a MyJavaServiceClient.jar file into the dist_client folder.
I then run the command ant -jar MyJavaServiceClient.jar 10 20 and it works.
All this is fine. I can run from the command line. But this is rather superfluous because I don't really need a command line service. I need to be able to run it from a java application or a java web project.
So in Eclipse I have tried to simply create a java application exactly the same as MyJavaSeviceClient.java and then I get the MyJavaServiceService cannot be resolved to a type
(You can see above I have had at least 4 attempts at this trying different scenarios, hence why it is called above MyJavaService4 and MyJavaService4Service)
I have included the jar file WEB-INF/lib/MyJavaService.jar which resolves the MyJavaService object, but to resolve the MyJavaServiceService object I also need to include the MyJavaServiceClient.jar in the build path. This seems a bit circular to me. That jar file is built in the ant dist step, which requires that line of code that refers to MyJavaServiceService. So it is not there until you build but then you can't have the line in the code before you build.
And if I run this application (in debug mode), it fails at the first step when setting Credentials with no error. (I've added a try catch to see what was happening but it doesn't even go into the catch but I just realised whilst typing this I should probably remove the throws in the method declaration).
So what I don't understand is why the MyJavaServiceClient.jar is required in the build path and then why it doesn't work in Eclipse. It seems very circular. The jar file required to resolve the MyJavaServiceService is built from the java file that contains that line of code. Completely confusing for me at least.
I need to be able to call the web service from somewhere other than the command line.
There is an example of how to do this in the InfoEngine Guide (page 193 in the latest guide) but it is for Visual Studio and C#. Why isn't there a java example for the same? But maybe that is also not what I want because I cannot test it, becasue we use java and Eclipse for all our development, not VS and C#.
I'm not a java expert and can actually understand the C# example because that is more my expertise, but I actually require java for what we are intending to build.
I realise this is a long post, but I have been working on this for days and feel I am misunderstanding something fundamental to get this to work. Unfortunately the guides only show how to develop this with ant scripts and only for a command line application. I would like to build the client in Eclipse and to be run as a standalone application or web project not on the Windchill server. There has to be a way of achieving this.
Regards
Ben