You are here: SOAP connection to Java Web Service from PHP « All PHP « IT news, forums, messages
SOAP connection to Java Web Service from PHP

Posted by tayze on 09/09/06 15:43

I've been struggling with this for a while and am finally resorting to
asking for help.

Below is the code that works in java:

---------------------------------------------------
import java.net.URL;
import java.util.Vector;

import org.apache.soap.Constants;
import org.apache.soap.Fault;
import org.apache.soap.SOAPException;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;

import java.io.*;
import java.util.*;

public class TopXCall {

public static void main(String argv[]) {

try {

String endpoint =
"http://infao5501.ag5.mpi-sb.mpg.de:8080/soap/servlet/rpcrouter";

// Initialize the method parameters
Vector params = new Vector();
// Create the call.
Call call = new Call();
call.setTargetObjectURI("TopXService");
call.setMethodName("processQuery");
call.setParams(params);
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);

// Invoke the call.
Response response = null;
try {
response = call.invoke(new URL(endpoint), "");

if (response.generatedFault()) {
Fault fault = response.getFault();
System.err.println("Generated fault: " + fault);
} else {

System.out.println(response.getReturnValue().getValue());
}
} catch (SOAPException e) {
System.err.println("Caught SOAPException (" +
e.getFaultCode() + "): " + e.getMessage());
}

}
catch(Exception e) {
System.err.println("Exception caught: " + e.getMessage());
}

}

}

---------------------------------------------------

Now I'm trying to get it to work in PHP. I believe I need to create a
WSDL file since there was not one provided.

Below is my PHP code and attempt at a WSDL file. I coppied a sample
file and modified the parts to suit my needs ... obviously I have made
some errors.

Any help or advice would be greatly appreciated.

Tayze

---------------------------------------------------
<?
require_once('nusoap.php');

$wsdl="http://www.myserver.com/soap/TopXService.wsdl";
$client=new soapclient($wsdl, 'wsdl');

$param=array(
'query'=>'//article[about(., java)]',
'collectionIndex'=>0,
'mode'=>0,
'k'=>10,
'page'=>0,
'conjunctive'=>false
);

echo $client->call('processQuery', $param);

echo 'Request: <xmp>'.$client->request.'</xmp>';
echo 'Response: <xmp>'.$client->response.'</xmp>';
echo 'Debug log: <pre>'.$client->debug_str.'</pre>';

?>
---------------------------------------------------
<?xml version="1.0"?>
<definitions name="TopXService"

targetNamespace="http://www.tayze.com/soap/TopXService.wsdl"
xmlns:tns="http://www.tayze.com/soap/TopXService.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="processQueryRequest">
<part name="query" type="xsd:string"/>
<part name="collectionIndex" type="xsd:integer"/>
<part name="mode" type="xsd:integer"/>
<part name="k" type="xsd:integer"/>
<part name="page" type="xsd:integer"/>
<part name="conjunctive" type="xsd:boolean"/>
</message>
<message name="processQueryResponse">
<part name="return" type="xsd:string"/>
</message>
<portType name="TopXPortType">
<operation name="processQuery">
<input message="tns:processQueryRequest" />
<output message="tns:processQueryResponse" />
</operation>
</portType>
<binding name="TopXBinding" type="tns:TopXPortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="processQuery">
<soap:operation soapAction=""/>
<input >
<soap:body use="encoded" namespace="TopXService"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="TopXService"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="TopXService">
<documentation>Returns search results</documentation>
<port name="TopXPort" binding="tns:TopXBinding">
<soap:address
location="http://infao5501.ag5.mpi-sb.mpg.de:8080/soap/servlet/rpcrouter"/>
</port>
</service>
</definitions>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация