1

公に公開されたサービスのクライアントを作成しようとしています。生の XMLを (Java 文字列として)渡し、生の応答を表示するだけです。バインディングは必要ありません。

サービスはここで公開されています: http://www.webservicex.net/periodictable

次のリクエスト XMLが正しく機能することを確認しました(Soap UI 経由)。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET">
   <soapenv:Header/>
   <soapenv:Body>
      <web:GetAtomicWeight>
         <!--Optional:-->
         <web:ElementName>Aluminium</web:ElementName>
      </web:GetAtomicWeight>
   </soapenv:Body>
</soapenv:Envelope>

ここでは、WS 用の Spring のテンプレート、Maven の依存関係を使用しています。

<dependency>
    <groupId>org.springframework.ws</groupId>
    <artifactId>spring-ws-core</artifactId>
    <version>2.1.3.RELEASE</version>
</dependency>

さて、これが私の単純な「メイン」アプリケーションです。XML 文字列を Spring に委任するだけWebServiceTemplateで、System.out.

package sk.xorty.ws;

import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.soap.client.core.SoapActionCallback;
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPException;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.StringReader;

public class WsTest {

    private static final String REQUEST_PERIODIC =
            "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:web=\"http://www.webserviceX.NET\">\n" +
            "   <soap:Header/>\n" +
            "   <soap:Body>\n" +
            "      <web:GetAtomicWeight>\n" +
            "         <web:ElementName>Aluminium</web:ElementName>\n" +
            "      </web:GetAtomicWeight>\n" +
            "   </soap:Body>\n" +
            "</soap:Envelope>\n";

    private static final String URL_PERIODIC = "http://www.webservicex.net/periodictable";

    private final WebServiceTemplate webServiceTemplate = new WebServiceTemplate();

    // send to an explicit URI
    public void customSendAndReceive() throws SOAPException {
        MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        SaajSoapMessageFactory newSoapMessageFactory = new SaajSoapMessageFactory(messageFactory);
        webServiceTemplate.setMessageFactory(newSoapMessageFactory);

        StreamSource source = new StreamSource(new StringReader(REQUEST_PERIODIC));
        StreamResult result = new StreamResult(System.out);
        webServiceTemplate.sendSourceAndReceiveToResult(URL_PERIODIC, source,
                new SoapActionCallback("GetAtomicWeight"), result);
    }

    public static void main(String[] args) throws SOAPException {
        new WsTest().customSendAndReceive();
    }
}

例は実行可能です (クラスパスの上記の依存関係のみが必要です)。次のエラーがスローされます。

INFO: Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
Exception in thread "main" org.springframework.ws.client.WebServiceTransportException: Not Found [404]
    at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:663)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:587)
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:537)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:492)
    at org.springframework.ws.client.core.WebServiceTemplate.sendSourceAndReceiveToResult(WebServiceTemplate.java:436)
    at sk.xorty.ws.WsTest.customSendAndReceive(WsTest.java:38)
    at sk.xorty.ws.WsTest.main(WsTest.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

編集: リクエストの正しい値は次のとおりです。

private static final String REQUEST_PERIODIC = "<web:GetAtomicWeight xmlns:web=\"http://www.webserviceX.NET\">\n" +
        "         <!--Optional:-->\n" +
        "         <web:ElementName>Aluminium</web:ElementName>\n" +
        "      </web:GetAtomicWeight>";
4

4 に答える 4

1

注釈を使用している場合は、次の注釈の名前空間属性が、対応する WSDL 要素の名前空間属性と一致していることを確認してください。

@XmlRootElement(namespace = "http://webService.mydomain.com", name = "someSOAPRequest")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = {      
        "xmlTag#1",
        "xmlTag#2",
        "xmlTag#3",
        "xmlTag#4",
},  namespace = "http://webService.mydomain.com", name = "someSOAPRequest")

注釈を使用していない場合は、名前空間属性がコードと WSDL 要素の間で一致していることを確認してください。

于 2015-09-01T05:03:34.387 に答える
1

あなたの問題はsoapActionCallBackに関係していると思います。uriを使用した操作ではなく、操作のみを呼び出しています。以下はここからの例です:

名前空間がhttp://tempuri.orgであり、soapActionCallback に指定された引数がhttp://tempuri.org/SOAPACTIONであることに注意してください*

 WebServiceTemplate template = new WebServiceTemplate(messageFactory);
 Result result = new DOMResult();
 template.sendSourceAndReceiveToResult(
     new StringSource("<content xmlns=\"http://tempuri.org\"/>"),
     new SoapActionCallback("http://tempuri.org/SOAPAction"),
     result);

あなたの場合、soap アクションはhttp://www.webserviceX.net/GetAtomicWeightである必要があります(ただし、大文字と小文字についてはよくわかりません)

于 2013-09-12T18:15:59.327 に答える
0

同じエラーが発生し、Soap1.1 を使用していました。WS が @SoapAction アノテーションを介して Spring によって公開され、Spring WS で生成されたクライアントと JAXB がデフォルトで soapAction を設定していないことに気付きました。 SoapActionCallback を使用して、その操作の WSDL で指定された SoapAction を設定します。

 SoapActionCallback soapActionCallback = new SoapActionCallback("restituisciStatiMessaggioListRequestSA");
    RestituisciStatiMessaggioListResponse response = (RestituisciStatiMessaggioListResponse) getWebServiceTemplate().marshalSendAndReceive(request,soapActionCallback);
于 2014-06-25T12:29:39.767 に答える