web service - jaxws with eclipse

package com.pc.ws;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style=Style.RPC)
public interface FirstWebServiceTry {
	@WebMethod
	public void sayPaul(String arg);
}


package com.pc.ws;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

import com.sun.org.apache.bcel.internal.generic.NEW;

@WebService(endpointInterface="com.pc.ws.FirstWebServiceTry")
@SOAPBinding(style=Style.RPC)
public class FirstWebServiceTryImpl implements FirstWebServiceTry {
	
	static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm:ssSSS");
	
	@Override
	public void sayPaul(String arg) {
		System.out.println( simpleDateFormat.format(new Date()) + " - Paul is " + arg);
	}

}


package com.pc.ws;

import javax.xml.ws.Endpoint;


public class PublishWebService {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		Endpoint endpoint = Endpoint.publish("http://localhost:50020/webservice", new FirstWebServiceTryImpl());
		System.out.println(endpoint.isPublished());
	}

}


package com.pc.ws.client;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import com.ibm.keymanager.audit.i;
import com.pc.ws.FirstWebServiceTry;

public class FirstWebServiceTryClient {

	/**
	 * @param args
	 * @throws MalformedURLException 
	 */
	public static void main(String[] args) throws MalformedURLException {

		URL url = new URL("http://localhost:8080/webservice?wsdl");
		QName qName = new QName("http://ws.pc.com/", "FirstWebServiceTryImplService");
		Service service = Service.create(url, qName);
		FirstWebServiceTry firstWebServiceTry = service.getPort(FirstWebServiceTry.class);
		int i =0;
		while(i<10){
			firstWebServiceTry.sayPaul("handsome");
			i++;
		}
	}

}


You only need to pass your contact with service to your client who use your web service. Go this URL to get the WSDL (service contact):

http://localhost:50020/webservice?wsdl

<!--
Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6.
-->
<!--
Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6.
-->
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.pc.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.pc.com/" name="FirstWebServiceTryImplService">
<types/>
<message name="sayPaul">
<part name="arg0" type="xsd:string"/>
</message>
<message name="sayPaulResponse"/>
<portType name="FirstWebServiceTry">
<operation name="sayPaul">
<input message="tns:sayPaul"/>
<output message="tns:sayPaulResponse"/>
</operation>
</portType>
<binding name="FirstWebServiceTryImplPortBinding" type="tns:FirstWebServiceTry">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="sayPaul">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://ws.pc.com/"/>
</input>
<output>
<soap:body use="literal" namespace="http://ws.pc.com/"/>
</output>
</operation>
</binding>
<service name="FirstWebServiceTryImplService">
<port name="FirstWebServiceTryImplPort" binding="tns:FirstWebServiceTryImplPortBinding">
<soap:address location="http://localhost:50020/webservice"/>
</port>
</service>
</definitions>



Tested on Local. The performance is ok using RPC.

Oracle tutorial link:

http://docs.oracle.com/javaee/5/tutorial/doc/bnayk.html

It just shows case how to implement in NetBean IDE. but it did can tell what jax-ws is and how.


Go here to understand the details SOAP mesg and the usage of SOAP binding:

http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值