我的设置如下。我有一个spring bean org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean 使用这个接口:
<bean id="snIncidentService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
<property name="wsdlDocumentUrl" value="https://subdom.service-now.com/incident.do?WSDL" />
<property name="namespaceUri" value="http://www.service-now.com" />
<property name="serviceName" value="ServiceNow_incident" />
<property name="portName" value="ServiceNowSoap" />
<property name="serviceInterface" value="edu.liberty.webservice.SNIncident" />
<property name="username" value="****" />
<property name="password" value="****" />
</bean>
package edu.liberty.webservice;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
@WebService(name = "ServiceNowSoap", targetNamespace = "http://www.service-now.com/incident")
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT)
public interface SNIncident {
@WebMethod(operationName = "insert", action = "http://www.service-now.com/incident/insert")
@WebResult(name = "insertResponse", targetNamespace = "http://www.service-now.com/incident")
public InsertResponse insert(@WebParam(name="insert", targetNamespace = "http://www.service-now.com/incident") Insert inc);
}
插入.java
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"skills",
"uponApproval",
...(大约 50 多个参数)
@XmlRootElement(name = "insert", namespace="http://www.service-now.com/incident")
public class Insert {
protected String skills;
@XmlElement(name = "upon_approval")
protected String uponApproval;
..(相同的参数)
我可以调用 web 服务和服务现在创建事件,但它没有考虑我传递给它的参数。
Insert inc = new Insert();
inc.setPriority(new BigInteger("1"));
inc.setShortDescription("test WS");
incidentService.insert(inc);
SOAP 消息:
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:insert xmlns:ns2="http://www.service-now.com/incident">
<ns2:insert>
<priority>1</priority>
<short_description>test WS</short_description>
</ns2:insert>
</ns2:insert>
</S:Body>
</S:Envelope>
我相信问题出在第二个插入标签上,但我不知道如何阻止它被发送。
可以在此处的 service now 演示站点上看到 WSDL:
https://demo05.service-now.com/incident.do?WSDL
用户:管理员
密码:管理员
当我使用 wsimport 时,它创建的服务方法包括服务方法调用中的所有 67 个参数。不幸的是,这行得通。我真的很想将所有这些论点抽象成一个对象。有没有办法让 java 展开 Insert 对象,而无需将额外的插入标签添加到 SAOP 消息中?