2016-07-07 2 views
0

로컬 웹 서비스가 있고 JAVA 클라이언트를 사용하여 메서드를 호출 할 수 있습니다.URL에서 JAX-WS 메소드를 호출하는 방법

URL을 사용하여 메소드에 액세스 할 수 있습니까? 나는 URL을 사용하여 WSDL의 XML에 액세스 할 수 있습니다

http://localhost:9999/ws/hello?wsdl

을 그리고는 같은 방법은 전화 싶습니다

http://localhost:9999/ws/hello/getHelloWorldAsString?name=test

하지만 오류를 수신하고 "로컬 호스트는 보내지 않았다 모든 데이터 ".

이 방법이 있습니까?

답변

0

Jax-ws가 POST를 사용하여 전화를 받는다는 것을 알고있는 한. URL에 POST 할 XML 요청을 작성해야합니다. 이런 식으로 뭔가 :

POST /ws/hello HTTP/1.1 
SOAPAction: "" 
Accept: text/xml, multipart/related, text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 
Content-Type: text/xml; charset=utf-8 
User-Agent: Java/1.6.0_13 
Host: localhost:9999 
Connection: keep-alive 
Content-Length: 224 

<?xml version="1.0" ?> 
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
    <S:Body> 
     <ns2:getHelloWorldAsString xmlns:ns2="http://ws.mkyong.com/"> 
      <arg0>test</arg0> 
     </ns2:getHelloWorldAsString> 
    </S:Body> 
</S:Envelope> 
0

사용의 java.net.URL 및 HttpURLConnection의 또는 HttpsURLConnection는

은 샘플을 볼

URL url = new URL("http://yourwebservices.soap.wsdl"); 
    HttpURLConnection connectionWS = (HttpURLConnection) ur.openConnection(); 
    //not forget this 
    connectionWS.setDoOutput(true); 
    connectionWS.setDoInput(true); 
    connectionWS.setRequestMethod("POST"); 
    connectionMinervaWS.setRequestProperty("Content-Type", "text/xml; charset=utf-8"); 

    StringBuilder envelopeSoapRequest = new StringBuilder() 
    //make the xml request 

    //now you send to service 
    OutputStreamWriter osw = new OutputStreamWriter(connectionWS.getOutputStream()); 
    osw.write(envelopeSoapRequest.toString()); 
    osw.flush(); 

    //now you can take response 
    BufferedReader wsReader = null; 
    StringBuilder envelopeSoapResponse = new StringBuilder(); 
    wsReader = new BufferedReader(new InputStreamReader( 
    connectionWS.getInputStream(), StandardCharsets.UTF_8)); 
    String line = wsReader.readLine(); 

    while (line != null) { 
     envelopeSoapResponse.append(line); 
     line = wsReader.readLine(); 
    } 
관련 문제