Java by API/javax.xml.ws/Service — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 17:43, 31 мая 2010
Service: createDispatch(QName portName, Class<SOAPMessage> type, Mode mode)
import java.io.FileInputStream;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
public class Main {
public static void main(String args[]) throws Exception {
URL url = new URL("http://api.google.ru/GoogleSearch.wsdl");
QName serviceName = new QName("urn:GoogleSearch", "GoogleSearchService");
QName portName = new QName("urn:GoogleSearch", "GoogleSearchPort");
Service service = Service.create(url, serviceName);
Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class,
Service.Mode.MESSAGE);
SOAPMessage request = MessageFactory.newInstance().createMessage(null,
new FileInputStream("yourGoogleKey.xml"));
SOAPMessage response = dispatch.invoke(request);
response.writeTo(System.out);
}
}
Service: create(URL wsdlDocumentLocation, QName serviceName)
import java.io.FileInputStream;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
public class Main {
public static void main(String args[]) throws Exception {
URL url = new URL("http://api.google.ru/GoogleSearch.wsdl");
QName serviceName = new QName("urn:GoogleSearch", "GoogleSearchService");
QName portName = new QName("urn:GoogleSearch", "GoogleSearchPort");
Service service = Service.create(url, serviceName);
Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class,
Service.Mode.MESSAGE);
SOAPMessage request = MessageFactory.newInstance().createMessage(null,
new FileInputStream("yourGoogleKey.xml"));
SOAPMessage response = dispatch.invoke(request);
response.writeTo(System.out);
}
}
Service.Mode.MESSAGE
import java.io.FileInputStream;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
public class Main {
public static void main(String args[]) throws Exception {
URL url = new URL("http://api.google.ru/GoogleSearch.wsdl");
QName serviceName = new QName("urn:GoogleSearch", "GoogleSearchService");
QName portName = new QName("urn:GoogleSearch", "GoogleSearchPort");
Service service = Service.create(url, serviceName);
Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class,
Service.Mode.MESSAGE);
SOAPMessage request = MessageFactory.newInstance().createMessage(null,
new FileInputStream("yourGoogleKey.xml"));
SOAPMessage response = dispatch.invoke(request);
response.writeTo(System.out);
}
}