如何使用Java使用需要用户名和密码的SOAP Web服务?

时间:2018-10-30 02:00:26

标签: java soap sharepoint webserver

我正在尝试使用NetBeans IDE(JAVA)来使用SOAP Web服务,但是当我尝试编译列表时,它将返回null。

与同事交谈时,他告诉我,这是我工作的用户的网络密码和公司密码,但是我很难理解此过程,因为我如何将该信息传递给我所使用的Web服务消费。

我是否必须通过其他方法传递此信息?

下面是分析数据;

在Sharepoint中完成的Web Service SOAP;

http://minha.casa.com.br/Servicos/ServicosGerais/_vti_bin/Lists.asmx?wsdl

列表所在的类。

package vamoLA;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for anonymous complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType>
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="listName" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "listName"
})
@XmlRootElement(name = "GetList")
public class GetList {

    protected String listName;

    /**
     * Gets the value of the listName property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getListName() {
        return listName;
    }

    /**
     * Sets the value of the listName property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setListName(String value) {
        this.listName = value;
    }

}

呼叫列表的类。

package Wss;

import java.util.ArrayList;
import java.util.List;
import vamoLA.GetListResponse.GetListResult;

public class Testando {

    private String username;

    private String password;

    public static void main(String[] args) {
        
        GetListResult list = getList("T_CARDAPIO_PRATO");
        List<Object> content;
        content = new ArrayList<Object>();
        content = list.getContent();
        System.out.println("Resultado 1 " + content.get(0));

    }

    private static GetListResult getList(java.lang.String listName) {
        vamoLA.Lists service = new vamoLA.Lists();
        vamoLA.ListsSoap port = service.getListsSoap();
        return port.getList(listName);
    }
    
    
    

}

回调。

ant -f C:\\Users\\casa\\Documents\\NetBeansProjects\\WSHell -Djavac.includes=Wss/Testando.java -Dnb.internal.action.name=run.single -Drun.class=Wss.Testando run-single
init:
Deleting: C:\Users\casa\Documents\NetBeansProjects\WSHell\build\built-jar.properties
deps-jar:
Updating property file: C:\Users\casa\Documents\NetBeansProjects\WSHell\build\built-jar.properties
wsimport-init:
wsimport-client-Lists:
files are up to date
wsimport-client-generate:
Compiling 1 source file to C:\Users\casa\Documents\NetBeansProjects\WSHell\build\classes
compile-single:
run-single:

Resultado 1 [List: null]
BUILD SUCCESSFUL (total time: 2 seconds)

0 个答案:

没有答案