webService 服务器未能识别 HTTP 头 SOAPAction 的值 java编程
歡歖 2019-03-04 09:23:19 @Test
public void getRegionDataset_soap11() throws MalformedURLException, SOAPException, TransformerException {
String wsdlDocumentLocation = "http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl";
String nameSpace = "http://WebXml.com.cn/";
String serviceName = "WeatherWS";
String portName = "WeatherWSSoap";
javax.xml.ws.Service service = javax.xml.ws.Service.create(new URL(wsdlDocumentLocation), new QName(nameSpace, serviceName));
Dispatch<SOAPMessage> dispatch = service.createDispatch(new QName(nameSpace, portName),
SOAPMessage.class, javax.xml.ws.Service.Mode.MESSAGE);
SOAPMessage soapMessage = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL).createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("method", nameSpace);
SOAPHeader soapHeader = envelope.getHeader();
soapHeader.addAttribute(new QName(nameSpace, "SOAPAction", "method"), "http://WebXml.com.cn/getRegionDataset");
SOAPBody soapBody = envelope.getBody();
SOAPElement operation = soapBody.addBodyElement(new QName("http://WebXml.com.cn/", "getRegionDataset"));
MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
mimeHeaders.setHeader("SOAPAction","http://WebXml.com.cn/getRegionDataset");
//请求webService
SOAPMessage response = dispatch.invoke(soapMessage);
// 输出响应结果
System.out.println("---------------------- response document ----------------------");
Document doc = response.getSOAPPart().getEnvelope().getBody().extractContentAsDocument();
}
com.sun.xml.internal.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: 服务器未能识别 HTTP 头 SOAPAction 的值: 。 Please see the server log to find more detail regarding exact cause of the failure.
发这个问答不知道为什么封号了就