日期:2014-05-18  浏览次数:21046 次

C#如何调用需要验证的JAVA web service(有java的源码)
Java code

package com.huawei.icp.buildcloud.searchservice.service.impl;

import org.codehaus.xfire.MessageContext;
import org.codehaus.xfire.handler.AbstractHandler;
import org.jdom.Element;

public class ClientAuthenticationHandler extends AbstractHandler
{

    private String username = null;
    
    private String password = null;
    
    public ClientAuthenticationHandler()
    {
        
    }
    
    public ClientAuthenticationHandler(String userName,String userPassWord)
    {
        this.username = userName;
        this.password =userPassWord;
    }
    
    public void setUerName(String userName)
    {
        this.username = userName;
    }
    
    public void setPassWord(String userPassWord)
    {
        this.password = userPassWord;
    }
    
    @Override
    public void invoke(MessageContext context) throws Exception
    {
        // 为SOAP header 构造验证信息
        Element head = new Element("header");
        context.getOutMessage().setHeader(head);
        Element auth = new Element("AuthenticationToken");
        Element username_e = new Element("UserName");
        username_e.addContent(username);
        Element password_e = new Element("PassWord");
        password_e.addContent(password);
        auth.addContent(username_e);
        auth.addContent(password_e);
        head.addContent(auth);
        
    }

}



------解决方案--------------------
huawei,快结吧