现在编写一个java spring Web服务客户端进行服务

时间:2012-02-17 18:20:40

标签: java web-services spring servicenow

我的设置如下。我有一个使用此界面的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);
}

Insert.java

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"skills",
"uponApproval",

......(约50多个args)

@XmlRootElement(name = "insert", namespace="http://www.service-now.com/incident")
public class Insert {

protected String skills;
@XmlElement(name = "upon_approval")
protected String uponApproval;

..(相同的args)

我可以调用webservice和服务现在创建事件,但它没有考虑我传递给它的参数。

    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>

我认为问题是第二个插入标记,但我不知道如何阻止它被发送。

可以在此处的服务现在演示站点看到WSDL:

https://demo05.service-now.com/incident.do?WSDL

user:admin

pw:admin

当我使用wsimport时,它创建的服务方法包括服务方法调用中的所有67个参数。不幸的是有效。我真的想把所有这些参数抽象成一个对象。有没有办法让java在不将额外的插入标记添加到SAOP消息的情况下展开Insert对象?

1 个答案:

答案 0 :(得分:1)

看起来问题是你将Insert对象命名为参数,这是第二个“

可能(必须?)是一个更好的选择,但我发现这个似乎有效:

更改insert方法以获取参数(命名并且没有命名空间)而不是Insert对象应该修复它。

public InsertResponse insert(
           @WebParam(name="priority", targetNamespace = "") BigInteger priority,
           @WebParam(name="short_description", targetNamespace = "") String shortDescription,
           @WebParam(name="assigned_to", targetNamespace = "") String assignedTo
);

根据需要为您尝试的任何内容添加参数。