当前位置:   article > 正文

意外的元素 (uri:““, local:“arg0“)。所需元素为<;{}arg0正确解决方法_意外的元素 url 所需元素为

意外的元素 url 所需元素为

一、前言

最近在做webservice接口迁移,要从一个系统把webservice接口迁移到另一个系统。

新系统上写好webservice接口后,调用发现报错:

意外的元素 (uri:"http://www.xxx.com/", local:"arg0")。所需元素为&lt;{}arg0

二、问题分析

1.使用postman请求的,请求url是:

post请求

http://127.0.0.1:8080/webservice/ClassinfoService?wsdl
  • 1
  • 2
  • 3

请求体是:

选择Body->raw,xml格式,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <getClassinfoBasic xmlns="http://www.xxx.com/">
    <arg0>123</arg0>
    </getClassinfoBasic>
  </soap:Body>
</soap:Envelope>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

其中:

    <getClassinfoBasic xmlns="http://www.xxx.com/">
    <arg0>123</arg0>
    </getClassinfoBasic>
  • 1
  • 2
  • 3

(1)getClassinfoBasic和/getClassinfoBasic是webservice的方法名,后端代码里有接口:

	@WebMethod
    public String getClassinfoBasic(String classId);
  • 1
  • 2

以及实现类:

	@Override
	@WebMethod(operationName="getClassinfoBasic")
	public String getClassinfoBasic(String classId) {
	    ......
		return classId;
	}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

(2)xmlns="http://www.xxx.com/"是一个配置的域名,和后端配置的一致即可(后端可以随便写),例如后端接口类上写:@WebService(targetNamespace = "http://www.xxx.com/")

(3)<arg0>123</arg0>的意思是,传入的第一个参数是123(对应本人代码,意思的入参classId是123);如果后续有参数就用<arg0>123</arg0><arg1>456</arg1>这样传递。

不过,现在这样会报错:意外的元素 (uri:"http://www.xxx.com/", local:"arg0")。所需元素为&lt;{}arg0

三、解决方法

1.网上搜索,有人说可以给后端加@WebParam

@WebMethod
public String getClassinfoBasic(@WebParam(name = "classId", targetNamespace = "http://www.xxx.com/") String classId);
  • 1
  • 2

然后就可以用<classId>123</classId>传参了。

不过,本人发现旧系统里并没有加@WebParam,也可以正常被调用;迁移到新系统后,感觉也不应该用这个方法来解决,应该和旧系统保持一致。

2.更换请求体报文,如下:

选择Body->raw,xml格式,内容如下:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pm="http://www.xxx.com/">
<soapenv:Header/>
<soapenv:Body>
<pm:getClassinfoBasic>

<arg0>123</arg0>

</pm:getClassinfoBasic>
</soapenv:Body>
</soapenv:Envelope>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

其中:
(1) xmlns:pm="http://www.xxx.com/",这个与第一种写法参数一致,还是后端配置的那个targetNamespace,和后端配置的保持一致即可。
(2)<pm:getClassinfoBasic></pm:getClassinfoBasic>,这个还是后端的方法名。
(3)<arg0>123</arg0>,还是方法的入参,表示第一个参数传入参123;如果有多个,就用<arg0>123</arg0><arg1>456</arg1>这样即可。

经过测试,使用这样的请求体,就可以把参数正确的传递给后台,不再报错。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/827781?site
推荐阅读
相关标签
  

闽ICP备14008679号