SOAP服务器无法处理请求

SOAP服务器无法处理请求,soap,fault,Soap,Fault,我对SOAP请求有一个问题。我想解释一下我在做什么。 这是我的SOAP请求 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET"> <soapenv:Header/> <soapenv:Body> <web:GetWeather>

我对SOAP请求有一个问题。我想解释一下我在做什么。 这是我的SOAP请求

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET">
   <soapenv:Header/>
   <soapenv:Body>
       <web:GetWeather>
         <!--Optional:-->
         <web:CityName>Istanbul</web:CityName>
         <!--Optional:-->
         <web:CountryName>Turkey</web:CountryName>
       </web:GetWeather>
   </soapenv:Body>
</soapenv:Envelope>
结果,我得到“服务器无法处理。过程或函数'getWeather'需要参数'@CountryName',但未提供该参数。”

这是什么意思?我为什么要破例


关于解决方案有什么建议吗?

您正在使用变量
serverUrl
作为HTTP服务器URL和XML命名空间名称。它们很接近,但并不完全相同。名称空间名称为
http://www.webserviceX.NET
但是您的服务器URL是
http://www.webserviceX.NET/
(注意后面的斜杠)。XML命名空间的字符串必须与架构中的命名空间名称完全匹配

建议为名称空间创建单独的变量(或直接内联):


通过此更改,您的代码对我有效。

谢谢您的回复。我将代码更改为您的答案,代码有效。我漏掉了看不到的斜杠。我正在使用SoapUI作为某些属性。您推荐了任何有关web服务的工具吗?我也使用SoapUI。这很有帮助。您可以尝试ApacheCXFWSDL2Java(codegen)。这并不一定比你所做的更好,但这是另一种考虑的方法。另外,如果您还有另一个Java/SOAP问题,请不要忘记标记为“Java”。Java关注者比SOAP关注者多得多谢谢你所做的一切。这些信息对我很有帮助。另外,我是新手,我将学习如何有效地使用stackovverflow。我将注意你的建议。
public static void main(String args[]) {
    try {
        // Create SOAP Connection
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory
                .newInstance();
        SOAPConnection soapConnection = soapConnectionFactory
                .createConnection();

        // Send SOAP Message to SOAP Server
        String url = "http://www.webservicex.net/globalweather.asmx?WSDL";
        // SOAPMessage soapResponse =
        SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(),
                url);

        // Process the SOAP Response
        printSOAPResponse(soapResponse);
        soapConnection.close();
    } catch (Exception e) {
        System.err.println("Error occurred while sending SOAP Request to Server");
        e.printStackTrace();
    }
}

private static SOAPMessage createSOAPRequest() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    String serverURL = "http://www.webserviceX.NET/";

    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("web", serverURL);

    // SOAP Body
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapElement = soapBody.addChildElement("GetWeather", "web");
    SOAPElement soapElement1 = soapElement.addChildElement("CityName",
            "web");
    soapElement1.addTextNode("Istanbul");
    SOAPElement soapElement2 = soapElement.addChildElement("CountryName",
            "web");
    soapElement2.addTextNode("Turkey");

    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader("SOAPAction", serverURL + "GetWeather");
    soapMessage.saveChanges();
    return soapMessage;
}

/**
 * Method used to print the SOAP Response
 */
private static void printSOAPResponse(SOAPMessage soapResponse)
        throws Exception {
    TransformerFactory transformerFactory = TransformerFactory
            .newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    Source sourceContent = soapResponse.getSOAPPart().getContent();
    System.out.print("\nResponse SOAP Message = ");
    StreamResult result = new StreamResult(System.out);
    transformer.transform(sourceContent, result);
}}
   String serverURL = "http://www.webserviceX.NET/";

   SOAPEnvelope envelope = soapPart.getEnvelope();
   envelope.addNamespaceDeclaration("web", "http://www.webserviceX.NET");
   ...