0
A
回答
0
你可以這樣說:
在這裏,我創建了一個簡單的Web服務,它有兩個參數 數字1和數字2。並給出答案爲number3(= number1 + number2)。 Web服務已經部署在localhost:8080(Tomcat的 服務器)
你的答案從這裏開始。
我已經創建了一個示例Java檔案...其中兩個參數傳遞給在SOAP請求一個 web服務,並得到從web服務 SOAP響應。您可以從WSDL文件中獲取getCalculation,m,localhost:8080,number1,number2和url等參數(以代碼形式描述)。
示例代碼:
package SampleJavaWSDLDemo;
- 進口javax.xml.soap中*;
- import java.util。*;
- import java.net.URL;
- import javax.xml.transform。*;
- import javax.xml.transform.stream.StreamResult;
- import javax.xml.soap.SOAPConnectionFactory;
- import javax.xml.soap.SOAPConnection;
- import javax.xml.soap.MessageFactory;
- import javax.xml.soap.SOAPMessage;
- import javax.xml.soap.SOAPPart;
- import javax.xml.soap.SOAPEnvelope;
- import javax.xml.soap.SOAPBody;
- import java.net.URL;
公共類SampleJavaWSDLDemo {
public static void main(String[] args)
{
try {
//Create a SOAPMessage
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnectionFactory.createConnection();
SOAPFactory soapFactory = SOAPFactory.newInstance();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPHeader header = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
header.detachNode();
Name bodyName = soapFactory.createName("getCalculation", "m", "http://localhost:8080/");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
//Insert Content
Name name = envelope.createName("number1");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode("10");
name = envelope.createName("number2");
symbol = bodyElement.addChildElement(name);
symbol.addTextNode("20");
System.out.println("\n Request: \n");
message.writeTo(System.out);
System.out.println();
// Create an endpint point which is either URL or String type
URL endpoint = new URL("http://localhost:8080/WebServiceName/OperationName");
//Send a SOAPMessage (request) and then wait for SOAPMessage (response)
SOAPMessage response = connection.call(message, endpoint);
// Get the response from the webservice.
SOAPBody soapBody = response.getSOAPBody();
System.out.println("\n Response: \n");
TransformerFactory transformerfactory = TransformerFactory.newInstance();
Transformer transformer = transformerfactory.newTransformer();
Source sourceContent = response.getSOAPPart().getContent();
StreamResult result = new StreamResult(System.out);
transformer.transform(sourceContent, result);
System.out.println();
String resp = response.getSOAPBody().getElementsByTagName("return").item(0).getFirstChild().getNodeValue();
System.out.println("Answer is: " + resp);
connection.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
嘗試運行這段代碼。 它可以給你一個完整的肥皂請求和響應消息。
相關問題
- 1. 創建SOAP請求
- 2. 如何像SOAP UI請求一樣從android構建SOAP請求?
- 3. PHP SOAP如何創建嵌套請求
- 4. Java:如何創建SOAP請求?
- 5. 創建SOAP請求和顯示響應
- 6. 如何通過ksoap2創建SOAP請求
- 7. 使用SOAP創建請求ui
- 8. 使用http build創建soap請求
- 9. 爲SOAP請求創建特定信封
- 10. 如何創建SOAP 1.2請求
- 11. 爲特定的SOAP請求創建WSDL
- 12. PHP SOAP請求屬性正確創建
- 13. 使用KSOAP創建SOAP請求Android
- 14. Java:爲UPnP重新創建SOAP請求
- 15. 使用ASP.Net 2.0創建SOAP請求
- 16. 如何創建簡單的SOAP請求?
- 17. 如何創建此SOAP XML請求?
- 18. 用Grails創建XML請求的SOAP請求
- 19. 創建沒有WSDL文件的PHP SOAP請求(Flickr SOAP API)
- 20. 用於從wsdl創建SOAP請求的Java代碼
- 21. 從SoapUI重新創建一個可用的SOAP請求到PHP
- 22. 如何從對象類型創建SOAP請求?
- 23. SOAP請求從Windows服務
- 24. 如何從SOAP請求
- 25. 從PHP發送SOAP請求
- 26. Java SOAP請求
- 27. curl SOAP請求
- 28. fsockopen soap請求
- 29. SOAP請求PHP5
- 30. SOAP請求PHP
JWSDL文檔建議你做什麼? – 2010-08-24 20:41:00
實際文檔沒有提及擴展的用法。但是,我不明白我的目的是使用擴展名。 – rel1kz 2010-08-24 20:51:41