簡體   English   中英

立即編寫Java Spring Web服務客戶端以進行服務

[英]write a java spring web service client for service now

我的設置如下所示。我使用此接口有一個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個參數)

@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>

我相信問題是第二個插入標記,但是我無法弄清楚如何阻止它被發送。

可以在“立即服務”演示站點上查看WSDL:

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

用戶:admin

pw:管理員

當我使用wsimport服務方法時,它創建的服務方法調用中包括所有67個參數。 不幸的是那行得通。 我真的很想將所有這些參數抽象到一個對象中。 有沒有一種方法可以讓Java在不將額外的insert標簽添加到SAOP消息的情況下展開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
);

根據需要添加參數,以進行任何嘗試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM