[英]SoapException: Server did not recognize the value of HTTP Header SOAPAction
我正在嘗試向此Web服務發送請求以獲取響應:這是我的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:
有誰可以幫助我解決這個問題?
查看Web服務wsdl,您必須使用"http://www.webservicex.net/GetGeoIP"
更改“ GetGeoIP "http://www.webservicex.net/GetGeoIP"
。
終於有
call.setOperationName(new QName("http://www.webservicex.net/","http://www.webservicex.net/GetGeoIP"));
試試吧。
當ws主機值不同於名稱空間值時,可能會發生以下情況:
<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使用“ example”,您必須更新主機值而不是名稱空間值。 它應該看起來像這樣
ExampleLocator.java
類(因為Locator類是您在軸向上設置主機的位置):
ExampleSoap_address =“ http://www.hostname.com/xxx/example.asmx ”
並且名稱空間值應保持與以下相同:
的targetNamespace = “http://www.namespace.com/example”
但是,這樣做的保證方法是從頭開始再次創建存根,檢查代碼中新主機名值的用法,並為這些用法更新舊代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.