• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing .NET web service from java

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone explain how to access .NET web service from java?

Please check the below code....is this the cirrect way?

import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import javax.xml.rpc.Call;
public class web
{
public static void main(String args[])
{
try
{
String endPoint ="http://ip/Service.asmx";
Service service = new Service();
Call call2 = (Call)service.createCall();
call2.setTargetEndpointAddress(endPoint);
call2.setOperationName(new QName ("op","HelloWorld"));
}
}catch(Exception pe){
pe.printStackTrace();
}
}
}
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's no single "right" way to access a WS. Does the code generate the SOAP that the service expects? If so, then it's correct.
 
Maya Pillai
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have re written the code like this...it throws an exxception...


import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;

import java.net.*;

public class aaa {

public void connect() throws Exception
{
Service service = new Service();
Call call = (Call)service.createCall();

String endpoint = "http://ip/Service.asmx";
call.setTargetEndpointAddress(new URL(endpoint));
call.setOperationName(new QName("ResumeUpload"));
String email = "email@gmail.com";
Integer SID = (Integer)call.invoke(new Object [] {
new String(email)});
System.out.println("Got result : " + SID);
}
public static void main(String [] args)
{
aaa w = new aaa();
try
{
w.connect();
}
catch(Exception e)
{
System.out.println("An error has occurred.");
e.printStackTrace();
}
System.out.println("Done");

}
}

Please find the error log

AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client
faultSubcode:
faultString: Server did not recognize the value of HTTP Header SOAPAction: .
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:Server did not recognize the value of HTTP Header SOAPAction: .
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SOAPAction headers are pretty common (and widely required); the documentation of the target WS should mention what its value needs to be. If you dig into the Call and/or Service classes you should find ways of setting HTTP headers.

Why are you using Axis 1, by the way? It's quite old. Any particular reason not to use Axis 2?

If this was my problem I'd use Axis' wsdl2java tool to create Java client code for accessing the WS, though. Much easier than to try to write the code on one's own.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am a newbie to web services & I too facing the same issue m using axis1 and java 1.4 since its an existing application we are not allowed to change the versions.

I need to call a .net web service from java,

I tried the below code but it doesn't work,with this code I could call a java webservice but not the .Net service.

//String endPoint ="http://ip/axis/services";
String endPoint = "http://ip/Service.asmx";

Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endPoint));
System.out.println(call.getOperationName());

//call.setOperationName(new QName("Login_ws","getEmployees"));
call.setOperationName(new QName("ServiceSoap","HelloWorld"));

String ans = (String) call.invoke(new Object []{});
System.out.println("Result From webService : " + ans);


FaultString: Server did not recognize the value of HTTP Header SOAPAction:


Can anybody provide a sample code...


Thanks.
 
Ammu Isac
Greenhorn
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi...I have fixed this issue..Please see my code

import java.net.MalformedURLException;
import java.rmi.RemoteException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.encoding.XMLType;
public class ddd
{
public static void main(String args[]) throws ServiceException, MalformedURLException, RemoteException
{
try
{
String endPoint ="http://ip/webservice/Service.asmx";
//String endPoint ="http://ip/axis/services";
Service service = new Service();
Call call = (Call) service.createCall();
String mailId = "World";
call.setTargetEndpointAddress(new java.net.URL(endPoint));
call.addParameter("mailId", XMLType.XSD_STRING, ParameterMode.IN);
call.setSOAPActionURI("mywebservice/WelcomeUser");
call.setOperationName(new QName("mywebservice","WelcomeUser"));
System.out.println(call.getOperationName());
call.setReturnType(XMLType.XSD_STRING);
String ans = (String) call.invoke(new Object []{mailId});
System.out.println("Result From webService : " + ans);
}
catch(Exception e)
{
e.printStackTrace();
}

}
}


It is printing - Result From webService : Hello

Actually the web service is supposed to accept parameter 'World' and return the string 'Hello World'

Why i am not getting the correct out put? can anyone help me?

Is this the correct way to pass parameter to the web service?
 
reply
    Bookmark Topic Watch Topic
  • New Topic