2013-04-30 26 views
0

如何訪問我的Java中的異步Web服務?我在Flex Builder使這個東西,它`很簡單:只需添加Web服務扔「數據 - >連接到Web服務 - >輸入WSDL的URL」並添加此行:Flex和java中的異步Web服務調用

private function result(e:ResultEvent):void 
{ 
    trace(e.result.toString()); 
} 

private function fault(e:FaultEvent):void 
{ 
    trace(e.toString()); 
} 

var d:DomainAuth = new DomainAuth(); 
d.AuthFuncName(login, pass); 
d.addEventListener(ResultEvent.RESULT, result); 
d.addEventListener(FaultEvent.FAULT, fault); 

哪有我使用eclipse EE在Java中執行此操作?

+0

http://stackoverflow.com/questions/2092083/using-and-testing-web-services-in-eclipse – NINCOMPOOP 2013-04-30 07:24:55

回答

0

基本上你需要在java中做一個SOAP web服務客戶端,如果我正確理解你的話。 JAX-WS可以成爲你的朋友。下面的代碼是從here

package simpleclient; 

import javax.xml.ws.WebServiceRef; 
import helloservice.endpoint.HelloService; 
import helloservice.endpoint.Hello; 

public class HelloClient { 
    @WebServiceRef(wsdlLocation="http://localhost:8080/ 
     helloservice/hello?wsdl") 
    static HelloService service; 

    public static void main(String[] args) { 
    try { 
     HelloClient client = new HelloClient(); 
     client.doTest(args); 
    } catch(Exception e) { 
     e.printStackTrace(); 
    } 
} 

public void doTest(String[] args) { 
    try { 
     System.out.println("Retrieving the port from 
       the following service: " + service); 
     Hello port = service.getHelloPort(); 
     System.out.println("Invoking the sayHello operation 
       on the port."); 

     String name; 
     if (args.length > 0) { 
      name = args[0]; 
     } else { 
      name = "No Name"; 
     } 

     String response = port.sayHello(name); 
     System.out.println(response); 
    } catch(Exception e) { 
     e.printStackTrace(); 
    } 
    } 
}