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. 为SOAP请求创建特定信封
- 5. 使用KSOAP创建SOAP请求Android
- 6. 使用SOAP创建请求ui
- 7. 如何通过ksoap2创建SOAP请求
- 8. 使用ASP.Net 2.0创建SOAP请求
- 9. Java:如何创建SOAP请求?
- 10. 如何创建简单的SOAP请求?
- 11. 如何创建此SOAP XML请求?
- 12. 用Grails创建XML请求的SOAP请求
- 13. 如何从对象类型创建SOAP请求?
- 14. 从PHP发送SOAP请求
- 15. SOAP请求从Windows服务
- 16. SOAP请求PHP5
- 17. SOAP请求PHP
- 18. curl SOAP请求
- 19. fsockopen soap请求
- 20. PHP - SOAP请求
- 21. Java SOAP请求
- 22. Google Adwords SOAP请求
- 23. pear soap xml请求
- 24. Java Servlet SOAP请求
- 25. SOAP请求负载
- 26. SOAP请求标签
- 27. 尝试构建正确的SOAP请求
- 28. 创建Ajax请求
- 29. 如何在Python中创建多个并行SOAP请求
- 30. 如何使用多个命名空间创建PHP SOAP请求
JWSDL文档建议你做什么? – 2010-08-24 20:41:00
实际文档没有提及扩展的用法。但是,我不明白我的目的是使用扩展名。 – rel1kz 2010-08-24 20:51:41