有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java SoapException:服务器未识别HTTP标头SOAPAction的值

我正在尝试向该web service发送请求以获取响应: 这是我的java代码

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;

public class TestClient {
    public static void main(String[] args) {
        try {

            String endpoint ="http://www.webservicex.net/geoipservice.asmx";
            Service service = new Service();
            Call call = (Call) service.createCall();

            call.setTargetEndpointAddress(new java.net.URL(endpoint));
            call.setOperationName(new QName("http://www.webservicex.net/","GetGeoIP"));

            String response = (String) call.invoke(new Object[] { "192.168.1.8" });

            System.out.println("The response is : " + response);
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }
}

当我运行此代码时,我得到以下soapException:

Server did not recognize the value of HTTP Header SOAPAction:

谁能帮我解决这个问题


共 (2) 个答案

  1. # 1 楼答案

    当ws-host值与命名空间值不同时,可能会发生这种情况,如下所示:

    <wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://www.hostname.com/example" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.namespace.com/example" slick-uniqueid="3">
    

    因此,如果试图发送请求的web服务正在移动,有时它们只会更改主机,而不会更改名称空间

    为了将“示例”用于Axis,必须更新主机值而不是名称空间值。应该是这样的

    ExampleLocator.java

    类(因为定位器类是在轴中设置主体的位置):

    示例SOAP_地址=“http://www.hostname.com/xxx/example.asmx

    和命名空间值应保持如下所示:

    targetNamespace=”http://www.namespace.com/example"

    但是保证这样做的方法是从头开始重新创建存根,检查代码中新主机名值的用法,并更新旧代码中的这些用法

  2. # 2 楼答案

    查看web服务wsdl,您必须更改“GetGeoIP” "http://www.webservicex.net/GetGeoIP"

    终于有了

    call.setOperationName(new QName("http://www.webservicex.net/","http://www.webservicex.net/GetGeoIP"));
    

    试试看