webserver报XFireFault: Unmarshalling Error: unexpected element (uri:"http://server.m/", loc

今天用XFire的客户端去访问自己创建的webserver,结果在调用的时候报错,首先看一下客户端的

代码:

/**
* Project Name:asjgl
* File Name:Main.java
* Package Name:com.zsy.jsec.zdsjyj.util
* Date:2016-1-13下午08:21:16
* Copyright (c) 2016, [email protected] All Rights Reserved.
*
*/

package com.zsy.jsec.zdsjyj.util;

import java.net.MalformedURLException;
import java.net.URL;

import org.codehaus.xfire.client.Client;
import org.codehaus.xfire.service.Service;

public class Main
{
    
    /**
     * main:(这里用一句话描述这个方法的作用). 
* @author syzhao * @param args * @since JDK 1.6 */ public static void main(String[] args) { Client client = null; try { client = new Client(new URL("http://localhost:8080/springwebserver/ws/HelloWorld?wsdl")); Service service = client.getService(); System.out.println(service.getName()); Object[] result1 = client.invoke("sayHello", new Object[] {"张三"}); for (int i = 0; i < result1.length; i++) { System.out.println(result1[i]); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } }

 

上面代码没有写错,就是报这个错误:

{http://server.zsy.com/}HelloWorldService
org.codehaus.xfire.fault.XFireFault: Unmarshalling Error: unexpected element (uri:"http://server.zsy.com/", local:"arg0"). Expected elements are <{}arg0> 
	at org.codehaus.xfire.fault.Soap11FaultSerializer.readMessage(Soap11FaultSerializer.java:31)
	at org.codehaus.xfire.fault.SoapFaultSerializer.readMessage(SoapFaultSerializer.java:28)
	at org.codehaus.xfire.soap.handler.ReadHeadersHandler.checkForFault(ReadHeadersHandler.java:111)
	at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:67)
	at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
	at org.codehaus.xfire.client.Client.onReceive(Client.java:406)
	at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)
	at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
	at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
	at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
	at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)
	at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)
	at org.codehaus.xfire.client.Client.invoke(Client.java:336)
	at org.codehaus.xfire.client.Client.invoke(Client.java:368)
	at com.zsy.jsec.zdsjyj.util.Main.main(Main.java:35)


说明后台代码错了,只要在webserver的注解里添加targetNamespace即可,请看代码:

@WebService
public class HelloWorldImpl implements HelloWorld
{
    /**
     * TODO 简单描述该方法的实现功能(可选).
     * @see com.zsy.server.HelloWorld#sayHello(java.lang.String)
     */
    @WebResult(name = "name", targetNamespace = "http://server.zsy.com/")
    @WebMethod
    public String sayHello(@WebParam(name = "name", targetNamespace = "http://server.zsy.com/") String string)
    {
        System.out.println("hello " + string);
        return "你好," + string;
}
}


 

在参数和返回值上添加targetNamespace即可,targetNamespace不要写错了,否则,后台无法获取你的参数值,也无法返回给你值!

targetNamespace这个东西冲wsdl里复制最稳当!


结果如下:


你可能感兴趣的:(java)