Hallo, ich habe ein Problem bei meinem Web-Sevice für Axis2. Ich will von meinem Client aus ein Double-Array übergeben und mir dann von meinem Service die Länge des Arrays zurückgeben lassen. Ich bekomme aber immer 0.0 zurück.
Mein Service Code:
Mein Client Code:
Meine services.xml:
[XML]<service>
<description>MatlabJavaService</description>
<parameter name="ServiceClass">
de.matlabservice.MatlabService
</parameter>
<operation name="getMedian">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
</service>[/XML]
Meine services.wsdl:
[XML]<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:xsd="http://matlabservice.de" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://matlabservice.de">
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified"
targetNamespace="http://matlabservice.de">
<xs:element name="getMedian">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="array" type="xs:double"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getMedianResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:double"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="getMedianRequest">
<wsdl
art name="parameters" element="xsd:getMedian"/>
</wsdl:message>
<wsdl:message name="getMedianResponse">
<wsdl
art name="parameters" element="xsd:getMedianResponse"/>
</wsdl:message>
<wsdl
ortType name="MatlabServicePortType">
<wsdl
peration name="getMedian">
<wsdl:input message="xsd:getMedianRequest" wsaw:Action="urn:getMedian"/>
<wsdl
utput message="xsd:getMedianResponse" wsaw:Action="urn:getMedianResponse"/>
</wsdl
peration>
</wsdl
ortType>
<wsdl:binding name="MatlabServiceSoap11Binding" type="xsd:MatlabServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl
peration name="getMedian">
<soap
peration soapAction="urn:getMedian" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl
utput>
<soap:body use="literal"/>
</wsdl
utput>
</wsdl
peration>
</wsdl:binding>
<wsdl:binding name="MatlabServiceSoap12Binding" type="xsd:MatlabServicePortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl
peration name="getMedian">
<soap12
peration soapAction="urn:getMedian" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl
utput>
<soap12:body use="literal"/>
</wsdl
utput>
</wsdl
peration>
</wsdl:binding>
<wsdl:binding name="MatlabServiceHttpBinding" type="xsd:MatlabServicePortType">
<http:binding verb="POST"/>
<wsdl
peration name="getMedian">
<http
peration location="MatlabService/getMedian"/>
<wsdl:input>
<mime:content type="text/xml" part="getMedian"/>
</wsdl:input>
<wsdl
utput>
<mime:content type="text/xml" part="getMedian"/>
</wsdl
utput>
</wsdl
peration>
</wsdl:binding>
<wsdl:service name="MatlabService">
<wsdl
ort name="MatlabServiceHttpSoap11Endpoint" binding="xsd:MatlabServiceSoap11Binding">
<soap:address location="http://localhost:8080/axis2/services/MatlabService"/>
</wsdl
ort>
<wsdl
ort name="MatlabServiceHttpSoap12Endpoint" binding="xsd:MatlabServiceSoap12Binding">
<soap12:address location="http://localhost:8080/axis2/services/MatlabService"/>
</wsdl
ort>
<wsdl
ort name="MatlabServiceHttpEndpoint" binding="xsd:MatlabServiceHttpBinding">
<http:address location="http://localhost:8080/axis2/services/MatlabService"/>
</wsdl
ort>
</wsdl:service>
</wsdl:definitions>
[/XML]
Die services.xml habe ich selbst erstellt und die services.xml habe ich mir vom Axis2 Codegernerator erstellen lassen.
Mein Service Code:
Java:
package de.matlabservice;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class MatlabService {
Socket sock = null;
PrintWriter out = null;
BufferedReader in = null;
String sendRequest = "";
String fromServer = "";
public void init(org.apache.axis2.context.ServiceContext serviceContext){
//Verbindung aufbauen
try{
sock = new Socket( "localhost", 4444 );
out = new PrintWriter( sock.getOutputStream(), true );
in = new BufferedReader( new InputStreamReader( sock.getInputStream()) );
}
catch(UnknownHostException e){
System.err.println("no localhost");
System.exit(1);
}
catch(IOException e){
System.err.println( e );
System.exit(1);
}
}
public void destroy(org.apache.axis2.context.ServiceContext serviceContext){
out.close();
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
sock.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public double getMedian(double[] array){
//Array in String wandeln
//Form: x = [1;2;3];
/*
String stringArray = "x = [";
for(int i = 0; i < array.length; i++){
stringArray = stringArray + array[i];
if(i<(array.length-1)){
stringArray = stringArray + ";";
}
}
stringArray = stringArray + "];";
//Request absetzen
String sendRequest = stringArray;
//Array x
out.println(sendRequest);
//Median berechnen lassen
out.println("median(x)");
//Antwort einlesen
String rez = "";
int c;
try {
while((c = in.read()) != 13){
rez = rez + ((char)c);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
*/
//Antwort in double umwandeln
return (double)array.length;
}
}
Mein Client Code:
Java:
package client;
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.databinding.utils.BeanUtil;
import org.apache.axis2.engine.DefaultObjectSupplier;
public class AxisMatlabClient {
public static void main(String[] args2) throws AxisFault{
ServiceClient sender = new ServiceClient();
Options options = sender.getOptions();
EndpointReference targetEPR = new EndpointReference("http://localhost:8081/axis2/services/Axis2Matlab");
options.setTo(targetEPR);
// die Operation "getMedian" soll aufgerufen werden
QName opGetMedian = new QName("http://matlabservice.de", "getMedian");
// Parameter für die Operation "getMedian" definieren
double[] zahlen = { 0.0 , 1.0 , 5.0 };
System.out.println(zahlen[1]);
Object[] opArgs = new Object[] { zahlen };
// OMElement mit der Request-Nachricht erzeugen
OMElement request = BeanUtil.getOMElement(opGetMedian,opArgs, null, false, null);
// Request an den Service schicken... der Aufruf erfolgt
// synchron mit dem Kommunikationsmuster IN-OUT
OMElement response = sender.sendReceive(request);
System.out.println(response.toString());
// diese Typen sollte der Web Service zurückliefern...
Class<?>[] returnTypes = new Class[] { Double.class };
// Antwort mit Hilfsroutine in ein Objekt-Array überführen
Object[] result = BeanUtil.deserialize(response, returnTypes, new DefaultObjectSupplier());
// Median ausgeben
double median = (Double) result[0];
System.out.println("Der Median ist:" + median);
}
}
Meine services.xml:
[XML]<service>
<description>MatlabJavaService</description>
<parameter name="ServiceClass">
de.matlabservice.MatlabService
</parameter>
<operation name="getMedian">
<messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</operation>
</service>[/XML]
Meine services.wsdl:
[XML]<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:xsd="http://matlabservice.de" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://matlabservice.de">
<wsdl:types>
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified"
targetNamespace="http://matlabservice.de">
<xs:element name="getMedian">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="array" type="xs:double"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getMedianResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:double"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="getMedianRequest">
<wsdl
</wsdl:message>
<wsdl:message name="getMedianResponse">
<wsdl
</wsdl:message>
<wsdl
<wsdl
<wsdl:input message="xsd:getMedianRequest" wsaw:Action="urn:getMedian"/>
<wsdl
</wsdl
</wsdl
<wsdl:binding name="MatlabServiceSoap11Binding" type="xsd:MatlabServicePortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl
<soap
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl
<soap:body use="literal"/>
</wsdl
</wsdl
</wsdl:binding>
<wsdl:binding name="MatlabServiceSoap12Binding" type="xsd:MatlabServicePortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl
<soap12
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl
<soap12:body use="literal"/>
</wsdl
</wsdl
</wsdl:binding>
<wsdl:binding name="MatlabServiceHttpBinding" type="xsd:MatlabServicePortType">
<http:binding verb="POST"/>
<wsdl
<http
<wsdl:input>
<mime:content type="text/xml" part="getMedian"/>
</wsdl:input>
<wsdl
<mime:content type="text/xml" part="getMedian"/>
</wsdl
</wsdl
</wsdl:binding>
<wsdl:service name="MatlabService">
<wsdl
<soap:address location="http://localhost:8080/axis2/services/MatlabService"/>
</wsdl
<wsdl
<soap12:address location="http://localhost:8080/axis2/services/MatlabService"/>
</wsdl
<wsdl
<http:address location="http://localhost:8080/axis2/services/MatlabService"/>
</wsdl
</wsdl:service>
</wsdl:definitions>
[/XML]
Die services.xml habe ich selbst erstellt und die services.xml habe ich mir vom Axis2 Codegernerator erstellen lassen.
Zuletzt bearbeitet von einem Moderator: