1. 程式人生 > >WebService客戶端出現A WebService annotation is not present on class: com.java1234.service.IUserService

WebService客戶端出現A WebService annotation is not present on class: com.java1234.service.IUserService

去客戶端找你的類,注意看報錯

加上WebService註解 即可

附上webService建立過程

1.分別建立兩個專案,右鍵web service

2.webserviceClient  直接啟動  服務端  訪問wsdl即可

package com.java1234.service;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
 
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
 

public class Test {
	public static void main(String[] args) throws Exception {
		URL url = new URL("http://localhost:9998/userService?wsdl");
		
		//建立服務名稱
		//1.namespaceURI - 名稱空間地址
		//2.localPart - 服務檢視名
		QName qname = new QName("http://impl.service.java1234.com/", "userService");
		
		//建立服務檢視
		//引數解釋:
		//1.wsdlDocumentLocation - wsdl地址
		//2.serviceName - 服務名稱
		Service service = Service.create(url, qname);
		//獲取服務實現類
		IUserService mobileCodeWSSoap = service.getPort(IUserService.class);
		//呼叫查詢方法
		String result = mobileCodeWSSoap.sayHello("nihao");
		System.out.println(result);

	/*	IUserServiceProxy helloPxy = new IUserServiceProxy();
		IUserService service = helloPxy.getIUserService();
		String res = service.sayHello("123212");
		System.out.println(res);*/


	}
}