2017-05-09 102 views
1

我創建了罰款運行一個簡單的Web服務: 接口:JAX web服務不CodenameOne項目工作

@WebService 
@SOAPBinding(style = Style.RPC) 
public interface HelloService { 
@WebMethod 
    void sayHello(); 
} 

實現的服務:

@WebService(endpointInterface = "mypackage.HelloService") 
public class HelloServiceImpl implements HelloService { 
@Override 
public void sayHello() { 
    System.out.println("Hello world"); 
} 

出版商:

public class HelloServicePublisher { 
    public static void main(String[] args) { 
     Endpoint.publish("http://localhost:8080/hello", new HelloServiceImpl()); 
    } 
} 

當我使用下面的客戶端代碼創建一個普通的JAVA項目時,它完美地工作:

public class Client { 
    public static void main(String[] args) throws Exception { 
     URL url = new URL("http://localhost:8080/hello?wsdl"); 

     // 1st argument service URI, refer to wsdl document above 
     // 2nd argument is service name, refer to wsdl document above 
     QName qname = new QName("http://server/", "HelloServiceImplService"); 
     Service service = Service.create(url, qname); 
     HelloService server = service.getPort(HelloService.class); 
     server.sayHello(); 
    } 
} 

這個編譯和運行良好。當我非常相同的客戶端代碼複製到一個純新項目CN1,我在service.getPort()調用得到一個零點例外:

at com.sun.xml.internal.ws.model.RuntimeModeler.getPortTypeName(Unknown Source) 
    at com.sun.xml.internal.ws.model.RuntimeModeler.getPortTypeName(Unknown Source) 
    at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source) 
    at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(Unknown Source) 
    at javax.xml.ws.Service.getPort(Unknown Source) 

所以現在的問題是:在創建時,究竟什麼是不同的CN1項目與普通Java項目相比較?它與代碼無關,因爲這很明顯。 欣賞任何提示。

感謝和問候

回答

1

代號一個doesn't support the full Java API也不支持JAX。您只能安裝Codename One支持的庫,並且只能使用javadocs中提及的JDK的子集。

上面解釋了原因,但總的來說,這是一個可行性/規模問題。相比之下,Codename One接近5mb以下的本機操作系統應用程序的效率/大小,即使我們將所有未使用的東西去掉,完整的JVM也將遠遠超過50mb,接近100mb。

networking section of the developer guide中,我們討論了幾種聯網方法,包括生成可以從客戶端與之通信的servlet的webservice嚮導。這是更快(更有效的溝通)和更小的代碼大小。

+0

嗯,好吧。不完全是我想聽到的,但至少是一個堅定的聲明。我對CN1和webservices都是新手,所以首先我按照我希望他們的樣子在服務器端上運行我的Web服務。現在我必須將其重寫爲任何CN1支持的Web服務。 但是,這是一個偉大的經驗,學習和有史以來這麼慢,我越來越得到這一切如何工作。感謝你的幫助! – Lequi