• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

ASP.net web service + java Client

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic