You should note that the example uses WASP, not Apache SOAP. Scott Nichol
----- Original Message ----- From: "Kaushik Patra" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, February 20, 2002 8:37 PM Subject: Re: java client for .NET : need SOAPMapping sample code Hi Elise, please go through the document and try if it is of any help to u. regards kaushik Code Examples Now we'll show a few Web services interoperability examples. We will use a simple banking application that is capable of keeping track of customers, accounts, and account balances. We will also use the MS .NET weather service that is listed on the XMethods site as a real-life example of Internet Web service access, so you'll need to be connected to the Internet while running this demo. NOTE: If you haven't already downloaded the software used to create the tutorial examples, please refer to the installation chapter in Part One. You'll also need to download the demo sources. We assume that you've unpacked this archive into the c:\wasp_demo directory. All Java sources mentioned in the tutorial examples can be found in the src subdirectory of the unpacked demo sources archive. They all reside in the com.systinet.demos package. Similarly all scripts used in the demo are located in the bin subdirectory. You don't need to download and use the software to understand these articles, but we strongly recommend it. Accessing a Microsoft .NET service from Java We'll start with the Java client/.NET service example. As we mentioned earlier, we will access the weather service listed on the XMethods site. Click on the link and try the service online using the MS .NET invocation framework. Next look at the WSDL document for this service. You'll notice that it defines three bindings (WeatherRetrieverSoap, WeatherRetrieverHttpGet, and WeatherRetrieverHttpPost). Now let's create a Java client for this service. Run the run_weather_client.bat script that's located in the bin directory of the demo sources archive. Please note that we're using a lookup method that specifices the fully qualified service name and the WSDL port. This lookup method allows us to specify that we want to use the SOAP binding. lookup("http://www.vbws.com/services/weatherretriever.asmx?WSDL", new javax.wsdl.QName("http://tempuri.org/", "WeatherRetriever"), "WeatherRetrieverSoap", WeatherRetrieverSoap.class) Calling a Java service from a Microsoft .NET client The opposite scenario is pretty straightforward. First start the Web service runtime with the startserver.bat command, and then compile and deploy our simple Bank Web service by invoking the deploy.bat command. Now we're ready to show three different MS SOAP clients accessing our service. NOTE: You need to use MS IE 6.0 or higher to run this demo. First we will run a MS JavaScript SOAP Client. Invoke the run_web_client.bat script. Specify an SSN number (you can use 001-0001-01, 002-0002-02 or 003-0003-03), and click the Get Accounts button, which populates the accounts combobox. Choose an account in the combobox and retrieve the account balance by clicking the Get Balance button. Look at the JavaScript code in src\msjsclient.html for further details. The code is very self-explanatory. NOTE: You'll need to download and install the MS SOAP Toolkit 2.0 in order to successfully complete the next example. You'll also need MS Excel on your machine. Now let's see the same functionality accessed from Microsoft Excel (using Visual Basic). Open the src\Bank.xls spreadsheet and use the same steps described in the previous example to navigate the application. You can find the SOAP client code in the Visual Basic Editor (Tools->Macro->Visual Basic Editor) in the Sheet1 module. NOTE: You'll need to download and install the MS .NET Framework SDK to run the C# part of this example The last example demonstrates how to access our Java Web service from a C# client. Run the run_csharp.bat script to generate a C# static proxy from the service WSDL and to compile and run the client application. This example is going one step further than our previous examples in that it passes a Transfer structure from C# to Java. The previous examples pass only simple data types. Notice the simple XML Schema definition of the Transfer type (it includes the Balance element): <xsd:schema targetNamespace="http://idoox.com/wasp/tools/java2wsdl/output/com/systinet/d emos/bank/"> <xsd:complexType name="Transfer"> <xsd:sequence> <xsd:element name="type" type="xsd:string"/> <xsd:element name="accountNumberBeneficiary" type="xsd:string"/> <xsd:element name="comment" type="xsd:string"/> <xsd:element name="balance" type="ns0:Balance"/> <xsd:element name="amount" type="xsd:double"/> <xsd:element name="timestamp" type="xsd:dateTime"/> <xsd:element name="accountNumber" type="xsd:string"/> <xsd:element name="transferID" type="xsd:long"/> <xsd:element name="commentBeneficiary" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="Balance"> <xsd:sequence> <xsd:element name="changed" type="xsd:dateTime"/> <xsd:element name="transfer" type="ns0:Transfer"/> <xsd:element name="comment" type="xsd:string"/> <xsd:element name="balance" type="xsd:double"/> <xsd:element name="accountNumber" type="xsd:string"/> <xsd:element name="transferID" type="xsd:long"/> </xsd:sequence> </xsd:complexType> </xsd:schema> The .NET WSDL compiler will generate the appropriate structures in C#. See the stub in the src/ms/JavaService.cs for more details. Run the Java client by invoking the run_java_client.bat script, and you'll notice that it does the same thing. NOTE: Both clients share the same Web service, and both clients make withdrawals from the same account. So if you run the demo multiple times, you can easily get out of funds. Then you'll get the TransferProcessingException that says something like 'Insufficient funds'. One nice thing you'll notice is that C# is able to transparently rethrow the exception with the same message on the client side. Restart the Web services runtime using the startserver.bat to renew your funds. ----- Original Message ----- From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, February 21, 2002 6:43 PM Subject: java client for .NET : need SOAPMapping sample code hi, i had a code, in the past, to marshall a java object into SOAP before to send it to a java webservice. Now, my java client calls a .NET webservice. and the way i connect to the .NET webservice is different (i don't use Call() class, i do use URL() class, just because taht's the only code i know to connectto a .NET webservice) the problem is that my SOAP code doesn't fit any more could you post me a sample code, with a connection to a .NETwebservice and a SOAPMapping ? regards, Elise ======================================================= Old java code Call call = new Call (); call.setTargetObjectURI ("urn:liox:Project"); call.setMethodName ("getProject"); call.setEncodingStyleURI(encodingStyleURI); SOAPMappingRegistry smr = new SOAPMappingRegistry(); ProjectSerializer beanSer = new ProjectSerializer(); StringDeserializer sd = new StringDeserializer (); smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName("urn:Projects", "Project"), Project.class, beanSer, beanSer); smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName("", "return"), Project.class, null, beanSer); smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName("", "ProjectCode"), null, null, sd); smr.mapTypes(Constants.NS_URI_SOAP_ENC, new QName("", "CompanyName"), null, null, sd); call.setSOAPMappingRegistry(smr); Response resp = call.invoke (url, "" ); ===================================================== New java code byte[] request = marshall(); URL endpoint = new URL("http://val1nt10/PCS_Integration/SynchronizeProfiles.asmx"); URLConnection con = endpoint.openConnection (); con.setDoInput (true); con.setDoOutput (true); con.setUseCaches (false); con.setAllowUserInteraction(false); con.setRequestProperty ("Content-Length", Integer.toString (request.length)); con.setRequestProperty ("Content-Type", "text/xml; charset=utf-8"); con.setRequestProperty ("SOAPAction", "\"http://tempuri.org/WS_UpdateProfileAgency\""); OutputStream out = con.getOutputStream (); //HERE SOAPMAPPING ???? HOW ??? it's not urn anymore true ??? out.write (request); out.flush (); out.close(); -------------------------------------------- Elise Dupont Software developer Technology Development Group Europe Lionbridge Technologies - France Buropolis 1 - 1240 route des Dolines 06560 Sophia-Antipolis www.lionbridge.com