上記のサービスに石鹸クライアントを作成しました。
しかし、私が受け取る応答には、常に答えとしてエラーが表示されます。問題がどこにあるのか本当にわかりません。多分誰かが私を助けることができます。
私のコードの下:
public static void main(String[] args) throws SOAPException {
try {
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
// Get Mime Header
MimeHeaders mimeHeader = message.getMimeHeaders();
mimeHeader.addHeader("Host", "www.w3schools.com");
mimeHeader.addHeader("Content-Type", "text/xml; charset=utf-8");
mimeHeader.addHeader("SOAPAction",
"http://tempuri.org/FahrenheitToCelsius");
// Get soap header
SOAPHeader header = message.getSOAPHeader();
// Enter data into header
// Get soap body
SOAPBody body = message.getSOAPBody();
// Enter data into body
SOAPElement temp = body.addChildElement("FahrenheitToCelsius", "",
"http://tempuri.org");
SOAPElement fahr = temp.addChildElement("Fahrenheit");
fahr.addTextNode("140");
// print what we are sending
message.writeTo(System.out);
SOAPConnection connection = SOAPConnectionFactory.newInstance()
.createConnection();
SOAPMessage response = connection.call(message, endpoint);
connection.close();
System.out.println("");
System.out.println("---------------");
response.writeTo(System.out);
} catch (SOAPException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
これは私が送っているものです:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<FahrenheitToCelsius xmlns="http://tempuri.org">
<Fahrenheit>140</Fahrenheit>
</FahrenheitToCelsius>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
そして、これはサービスが私に送信するように求めているものです:
POST /webservices/tempconvert.asmx HTTP/1.1
Host: www.w3schools.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/FahrenheitToCelsius"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<FahrenheitToCelsius xmlns="http://tempuri.org/">
<Fahrenheit>string</Fahrenheit>
</FahrenheitToCelsius>
</soap:Body>
</soap:Envelope>
メソッド自体は機能します。しかし、応答にはエラーが示されています。
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<FahrenheitToCelsiusResponse xmlns="http://tempuri.org/">
<FahrenheitToCelsiusResult>Error</FahrenheitToCelsiusResult>
</FahrenheitToCelsiusResponse>
</soap:Body>
</soap:Envelope>
サービスの説明はここにあります: http://www.w3schools.com/webservices/tempconvert.asmx?op=FahrenheitToCelsius
だから私は不完全なヘッダーを持っていると推測しています。しかし、私はそれを正しく設定する方法がわかりません。