如何使用 Java 从 WSDL 获取 SOAPAction

发布于 2024-12-13 20:12:34 字数 196 浏览 0 评论 0原文

我正在使用 javax.wsdl 包来解析 wsdl 文件。

我不确定如何从 wsdl 文件获取操作的 SOAPAction。

我可以使用 WSDLFactory 获取 javax.wsdl.Operation 对象。但我找不到获得该操作的 SOAPAction 的方法。

有人知道如何获得它吗?

谢谢, 马维什瓦

I am using javax.wsdl package for parsing the wsdl file.

I am not sure how to get the SOAPAction of an operation from the wsdl file.

I am able to get the javax.wsdl.Operation object using the WSDLFactory. But I find no way to get the SOAPAction of that operation.

Anybody has idea on how to get it?

Thanks,
Maviswa

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷夜 2024-12-20 20:12:34

您需要获取与 SOAPOperation 对应的 ExtensibilityElement 并从那里提取 SOAPAction

让我们以 TempConvert Web Service 中的一个简单 WSDL 为例,并从其 中提取 SOAP 操作摄氏度转华氏度操作;我将继续这一部分:

<wsdl:binding name="TempConvertSoap" type="tns:TempConvertSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="FahrenheitToCelsius">
      <soap:operation soapAction="http://tempuri.org/FahrenheitToCelsius" style="document"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="CelsiusToFahrenheit">
      <soap:operation soapAction="http://tempuri.org/CelsiusToFahrenheit" style="document"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>

以下代码打印 CelsiusToFahrenheit 操作的 SOAP 操作的值:

WSDLFactory factory = WSDLFactory.newInstance();
WSDLReader reader = factory.newWSDLReader();
Definition definition = reader.readWSDL("http://www.w3schools.com/webservices/tempconvert.asmx?wsdl");
Binding binding = definition.getBinding(new QName("http://tempuri.org/", "TempConvertSoap"));
BindingOperation operation = binding.getBindingOperation("CelsiusToFahrenheit", null, null); 
List extensions = operation.getExtensibilityElements();
if (extensions != null) {
    for (int i = 0; i < extensions.size(); i++) {
        ExtensibilityElement extElement = (ExtensibilityElement) extensions.get(i); 

        // ....

        if (extElement instanceof SOAPOperation) {
            SOAPOperation soapOp = (SOAPOperation) extElement;
            System.out.println(soapOp.getSoapActionURI());
        }

        // ....
    }
}

输出如下:

http://tempuri.org/CelsiusToFahrenheit

You need to get the ExtensibilityElement that corresponds to the SOAPOperation and extract the SOAPAction from there.

Let's take a simple WSDL as example, from the TempConvert Web Service, and extract the SOAP action from its CelsiusToFahrenheit operation; I'm going after this part:

<wsdl:binding name="TempConvertSoap" type="tns:TempConvertSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="FahrenheitToCelsius">
      <soap:operation soapAction="http://tempuri.org/FahrenheitToCelsius" style="document"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="CelsiusToFahrenheit">
      <soap:operation soapAction="http://tempuri.org/CelsiusToFahrenheit" style="document"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>

The following code prints the value of the SOAP action for the CelsiusToFahrenheit operation:

WSDLFactory factory = WSDLFactory.newInstance();
WSDLReader reader = factory.newWSDLReader();
Definition definition = reader.readWSDL("http://www.w3schools.com/webservices/tempconvert.asmx?wsdl");
Binding binding = definition.getBinding(new QName("http://tempuri.org/", "TempConvertSoap"));
BindingOperation operation = binding.getBindingOperation("CelsiusToFahrenheit", null, null); 
List extensions = operation.getExtensibilityElements();
if (extensions != null) {
    for (int i = 0; i < extensions.size(); i++) {
        ExtensibilityElement extElement = (ExtensibilityElement) extensions.get(i); 

        // ....

        if (extElement instanceof SOAPOperation) {
            SOAPOperation soapOp = (SOAPOperation) extElement;
            System.out.println(soapOp.getSoapActionURI());
        }

        // ....
    }
}

The output is this:

http://tempuri.org/CelsiusToFahrenheit
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文