使用SAAJ调用webservice出错,求救

TGITCIC
Java领域优质创作者
博客专家认证
2008-09-24 01:39:56
被调用的WSDL如下:

<?xml version="1.0" encoding="UTF-8" ?>
- <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="urn:Foo" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="MyHelloService" targetNamespace="urn:Foo">
<types />
- <message name="HelloIF_sayHello">
<part name="String_1" type="xsd:string" />
</message>
- <message name="HelloIF_sayHelloResponse">
<part name="result" type="xsd:string" />
</message>
- <portType name="HelloIF">
- <operation name="sayHello" parameterOrder="String_1">
<input message="tns:HelloIF_sayHello" />
<output message="tns:HelloIF_sayHelloResponse" />
</operation>
</portType>
- <binding name="HelloIFBinding" type="tns:HelloIF">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc" />
- <operation name="sayHello">
<soap:operation soapAction="" />
- <input>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded" namespace="urn:Foo" />
</input>
- <output>
<soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded" namespace="urn:Foo" />
</output>
</operation>
</binding>
- <service name="MyHelloService">
- <port name="HelloIFPort" binding="tns:HelloIFBinding">
<soap:address location="http://localhost:8080/hello-jaxrpc/hello" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" />
</port>
</service>
</definitions>

我的客户端用的是SAAJ写的,代码如下:

package saaj;

import javax.xml.soap.*;
import java.util.*;
import java.net.URL;

public class SoapRequestExample {
public static void main(String[] args) {
/* String endpointAddress = "http://localhost:8080/hello-jaxrpc/hello"; */
String endpointAddress = "http://localhost:8080/Axis2/services/HelloWorld";
try {

SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory
.newInstance();
SOAPConnection connection = soapConnectionFactory
.createConnection();
SOAPFactory soapFactory = SOAPFactory.newInstance();

MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPHeader header = message.getSOAPHeader();

SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
header.detachNode();

Name bodyName = soapFactory.createName("sayHello", null,
"urn:Foo");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);

Name name = soapFactory.createName("s");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode("duke");


message.saveChanges();
message.writeTo(System.out);
System.out.println();

URL endpoint = new URL(endpointAddress);
SOAPMessage response = connection.call(message, endpoint);
connection.close();

SOAPBody soapBody = response.getSOAPBody();
System.out.println("soapBody====" + response.getSOAPBody());

} catch (Exception ex) {
ex.printStackTrace();
}
}

}


然后得到如下的错误:

Sep 24, 2008 1:34:19 PM com.sun.xml.messaging.saaj.soap.MessageImpl identifyContentType
SEVERE: SAAJ0536: Content-Type needs to be Multipart/Related and with type=text/xml or application/soap+xml
Sep 24, 2008 1:34:19 PM com.sun.xml.messaging.saaj.soap.MessageImpl <init>
SEVERE: SAAJ0535: Unable to internalize message


...全文
113 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
TGITCIC 2008-09-24
  • 打赏
  • 举报
回复
不是太明白大侠的意思
termite 2008-09-24
  • 打赏
  • 举报
回复
你用的transport是"http://schemas.xmlsoap.org/soap/http"哦,看看这个错误信息:
Content-Type needs to be Multipart/Related and with type=text/xml or application/soap+xml

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧