---
title: "转   axis2 客户端调用wss4j 安全web服务的方法"
author: "tedygrate"
date: "2011-06-01T16:30:30Z"
tags: [".net", "Blog", "Security", "Web"]
categories: ["企业架构"]
slug: "axis2-wss4j-web"
draft: false
lastmod: "2011-06-01T16:30:30Z"
id: 1067406
url: "https://tedygrate.iteye.com/blog/1067406"
---

public class DocCategoryWebServiceClientTest {

    /\**  
     * @param args  
     * @throws RemoteException  
     \*/  
    public static void main(String\[] args) throws RemoteException {  
        // TODO Auto-generated method stub  
        DocCategoryWebServiceImpServiceStub stub = new DocCategoryWebServiceImpServiceStub(  
                "[http://my.service.net:8080/test/services/DocCategoryWebService](http://my.service.net:8080/test/services/DocCategoryWebService)");  
        String username = "admin";  
        String password = "1";  
        ServiceClient client = stub.\_getServiceClient();  
        SOAP11Factory factory = new SOAP11Factory();

        OMNamespace SecurityElementNamespace = factory  
                .createOMNamespace(  
                        "[http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd](http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd)",  
                        "wsse");

        OMElement usernameTokenEl = factory.createOMElement("UsernameToken",  
                SecurityElementNamespace);  
        OMElement usernameEl = factory.createOMElement("Username",  
                SecurityElementNamespace);  
        OMElement passwordEl = factory.createOMElement("Password",  
                SecurityElementNamespace);  
        OMElement actionEl = factory.createOMElement("Action",  
                SecurityElementNamespace);

        passwordEl  
                .addAttribute(factory  
                        .createOMAttribute(  
                                "Type",  
                                null,  
                                "[http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText](http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText)"));

        usernameEl.setText(username);  
        passwordEl.setText(password);  
        usernameTokenEl.addChild(usernameEl);  
        usernameTokenEl.addChild(passwordEl);  
        usernameTokenEl.addChild(actionEl);  
        SOAPHeaderBlockImpl block = new SOAP11HeaderBlockImpl("Security",  
                SecurityElementNamespace, factory);  
        block.addChild(usernameTokenEl);

        client.addHeader(block);

        DocCategoryWebServiceImpServiceStub.FindCategoryByParentId request = new DocCategoryWebServiceImpServiceStub.FindCategoryByParentId();  
        DocCategoryWebServiceImpServiceStub.FindCategoryByParentIdE requestE = new DocCategoryWebServiceImpServiceStub.FindCategoryByParentIdE();  
        request.setArg0("2");  
        requestE.setFindCategoryByParentId(request);  
        DocCategoryWebServiceImpServiceStub.FindCategoryByParentIdResponseE response = stub  
                .findCategoryByParentId(requestE);  
        ListObject listObject = response.getFindCategoryByParentIdResponse()  
                .get\_return();  
        if (listObject != null && listObject.getList() != null) {  
            for (int i = 0; i &lt; listObject.getList().length; i++) {  
                Object ob = listObject.getList()\[i];  
                DocCategory cat = (DocCategory) ob;  
                System.out.println(cat.getFdName());  
            }  
        }  
    }  
}

本文来自CSDN博客，转载请标明出处：[http://blog.csdn.net/bibitoo712/archive/2008/10/30/3184252.aspx](http://blog.csdn.net/bibitoo712/archive/2008/10/30/3184252.aspx)