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

1、C#写Webservices方法定义
[SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)] //必须这样写
[WebService(Namespace = "http://qqbbxpd.xicp.net/")] //必须这样写,注意URL
public class WebServiceIPDA : System.Web.Services.WebService
{
/// <summary>
/// 业务员登录
/// </summary>
/// <param name="aUserID">业务员编号</param>
/// <param name="aPWD">业务密码</param>
/// <returns>成功返回:'T',失败返回'F'</returns>
[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
}


}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值