Help!!! can't invoke a webservice.

Hi guys,

I am in terrible need of having this solved (been on it for 5 days now), it's getting ridiculous, all this hype over webservices ... it ain't workin' for me. Anyhow, here's my stuff...

There's a webservice (wsdl) running on a remote box on IIS. The URL ishttp://xxx.xxx.xxx.xx/pdws/pdwebserv.WSDL

Now, the actual contents of the wsdl file are as follows:

<?xml version="1.0" encoding="UTF-8" ?>

- <!-- Generated 05/25/06 by Microsoft SOAP Toolkit WSDL File Generator, Version 3.00.1325.0

-->

- <definitions name="pdwebserv" targetNamespace="http://tempuri.org/pdwebserv/wsdl/" xmlns:wsdlns="http://tempuri.org/pdwebserv/wsdl/" xmlns:typens="http://tempuri.org/pdwebserv/type/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:stk="http://schemas.microsoft.com/soap-toolkit/wsdl-extension" xmlns:dime="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/" xmlns:ref="http://schemas.xmlsoap.org/ws/2002/04/reference/" xmlns:content="http://schemas.xmlsoap.org/ws/2002/04/content-type/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">

- <types>

- <schema targetNamespace="http://tempuri.org/pdwebserv/type/" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" elementFormDefault="qualified">

<import namespace="http://schemas.xmlsoap.org/soap/encoding/" />

<import namespace="http://schemas.xmlsoap.org/wsdl/" />

<import namespace="http://schemas.xmlsoap.org/ws/2002/04/reference/" />

<import namespace="http://schemas.xmlsoap.org/ws/2002/04/content-type/" />

</schema>

</types>

- <message name="pdwebserv.MainMethod">

<part name="cXMLInput" type="xsd:string" />

<part name="cDataPath" type="xsd:string" />

<part name="cWSPath" type="xsd:string" />

<part name="cXMLOutput" type="xsd:string" />

<part name="cMethod" type="xsd:string" />

</message>

- <message name="pdwebserv.MainMethodResponse">

<part name="Result" type="xsd:anyType" />

</message>

- <portType name="pdwebservSoapPort">

- <operation name="MainMethod" parameterOrder="cXMLInput cDataPath cWSPath cXMLOutput cMethod">

<input message="wsdlns:pdwebserv.MainMethod" />

<output message="wsdlns:pdwebserv.MainMethodResponse" />

</operation>

</portType>

- <binding name="pdwebservSoapBinding" type="wsdlns:pdwebservSoapPort">

<stk:binding preferredEncoding="UTF-8" />

<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />

- <operation name="MainMethod">

<soap:operation soapAction="http://tempuri.org/pdwebserv/action/pdwebserv.MainMethod" />

- <input>

<soap:body use="encoded" namespace="http://tempuri.org/pdwebserv/message/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" parts="cXMLInput cDataPath cWSPath cXMLOutput cMethod" />

</input>

- <output>

<soap:body use="encoded" namespace="http://tempuri.org/pdwebserv/message/" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" parts="Result" />

</output>

</operation>

</binding>

- <service name="pdwebserv">

- <port name="pdwebservSoapPort" binding="wsdlns:pdwebservSoapBinding">

<soap:address location="http://xxx.xxx.xxx.xx/pdws/pdwebserv.WSDL" />

</port>

</service>

</definitions>

Now, I am trying from my java code to invoke this webservice using JAX-RPC and the error I am getting is the following:

Exception in thread "main" HTTP Status-Code 405: Method Not Allowed

My code is the following:

import java.net.*;

import java.util.*;

import javax.xml.rpc.*;

import javax.xml.rpc.encoding.*;

import javax.xml.namespace.*;

publicclass Test

{

String wsdlURL ="http://xxx.xxx.xxx.xx/pdws/pdwebserv.WSDL";

String namespaceURI ="http://tempuri.org/pdwebserv/wsdl/";

public Test()throws Exception

{

ServiceFactory factory = ServiceFactory.newInstance();

Service service = factory.createService(new URL(wsdlURL),new QName(namespaceURI,"pdwebserv"));

Call call = service.createCall();

call.setPortTypeName(new QName(namespaceURI,"pdwebservSoapPort"));

call.setOperationName(new QName(namespaceURI,"MainMethod"));

call.setTargetEndpointAddress("http://schemas.xmlsoap.org/soap/http");

call.setProperty("javax.xml.rpc.encodingstyle.namespace.uri","http://schemas.xmlsoap.org/soap/encoding/");

call.setProperty("javax.xml.rpc.soap.http.soapaction.uri","http://tempuri.org/pdwebserv/action/pdwebserv.MainMethod");

call.setProperty("javax.xml.rpc.soap.http.soapaction.use",new Boolean(true));

call.addParameter("cXMLInput",XMLType.XSD_STRING,ParameterMode.IN);

call.addParameter("cDataPath",XMLType.XSD_STRING,ParameterMode.IN);

call.addParameter("cWSPath",XMLType.XSD_STRING,ParameterMode.IN);

call.addParameter("cXMLOutput",XMLType.XSD_STRING,ParameterMode.IN);

call.addParameter("cMethod",XMLType.XSD_STRING,ParameterMode.IN);

call.setReturnType(XMLType.XSD_STRING);

String[] args ={"<?xml version = \"1.0\" encoding=\"UTF-8\" ?> " +

"<VFPDataSet xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"PD_Input.xsd\"> " +

"<PD_Input>" +

"<MasterID>123456</MasterID>" +

"<BillTo>234567</BillTo>" +

"<PDCode>SPORT</PDCode>" +

"<Amount>1000.00</Amount>" +

"</PD_Input>" +

"</VFPDataSet>",

"P:\\","P:\\Pdws\\","","PublDuty"};

System.out.println(call.invoke(args));

}

publicstaticvoid main(String[] args)throws Exception

{

new Test();

}

}

Help guys, this is an emergency!

Thank you all for taking the time to read it and help me.

Steve.

[9681 byte] By [stevekatsarasa] at [2007-10-2 21:34:06]
# 1
Did you have .wsdd file and did you have the method in that file which you are trying to access. Check this some times if you dont have mehtod in .wsdd file and try to acces that method you get error
kssra at 2007-7-14 0:47:54 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

> Did you have .wsdd file and did you have the method

> in that file which you are trying to access. Check

> this some times if you dont have mehtod in .wsdd file

> and try to acces that method you get error

Ok, thanks I will have a look and get back to you.

stevekatsarasa at 2007-7-14 0:47:54 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Try this code and see if you still get error. I am using this method and have no problem calling Web Services.

public static void invokeWS(String endpoint) {

String qnameService = "HelloWorld";

String qnamePort = "HelloWorldSoap";

String BODY_NAMESPACE_VALUE = "http://tempuri.org/HelloWorld/HelloWorld"; // TargetNameSpace in WSDL

String ENCODING_STYLE_PROPERTY = "javax.xml.rpc.encodingstyle.namespace.uri";

String NS_XSD = "http://www.w3.org/2001/XMLSchema"; // xmlns:xsd in WSDL

String URI_ENCODING = "http://schemas.xmlsoap.org/soap/encoding/"; // // operation - input - body - encodingStyle in WSDL

String result = "ERROR IN WEB SERVICE METHOD";

try {

ServiceFactory factory = ServiceFactory.newInstance();

Service service = factory.createService(new QName(qnameService));

QName port = new QName(qnamePort);

Call call = service.createCall(port);

call.setTargetEndpointAddress(endpoint);

call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));

call.setProperty(Call.SOAPACTION_URI_PROPERTY, "http://tempuri.org/HelloWorld"); // soapAction attribute

call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING);

// Define Return Type

QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");

call.setReturnType(QNAME_TYPE_STRING);

call.setOperationName(new QName(BODY_NAMESPACE_VALUE, "HelloWorld")); // operation name

// Add Parameters

/*

call.addParameter("Param_1", QNAME_TYPE_STRING, ParameterMode.IN);

call.addParameter("Param_2", QNAME_TYPE_STRING, ParameterMode.IN);

call.addParameter("Param_3", QNAME_TYPE_STRING, ParameterMode.IN);

call.addParameter("Param_4", QNAME_TYPE_STRING, ParameterMode.IN);

*/

// Set Parameters Values

String[] params = {};

//String[] params = { "Value_1", "Value_2", "Value_3", "Value_4" };

result = (String)call.invoke(params);

} catch (Exception ex) {

ex.printStackTrace();

} // catch

System.out.println(result);

} // invokeWS

dvd66a at 2007-7-14 0:47:54 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...