java客户端调用C#webservice服务相关问题
2016-11-04 09:56
501 查看
1、解决无法识别请求元素问题
在c#类名的空间下面添加
[WebService(Namespace = "http://tempuri.org/")]
java代码修改:
mCall.setOperationName(new QName("http://tempuri.org/","HelloWord"));
2、解决参数丢失问题
在C#类中每一个webservice方法前面添加:
[SoapRpcMethod(Use = SoapBindingUse.Literal, Action = "http://tempuri.org/HelloWord",
RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/")]
服务端:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Description;
using System.Web.Services.Protocols;
using System.Diagnostics;
namespace WebApplication1
{
/// <summary>
/// WebService1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
[SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
public class WebService1 : System.Web.Services.WebService
{
[SoapRpcMethod(Use = SoapBindingUse.Literal, Action = "http://tempuri.org/HelloWord",
RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/")]
[WebMethod]
public string HelloWorld(string name)
{
//Console.WriteLine("name:"+name);
//Console.ReadKey();
Debug.WriteLine("NAME:"+name);
return "hello"+name;
}
[SoapRpcMethod(Use = SoapBindingUse.Literal, Action = "http://tempuri.org/add", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/")]
[WebMethod]
public int add(int x, int y)
{
return x + y;
}
}
}
客户端
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class test4 {
public static void main(String[] args) throws RemoteException, MalformedURLException, ServiceException {
String service_url = "http://localhost:30332/WebService1.asmx";
Service ser = new Service();
Call call = (Call) ser.createCall();
call.setTargetEndpointAddress(new java.net.URL(service_url));
QName opAddEntry = new QName("http://tempuri.org/", "HelloWorld");
call.setOperationName(opAddEntry);
call.addParameter("name", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING); Object[] opAddEntryArgs = new Object[] { "jone" };
String result = (String) call.invoke(opAddEntryArgs);
call.invoke("http://tempuri.org/", "HelloWorld", opAddEntryArgs);
System.out.println("result:" + result);
}
}
部分摘自:http://bbs.csdn.net/topics/390617053
在c#类名的空间下面添加
[WebService(Namespace = "http://tempuri.org/")]
java代码修改:
mCall.setOperationName(new QName("http://tempuri.org/","HelloWord"));
2、解决参数丢失问题
在C#类中每一个webservice方法前面添加:
[SoapRpcMethod(Use = SoapBindingUse.Literal, Action = "http://tempuri.org/HelloWord",
RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/")]
服务端:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Description;
using System.Web.Services.Protocols;
using System.Diagnostics;
namespace WebApplication1
{
/// <summary>
/// WebService1 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
[SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
public class WebService1 : System.Web.Services.WebService
{
[SoapRpcMethod(Use = SoapBindingUse.Literal, Action = "http://tempuri.org/HelloWord",
RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/")]
[WebMethod]
public string HelloWorld(string name)
{
//Console.WriteLine("name:"+name);
//Console.ReadKey();
Debug.WriteLine("NAME:"+name);
return "hello"+name;
}
[SoapRpcMethod(Use = SoapBindingUse.Literal, Action = "http://tempuri.org/add", RequestNamespace = "http://tempuri.org/", ResponseNamespace = "http://tempuri.org/")]
[WebMethod]
public int add(int x, int y)
{
return x + y;
}
}
}
客户端
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class test4 {
public static void main(String[] args) throws RemoteException, MalformedURLException, ServiceException {
String service_url = "http://localhost:30332/WebService1.asmx";
Service ser = new Service();
Call call = (Call) ser.createCall();
call.setTargetEndpointAddress(new java.net.URL(service_url));
QName opAddEntry = new QName("http://tempuri.org/", "HelloWorld");
call.setOperationName(opAddEntry);
call.addParameter("name", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING); Object[] opAddEntryArgs = new Object[] { "jone" };
String result = (String) call.invoke(opAddEntryArgs);
call.invoke("http://tempuri.org/", "HelloWorld", opAddEntryArgs);
System.out.println("result:" + result);
}
}
部分摘自:http://bbs.csdn.net/topics/390617053
相关文章推荐
- 关于java中Axis2客户端调用C#webservice服务端包含Cookie问题
- java客户端调用c#的webservice服务
- 用C#.NET调用Java开发的WebService传递int,double问题
- Java 调用C# webservice接口 生成java客户端 实现方式
- 客户端(C#)调用CXF搭建的webservice的出现一些问题记录
- 用C#.NET调用Java开发的WebService传递int,double问题,出现java无法获得值!
- java调用xfire webService服务客户端代码
- c#调用java写的webservice数据丢失有关问题
- 【工作记录0022】C#(.NET)调用Java开发的WebService(wsdl),客户端传递非string类型参数(int,double,bool等),而服务端无法获取到参数值的解决方案
- webservice接口常见问题1:客户端使用SOAP方式调用CXF服务时异常
- C#开发WEBService服务 C++开发客户端调用WEBService服务
- 求救:C# 调用JAVA写的WEBSERVICE的问题!
- 问题:C#调webservice超时;结果:C#调用webservice服务超时
- java生成webservice客户端及服务调用
- 用C#.NET调用Java开发的WebService传递int,double问题,出现java无法获得值!
- 调用WebService超时问题汇总(Java、C#)
- C# 调用JAVA(使用axis)开发的webservice 提示错误的问题
- java 用cxf方式实现的webservice,java客户端,C#客户端调用
- 【转】用C#.NET调用Java开发的WebService传递int,double问题,出现java无法获得值!
- webservice 针对WebService服务,客户端调用时报序列化的最大项数maxItemsInObjectGraph超过65536问题