wood burning stoves 2.0*
The moose likes Web Services and the fly likes unable to connect to .Net web service using axis with java 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 "unable to connect to .Net web service using axis with java" Watch "unable to connect to .Net web service using axis with java" New topic
Author

unable to connect to .Net web service using axis with java

Moiz Siddiqui
Greenhorn

Joined: Mar 27, 2009
Posts: 1
Hi,

I am trying to create a java client using Apache Axis to call a .net web service.Web service is very simple.m using .net 2.0 to build the web service.i used tcp mon to see the soap msg generated and generated msg was


POST /WebSite3/Service.asmx HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.4
Host: localhost:8089
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Content-Length: 340

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<HelloWorld soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</soapenv:Body>
</soapenv:Envelope>


and the result was


HTTP/1.1 500 Internal Server Error
Server: ASP.NET Development Server/8.0.0.0
Date: Fri, 27 Mar 2009 20:08:05 GMT
X-AspNet-Version: 2.0.50727
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Content-Length: 1005
Connection: Close

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: . at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.RouteRequest(SoapServerMessage message) at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocol.SetContext(Type type, HttpContext context, HttpRequest request, HttpResponse response) at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>



Following is the expected SOAP 1.1 request and response.

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

<?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>
<HelloWorld xmlns="http://mywebservice.org/" />
</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>
<HelloWorldResponse xmlns="http://mywebservice.org/">
<HelloWorldResult>string</HelloWorldResult>
</HelloWorldResponse>
</soap:Body>
</soap:Envelope>



----here is the java code---------

package classes;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;


import com.ibm.wsdl.extensions.soap.SOAPConstants;

import javax.xml.rpc.ParameterMode;

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

Service service = new Service();
Call call = (Call)service.createCall();

String endpoint = "http://localhost:8089/WebSite3/Service.asmx";
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName("HelloWorld");
SOAPConstants soapConstants=new SOAPConstants();


String position = (String)call.invoke( new Object [] { } );

System.out.println("Got result : " + position);
}
}



------ java code ends----

------Here is the code for .Net web service------

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://mywebservice.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public string HelloWorld() {
return "Hello World";
}

}

---- code ends-------



Please help me guys.. m desprate.. have been trying to get this code running for the past 4 days

Thanks in advance

Moiz
Yaron Naveh
Greenhorn

Joined: Oct 26, 2008
Posts: 24
I think you are using a relatively old version of Axis.

With newer versions you should use the web service wsdl (on /WebSite3/Service.asmx?WSDL) to generate a client side proxy (using wsdl2java.bat for example). This should also be possible with your current version.

What you are doing in your code is ignoring the WSDL. The WSDL contains some important information with regarding to how request should look like. It might be possible to configure Axis to send correct message even in the way you do it but it is harder.


[url]http://webservices20.blogspot.com/[/url]
Web Services Performance, Interoperability And Testing Blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: unable to connect to .Net web service using axis with java
 
Similar Threads
SOAP validateUser
error while connecting to webservices
how to write soap sending message with java?
how to set an attribute like SOAPAction in the Header?
SOAP Fault for SOAP Action property