java调用.net写的webservice 如何传入实体类作为参数求解!感激不尽啊。

幽默K1 发布于 2012/11/23 14:22
阅读 2K+
收藏 0

java调用.net写的webservice 如何传入实体类作为参数

.net webServcie方法

 

    /// <summary>

        /// 添加windows用户

        /// </summary>

        /// <param name="ldapDN">单元名称</param>

        /// <param name="user">用户对象</param>

        /// <param name="group">所属组</param>

        /// <param name="de">连接对象</param>


        public static string AddUser(string ldapDN, UsersInfo user, string group, string path, string name, string pwd)
        {
          
            DirectoryEntry de = GetFirectoryObject(path, name, pwd); //连接
            DirectoryEntry subEntry = de.Children.Find("CN=" + ldapDN); //查找User单元
            DirectoryEntry NewUser = subEntry.Children.Add("cn=" + user.UserPrincipalName, "user");
            SetProperty(NewUser, "Description", user.Description);//描述
            SetProperty(NewUser, "sn", user.SN); //姓
            SetProperty(NewUser, "employeeID", user.EmployeeID);
            SetProperty(NewUser, "givenname", user.GivenName); //名
            SetProperty(NewUser, "initials", user.Initials); //英文缩写
            SetProperty(NewUser, "displayName", user.displayName); //显示名称
            SetProperty(NewUser, "physicalDeliveryOfficeName", user.PhysicalDeliveryOfficeName); //办公室地址
            SetProperty(NewUser, "telephoneNumber", user.telephoneNumber); //办公室电话
            SetProperty(NewUser, "otherTelephone", user.otherTelephone); //其他电话
            SetProperty(NewUser, "C", user.C); //国家/地区
            SetProperty(NewUser, "St", user.St); //省/自治区
            SetProperty(NewUser, "L", user.L); //市/县
            SetProperty(NewUser, "streetAddress", user.StreetAddress); //街道
            SetProperty(NewUser, "postOfficeBox", user.PostOfficeBox); //邮政信箱
            SetProperty(NewUser, "postalCode", user.PostalCode); //邮政编码
            SetProperty(NewUser, "userPrincipalName", user.UserPrincipalName); //用户登录名
            // SetProperty(NewUser, "logonHours",DateTime.Now.ToString()); //登录时间
            SetProperty(NewUser, "accountExpires", user.AccountExpires); //账户过期
            SetProperty(NewUser, "mail", user.Mail); //寻呼机
            SetProperty(NewUser, "Pager", user.Pager); //寻呼机
            SetProperty(NewUser, "mobile", user.Mobile); //移动电话
            SetProperty(NewUser, "FacsimileTelephoneNumber", user.FacsimileTelephoneNumber); //传真
            SetProperty(NewUser, "ipPhone", user.IpPhone); //IP电话
            SetProperty(NewUser, "wWWHomePage", user.WWWHomePage); //网页
            SetProperty(NewUser, "Info", user.Info); //注释
            SetProperty(NewUser, "Title", user.Title); //职务
            SetProperty(NewUser, "Department", user.Department); //部门
            SetProperty(NewUser, "Company", user.Company); //公司
            SetProperty(NewUser, "sAMAccountName", user.sAMAccountName); //登录名称曾用名
            NewUser.CommitChanges();
            NewUser.Properties["userPassword"].Add(user.UserPassWord);
            NewUser.CommitChanges();
            NewUser.Invoke("SetPassword", new object[] { user.UserPassWord });
            NewUser.CommitChanges();
            AddGroupUser(group, user.UserPrincipalName, de); //将用户添加到组
            EnableAccount(NewUser);
            return "已将用户" + ldapDN + "添加到组";
        }

以下是服务端xml

POST /OperationAD.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length SOAPAction: "http://tempuri.org/AddUser"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <AddUser xmlns="http://tempuri.org/">
      <ldapDN>string</ldapDN>
      <user>
        <EmployeeID>string</EmployeeID>
        <Description>string</Description>
        <SN>string</SN>
        <GivenName>string</GivenName>
        <Initials>string</Initials>
        <displayName>string</displayName>
        <PhysicalDeliveryOfficeName>string</PhysicalDeliveryOfficeName>
        <telephoneNumber>string</telephoneNumber>
        <otherTelephone>string</otherTelephone>
        <C>string</C>
        <St>string</St>
        <L>string</L>
        <StreetAddress>string</StreetAddress>
        <PostOfficeBox>string</PostOfficeBox>
        <PostalCode>string</PostalCode>
        <UserPrincipalName>string</UserPrincipalName>
        <sAMAccountName>string</sAMAccountName>
        <UserPassWord>string</UserPassWord>
        <Pager>string</Pager>
        <Mobile>string</Mobile>
        <Mail>string</Mail>
        <FacsimileTelephoneNumber>string</FacsimileTelephoneNumber>
        <IpPhone>string</IpPhone>
        <Info>string</Info>
        <WWWHomePage>string</WWWHomePage>
        <AccountExpires>string</AccountExpires>
        <Title>string</Title>
        <Department>string</Department>
        <Company>string</Company>
      </user>
      <group>string</group>
      <path>string</path>
      <name>string</name>
      <pwd>string</pwd>
    </AddUser>
  </soap:Body>
</soap:Envelope>

java 客户端测试代码

package webservice;

import org.apache.axis.client.Service;
import org.apache.axis.client.Call;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;

public class TestAxisClient {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  try {
  
  
 // webserviceURL
  String endpoint = "http://localhost:20576/OperationAD.asmx?wsdl";
  Service service = new Service();
  

  
  Call call = (Call) service.createCall();
  call.setTargetEndpointAddress(new java.net.URL(endpoint));
  /**
   QName qn = new QName("user");
     call.registerTypeMapping(UsersInfo.class, qn,
     new BeanSerializerFactory(UsersInfo.class, qn)
     , new BeanDeserializerFactory(UsersInfo.class, qn));   
          注册 bean
         UsersInfo user = new UsersInfo();
         user.C="sda";
         user.Company="xiaosdfna";
         user.Info="sdfajsodfji";
         user.setInfo("sdafsdf");
   */
  // 设置要调用的方法
  call.setOperationName(new QName("http://tempuri.org/","AddUser")); 
  //该方法需要的参数
  call.addParameter(new QName("http://tempuri.org/","ldapDN"),
  org.apache.axis.Constants.XSD_STRING,
  ParameterMode.IN);
  
  //此处缺少一个实体类参数[java中有个UsersInfo.class实体类]
  /**call.addParameter(new QName("http://tempuri.org/","user"),
  org.apache.axis.Constants.XSD_STRING,UsersInfo.class,
  ParameterMode.IN); 
  call.registerTypeMapping(UsersInfo.class,qx,new BeanSerializerFactory(UsersInfo.class, qx),new BeanDeserializerFactory(UsersInfo.class, qx));
  call.addParameter(new QName("http://tempuri.org/","group"), 
  org.apache.axis.Constants.XSD_STRING,
  ParameterMode.IN);*/
  call.addParameter(new QName("http://tempuri.org/","path"),
  org.apache.axis.Constants.XSD_STRING,
  ParameterMode.IN);
  call.addParameter(new QName("http://tempuri.org/","name"),
  org.apache.axis.Constants.XSD_STRING,
  ParameterMode.IN);
  call.addParameter(new QName("http://tempuri.org/","pwd"),
  org.apache.axis.Constants.XSD_STRING,
  ParameterMode.IN);
  
  call.setReturnClass(UsersInfo.class);  
  // 方法的返回值类型  
  call.setReturnType(org.apache.axis.Constants.XSD_STRING);  
  call.setUseSOAPAction(true);
  call.setSOAPActionURI("http://tempuri.org/AddUser");
  // 调用该方法,
  String ret = (String)call.invoke(new Object[] { "22",user,"23","22","12","23"});
  System.out.println("Successful = " + ret);
  
  } catch (Exception e) {
  System.err.println(e.toString());
  }
  
  }
}

 

加载中
返回顶部
顶部