Java使用Axis调用.NET语言开发的WebService

本文介绍了一种使用Java结合Apache Axis库调用.NET开发的WebService的方法。通过具体代码示例,展示了如何设置请求参数、操作命名空间及方法名等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Java结合Axis调用.net语言开发的WebService

=====================具体参见代码=================================

package com;

import java.net.URL;

import javax.xml.namespace.QName;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

/**
 * 平台请求客户端(Axis+WebService)
 * 所需jar包
 * jaxrpc.jar
 * axis.jar
 * wsdl4j-1.5.1.jar
 * commons-discovery-0.2.jar
 * commons-logging-1.0.4.jar
 *
 */
public class Client {

 /**
  * WebService请求(因只有一个参数@_@)
  * @param url   服务器请求URL
  * @param namespace  WebService命名空间(targetNamespace="http://tempuri.org/")
  * @param methodName 方法名称(<xs:element name="SubmitOrder" />)
  * @param parameterName 参数名称(参数名称必须和WebService方法的参数的名称一样
  *       {<xs:element minOccurs="0" name="args" nillable="true" type="xs:string" />})
  * @param actionUrl  方法对应的ActionURI(<wsdl:input wsaw:Action="actionUrl" message="tns:xxx" />)
  * @param request   请求报文
  */
 public static String send(String url, String namespace, String methodName, String parameterName, 
   String actionUrl, String request) throws Exception {
  Service service = new Service();
  Call call = (Call)service.createCall();
  call.setOperationName(new QName(namespace, methodName));
  call.addParameter(new QName(namespace, parameterName), XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
  call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING); 
  call.setTargetEndpointAddress(new URL(url));
  call.setUseSOAPAction(true);
  call.setSOAPActionURI(actionUrl);
  String response = (String)call.invoke(new String[]{request});
  
  return response;
 }
 }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值