soapfaultexception 会不会是接口的targetphp soap namespacee配置问题

[Java教程]cxf webservice:异常SOAPFaultException: Unexpected wrapper element found解决
你的位置:
[Java教程]cxf webservice:异常SOAPFaultException: Unexpected wrapper element found解决
客户端使用SOAP方式调用CXF服务时异常:javax.原因:是客户端和服务器的namespace不同,即客户端和服务端的WebService接口包路径不一致。解决方式:1、客户端和服务器的WebService接口包路径相同。2、在客户端和服务端的接口注解上指定相同的targetNamespace。建议与包名保持一致。3、如果是反向生成的服务器代码,需注释掉:wsdlLocation部分;wsdlLocation会导致找不到具体的服务。
、 、 、 、 、SOAPFaultException (Java EE 5 SDK)
Java EE 5 SDK
javax.xml.ws.soap
Class SOAPFaultException
javax.xml.ws.soap.SOAPFaultException
All Implemented Interfaces:
public class SOAPFaultExceptionextends
The SOAPFaultException exception represents a
SOAP 1.1 or 1.2 fault.
A SOAPFaultException wraps a SAAJ SOAPFault
that manages the SOAP-specific representation of faults.
The createFault method of
javax.xml.soap.SOAPFactory may be used to create an instance
of javax.xml.soap.SOAPFault for use with the
constructor. SOAPBinding contains an accessor for the
SOAPFactory used by the binding instance.
Note that the value of getFault is the only part of the
exception used when searializing a SOAP fault.
Refer to the SOAP specification for a complete
description of SOAP faults.
JAX-WS 2.0
See Also:,
&&&&&&&&&&Constructor for SOAPFaultException
&&&&&&&&&&Gets the embedded SOAPFault instance.
, , , , , , , , , ,
, , , , , , , , ,
SOAPFaultException
public SOAPFaultException(&fault)
Constructor for SOAPFaultException
Parameters:fault - SOAPFault representing the faultSee Also:
getFault()
Gets the embedded SOAPFault instance.
Returns:javax.xml.soap.SOAPFault SOAP
fault element
Java EE 5 SDK
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to
Scripting on this page tracks web page traffic,
but does not change the content in any way.soap中自定义异常处理
  创建服务器端
  1.创建一个接口
  IMyService.java
  package com.test.
import java.util.L
import javax.jws.WebP
import javax.jws.WebR
import javax.jws.WebS
@WebService(targetNamespace = "")
public interface IMyService {
// 异常处理
@WebResult(name = "user")
public User login(@WebParam(name = "username") String username, @WebParam(name = "password") String password) throws UserE
  2.创建实现接口的类
  MyServiceImpl.java
  package com.test.
import java.util.ArrayL
import java.util.L
import javax.jws.WebS
@WebService(endpointInterface = "com.test.service.IMyService", targetNamespace = "")
public class MyServiceImpl implements IMyService {
private static List&User& users = new ArrayList&User&();
public MyServiceImpl() {
users.add(new User(1, "admin", "管理员", "111111"));
public User login(String username, String password) throws UserException {
for (User user : users) {
if (username.equals(user.getUsername()) && password.equals(user.getPassword())) {
throw new UserException("用户名或密码不正确!");
  3.自定义异常类
  UserException.java
  package com.test.
public class UserException extends Exception {
public UserException() {
public UserException(String message, Throwable cause) {
super(message, cause);
public UserException(String message) {
super(message);
public UserException(Throwable cause) {
super(cause);
  4.开启服务
  MyServer.java
  package com.test.
import javax.xml.ws.E
public class MyServer {
public static void main(String[] args) {
String address = "http://localhost:9999/server";
// 发布服务的实现类
Endpoint.publish(address, new MyServiceImpl());
  5.测试类TestSoap.java
  // 异常处理
public void test05() {
// 创建服务
URL url = new URL("http://localhost:9999/server");
QName qname = new QName("", "MyServiceImplService");
Service service = Service.create(url, qname);
// 创建Dispatch
Dispatch&SOAPMessage& dispatch = service.createDispatch(new QName("", "MyServiceImplPort"), SOAPMessage.class, Service.Mode.MESSAGE);
// 创建SOAP的body消息
SOAPMessage message = MessageFactory.newInstance().createMessage();
SOAPBody body = message.getSOAPPart().getEnvelope().getBody();
// 根据QName创建相应的节点
QName ename = new QName("", "login", "ns");
SOAPBodyElement element = body.addBodyElement(ename);
element.addChildElement("username").setValue("cdxs");
element.addChildElement("password").setValue("123");
message.writeTo(System.out);
System.out.println("\n invoking...");
// 通过dispatch传递消息,返回响应消息
SOAPMessage response = dispatch.invoke(message);
response.writeTo(System.out);
System.out.println();
} catch (SOAPException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SOAPFaultException e) {
System.out.println(e.getMessage());
  运行结果:
  &SOAP-ENV:Envelope xmlns:SOAP-ENV=""&&SOAP-ENV:Header/&&SOAP-ENV:Body&&ns:login xmlns:ns=""&&username&cdxs&/username&&password&123&/password&&/ns:login&&/SOAP-ENV:Body&&/SOAP-ENV:Envelope&
  invoking...
  用户名或密码不正确!君,已阅读到文档的结尾了呢~~
cxf cxf spring cxf spring配置 cxf环境配置 spring cxf 配置 电脑配置 红米note配置 剑灵配置
扫扫二维码,随身浏览文档
手机或平板扫扫即可继续访问
举报该文档为侵权文档。
举报该文档含有违规或不良信息。
反馈该文档无法正常浏览。
举报该文档为重复文档。
推荐理由:
将文档分享至:
分享完整地址
文档地址:
粘贴到BBS或博客
flash地址:
支持嵌入FLASH地址的网站使用
html代码:
&embed src='/DocinViewer-4.swf' width='100%' height='600' type=application/x-shockwave-flash ALLOWFULLSCREEN='true' ALLOWSCRIPTACCESS='always'&&/embed&
450px*300px480px*400px650px*490px
支持嵌入HTML代码的网站使用
您的内容已经提交成功
您所提交的内容需要审核后才能发布,请您等待!
3秒自动关闭窗口}

我要回帖

更多关于 wsdl targetnamespace 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信