java控制台调用webserivce(C#写的)例子
2016-11-01 11:10
253 查看
步骤:
1、添加axis包:
2、webservices中的代码
/// <summary>
/// BarCodeServices 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class BarCodeServices : System.Web.Services.WebService
{
[WebMethod]
public string GetBarCodeInformation(string BarCode, string UserName, string PassWord)
{
return "XXXXXXX";
}
}
3、Java中的代码:
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
public class MainClass {
public static void main(String[] args) throws Exception{
WebServicesUsed();
}
//webservices调用例子
public static void WebServicesUsed() throws Exception
{
// 定义方法
String method = "GetBarCodeInformation";
// 定义服务
Service service = new Service();
// 测试1:调用HelloWorld方法,方法没有参数
Call call2 = (Call) service.createCall();
call2.setTargetEndpointAddress(new java.net.URL("http://10.2.32.64:7005/WebServices/BarCodeServices.asmx")); //weibservice地址
call2.setUseSOAPAction(true);
call2.setReturnType(new QName("http://www.w3.org/2001/XMLSchema","string"));
call2.setOperationName(new QName("http://tempuri.org/", method)); //webservice中namespace
call2.setSOAPActionURI("http://tempuri.org/GetBarCodeInformation"); //webservice中namespace的方法
call2.addParameter(new QName("http://tempuri.org/", "BarCode"),XMLType.XSD_STRING, ParameterMode.IN); //参数
call2.addParameter(new QName("http://tempuri.org/", "UserName"),XMLType.XSD_STRING, ParameterMode.IN); //参数
call2.addParameter(new QName("http://tempuri.org/", "PassWord"),XMLType.XSD_STRING, ParameterMode.IN); //参数
String retVal2 = (String) call2.invoke(new Object[] { "8427650000468","SJYB","81e50f63" }); //参数值
System.out.println(retVal2);
}
}
4、输出结果(json格式):
{"barcode":"8427650000468"}
1、添加axis包:
2、webservices中的代码
/// <summary>
/// BarCodeServices 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class BarCodeServices : System.Web.Services.WebService
{
[WebMethod]
public string GetBarCodeInformation(string BarCode, string UserName, string PassWord)
{
return "XXXXXXX";
}
}
3、Java中的代码:
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
public class MainClass {
public static void main(String[] args) throws Exception{
WebServicesUsed();
}
//webservices调用例子
public static void WebServicesUsed() throws Exception
{
// 定义方法
String method = "GetBarCodeInformation";
// 定义服务
Service service = new Service();
// 测试1:调用HelloWorld方法,方法没有参数
Call call2 = (Call) service.createCall();
call2.setTargetEndpointAddress(new java.net.URL("http://10.2.32.64:7005/WebServices/BarCodeServices.asmx")); //weibservice地址
call2.setUseSOAPAction(true);
call2.setReturnType(new QName("http://www.w3.org/2001/XMLSchema","string"));
call2.setOperationName(new QName("http://tempuri.org/", method)); //webservice中namespace
call2.setSOAPActionURI("http://tempuri.org/GetBarCodeInformation"); //webservice中namespace的方法
call2.addParameter(new QName("http://tempuri.org/", "BarCode"),XMLType.XSD_STRING, ParameterMode.IN); //参数
call2.addParameter(new QName("http://tempuri.org/", "UserName"),XMLType.XSD_STRING, ParameterMode.IN); //参数
call2.addParameter(new QName("http://tempuri.org/", "PassWord"),XMLType.XSD_STRING, ParameterMode.IN); //参数
String retVal2 = (String) call2.invoke(new Object[] { "8427650000468","SJYB","81e50f63" }); //参数值
System.out.println(retVal2);
}
}
4、输出结果(json格式):
{"barcode":"8427650000468"}
相关文章推荐
- delphi调用C#写的web服务例子-----------(重点 InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceSoap), ioDocu
- C#调用java WebService传递图片
- c#与java webservice调用问题
- C# 调用 JavaWebservice服务遇到的问题汇总
- Delphi 调用JAVA WebService 操作数据库登录的例子
- delphi调用C#写的web服务例子-----------(重点 InvRegistry.RegisterInvokeOptions(TypeInfo(ServiceSoap), ioDocument);)
- C# 调用Java webservices 步骤并下载数据
- Java WebService例子--------调用www.36wu.com查询IP地址
- java webservice调用c#接口并传多个参数
- php使用NuSoap调用java/C# webservice的中文乱码问题
- [z]c#调用Java webService的专题(一)
- 万能的Java WebService调用程序支持C# JAVA WS调用
- delphi调用C#写的web服务例子
- c#调用Java webService的专题
- C# 调用JAVA WebService
- .net 调用Java Webservice 例子
- Delphi 调用JAVA WebService例子
- 关于 C# 调用 JavaWebservice服务,版本不一致的问题
- c# 调用java webservice带有soapheader