2016-07-07 7 views
0

ローカルWebサービスがあり、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(); 
    } 
を見ます
関連する問題