Meaningless Drivel is fun!*
The moose likes Web Services and the fly likes ASP.net web service + java Client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "ASP.net web service + java Client" Watch "ASP.net web service + java Client" New topic
Author

ASP.net web service + java Client

madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148
Hi
I am new to WEB SERVICES and basically need to use a java client for a WEB SERVICE in ASP.net.

I would like someone to help me out as to how i should proceed and be able to access the web service.


regards


Money for nothing and Java for Free
SCJP, SCWCD
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
The Web service will expose a WSDL, like any other. From this point, you can (mostly*) ignore the fact that the service is implemented in ASP.net.

Then, implement it like any other Web service. This recent thread had some links for this.


-Tim

When accessing a Web service produced using a toolkit other than the one you're using, it's quite possible you'll run into difficulties/bugs/inconsistencies. There are some documented problems between Microsoft platforms and Java ones, such as Microsoft's use of 'Document/Literal Wrapped', which is non-standard. Googling with the appropriate terms will find a horde of relevant sites.
madhup narain
Ranch Hand

Joined: Dec 14, 2004
Posts: 148
HELLO

here's a description of the service deployed in ASP.NET . I need a java Client to access this service. After writing a java client i have not been able to get the desired result. im getting an exception as follows
____________________________________________________________________________
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 500 for URL: http://127.0.0.1/test/HelloWorld.asmx/add
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:697)
at Client.main(Client.java:45)____________________________________________________________________________

The listing of the add method(ASP.NET) is as follows

SOAP
The following is a sample SOAP request and response. The placeholders shown need to be replaced with actual values.

POST /test/HelloWorld.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/test/HelloWorld/add"

<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<add xmlns="http://tempuri.org/test/HelloWorld">
<a>int</a>
<b>int</b>
</add>
</soap:Body>
</soap:Envelope>



HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<addResponse xmlns="http://tempuri.org/test/HelloWorld">
<addResult>int</addResult>
</addResponse>
</soap:Body>
</soap:Envelope>



My Java File--> Client.java

import java.io.*;
import java.net.*;

public class Client {
public static void main(String[] args) throws Exception {

String SOAPUrl = "http://127.0.0.1/test/HelloWorld.asmx";
String xmlFile2Send = "C:\\Madhup Temp\\add.xml";

String SOAPAction = "http://tempuri.org/test/HelloWorld/add";

// Create the connection where we're going to send the file.
URL url = new URL(SOAPUrl);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;

// Open the input file. After we copy it to a byte array, we can see
// how big it is so that we can set the HTTP Cotent-Length
// property.

FileInputStream fin = new FileInputStream(xmlFile2Send);
ByteArrayOutputStream bout = new ByteArrayOutputStream();

// Copy the SOAP file to the open connection.
copy(fin,bout);
fin.close();

byte[] b = bout.toByteArray();

// Set the appropriate HTTP parameters.
httpConn.setRequestProperty( "Content-Length", String.valueOf( b.length ) );
httpConn.setRequestProperty("Content-Type","text/xml; charset=utf-8");
httpConn.setRequestProperty("SOAPAction",SOAPAction);
httpConn.setRequestMethod( "POST" );
httpConn.setDoOutput(true);
httpConn.setDoInput(true);

// Everything's set up; send the XML that was read in to b.
OutputStream out = httpConn.getOutputStream();
out.write( b );
out.close();

// Read the response and write it to standard out.

InputStreamReader isr = new InputStreamReader httpConn.getInputStream());
BufferedReader in = new BufferedReader(isr);

String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);

in.close();
}

public static void copy(InputStream in, OutputStream out)
throws IOException {

// do not allow other threads to read from the
// input or write to the output while copying is
// taking place

synchronized (in) {
synchronized (out) {

byte[] buffer = new byte[256];
while (true) {
int bytesRead = in.read(buffer);
if (bytesRead == -1) break;
out.write(buffer, 0, bytesRead);
}
}
}
}
}

Can anyone please help me out as to why i am not able to access the service and the reason ?
By the way the XML file - add.xml
<a>23</a>
<b>54</b>
 
Don't get me started about those stupid light bulbs.
 
subject: ASP.net web service + java Client
 
Similar Threads
Defining characteristics of the DispatchAction class
Making a webservice call using axis2
Java EE 5 Tutorial - Problem with Web Services
stand alone java client for web server(ASP.net)
Java client and .NET 2.0 ASP.NET Web Service: SOAP port uses a non-standard SOAP 1.2 binding