c# 编写webservices方法及注意事项

1、C#写Webservices方法定义
     [SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]   //必须这样写
    [WebService(Namespace = "http://qqbbxpd.xicp.net/")]                           //必须这样写,注意URL 
    public class WebServiceIPDA : System.Web.Services.WebService
    {
        ///


        /// 业务员登录
         ///

        /// 业务员编号
        /// 业务密码
        /// 成功返回:'T',失败返回'F'
        [WebMethod]
        public string Login(string aUserID, string aPWD)
        {
            string result = "T";
            try
            {
                IDataParameter[] parms = new SqlParameter[] { new SqlParameter("@v_UserID", aUserID), new SqlParameter("@v_PWD", aPWD) };

                DataSet dsLogin = DataBaseSrvConn.ExecuteDataSet(CommandType.StoredProcedure, "p_CheckBusLogin", parms);

                if (!(dsLogin.Tables[0] != null && dsLogin.Tables[0].Rows[0]["Result"].ToString().Trim() == "T"))
                {
                    result = "F";
                }
            }
            catch
            {
                result = "F";
            }
            return result;
        }
      }

2、java调用:

import org.apache.axis.AxisFault;
import org.apache.axis.client.Call; 
import org.apache.axis.client.Service; 
import org.apache.axis.message.MessageElement;

import javax.xml.namespace.QName; 
import javax.xml.rpc.ServiceException; 
import java.net.MalformedURLException; 
import java.rmi.RemoteException; 
import org.w3c.dom.*; 

import _99._1._168._192.GetClientBaseResponseGetClientBaseResult;
import _99._1._168._192.GetGoodBaseResponseGetGoodBaseResult;
import _99._1._168._192.WebServiceIPDALocator;
import _99._1._168._192.WebServiceIPDASoapStub;

public class callWebservice {

 /**
  * @param args
  * @throws ServiceException
  * @throws MalformedURLException
  * @throws RemoteException
  * @throws AxisFault
  */
 public static void main(String[] args) throws MalformedURLException, RemoteException, ServiceException  {
  // TODO Auto-generated method stub

      // axis1CallWebService();
  axis2Callwebservice();
 
 }
 
 static void axis1CallWebService() throws ServiceException, MalformedURLException, RemoteException{
  String endpoint = "http://jcsoddddddd.vicp.net:8090/WebServiceIPDA.asmx?wsdl";
  // 创建一个服务(service)调用(call)
  Service service = new Service();
  Call call = (Call) service.createCall();// 通过service创建call对象
  // 设置service所在URL
 
  // 设置要调用的方法
  call.setOperationName(new QName(
    "http://qqbbsssssssssssssssssssssxpd.xicp.net/", "Login"));
  // 设置该方法需要的参数
  call.addParameter("aUserID",
    org.apache.axis.encoding.XMLType.XSD_STRING,
    javax.xml.rpc.ParameterMode.IN);
  call.addParameter("aPWD", org.apache.axis.encoding.XMLType.XSD_STRING,
    javax.xml.rpc.ParameterMode.IN);
  // 设置方法返回值的类型
  call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
  //call.setUseSOAPAction(true);
  // 调用该方法
  //call.setSOAPActionURI("http://jcsofffffffffffffffffft99.vicp.net:8090/WebServiceIPDA.asmx");
  call.setTargetEndpointAddress(new java.net.URL(endpoint));
  String ret = (String) call.invoke(new Object[] { "00001", "123456" });

  System.out.println(ret);


  
 }
 
 
 static void axis2Callwebservice() throws RemoteException, ServiceException{
  WebServiceIPDALocator wl=new WebServiceIPDALocator();
  WebServiceIPDASoapStub  wb=(WebServiceIPDASoapStub) wl.getWebServiceIPDASoap();
     //String ret= wb.login("00001", "9:;<=>");
    // GetGoodBase("ae","00001")
  GetGoodBaseResponseGetGoodBaseResult ret=   wb.getGoodBase("ae", "00001");
  if(ret!=null){
      System.out.println("OK");
    MessageElement[]  ss= ret.get_any();
         System.out.print(ss.length);
   
    //  ret.g
  }


 }

}

 

 

你可能感兴趣的:(.NET,c#,string,import,service,webservice,dataset)