Home Database Mysql Tutorial axis2客户端调用免费的webservice服务的实例之三axis2使用RPC方

axis2客户端调用免费的webservice服务的实例之三axis2使用RPC方

Jun 07, 2016 pm 03:15 PM
webservice free client Serve transfer

前面两节我们分别说了调用webservice的两种方式: 1.axis2客户端调用免费的webservice服务的实例之一通过wsdl生成客户端程序并本地调用 2 . axis2客户端调用免费的webservice服务的实例之二纯手动调用免费天气预报webservice服务 下面我们介绍一下第三种方式

前面两节我们分别说了调用webservice的两种方式:

1.axis2客户端调用免费的webservice服务的实例之一通过wsdl生成客户端程序并本地调用

2.axis2客户端调用免费的webservice服务的实例之二纯手动调用免费天气预报webservice服务

下面我们介绍一下第三种方式:axis2使用RPC方式调用网上免费WebService 

这种方式类似第二种方式,只是用到的类不同,但是这种方式感觉容易出问题。不多说,直接上代码

<span style="color:#3b5998;">package com.yy.test;

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;

//</span><span style="color:#ff6600;">使用webservice无参数的方法:getRegionProvince</span>
Copy after login
public class Test2 {
	public static void main(String args[]) throws AxisFault{  
	    //使用RPC方式调用WebService   	
	    RPCServiceClient serviceClient = new RPCServiceClient();  
	    Options options = serviceClient.getOptions();  
	    //指定调用WebService的URL  
	    EndpointReference targetEPR = new EndpointReference(  
	            "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl");  
	    options.setTo(targetEPR);  
	    options.setAction("http://WebXml.com.cn/getRegionProvince");
	    //指定方法的参数值  
	    Object[] opAddEntryArgs = new Object[] {};  
	    //指定要调用的方法及WSDL文件的命名空间  
	    QName opAddEntry = new QName("http://WebXml.com.cn/", "getRegionProvince");  
	    //调用法并输出该方法的返回值  
	    System.out.println(serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs));
	    /*Object[] result=serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes);
	    for (Object object : result) {
	    	System.out.println(object.toString());
	    }*/
	}
}  
Copy after login
其运行结果:

黑龙江,3113吉林,3114辽宁,3115内蒙古,3116河北,3117河南,3118山东,3119山西,31110江苏,31111安徽,31112陕西,31113宁夏,31114甘肃,31115青海,31116湖北,31117湖南,31118浙江,31119江西,31120福建,31121贵州,31122四川,31123广东,31124广西,31125云南,31126海南,31127新疆,31128西藏,31129台湾,31130北京,311101上海,311102天津,311103重庆,311104香港,311201澳门,311202钓鱼岛,311203


相同的webservive服务,本次使用有参数的方法:getSupportCityString

package com.yy.test;

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;

<a target="_blank" href="http://blog.csdn.net/mingliangniwo/article/details/44202139" style="list-style: none; text-decoration: none; word-break: break-all; word-wrap: break-word; font-family: Verdana, 'Lucida Grande', Arial, Helvetica, sans-serif;"></a><pre name="code" class="java"><span style="color:#3b5998;">//</span><span style="color:#ff6600;">使用webservice有参数的方法:getSupportCityString</span>
Copy after login
public class Test2 {public static void main(String args[]) throws AxisFault{  
Copy after login
            //指定调用WebService的URL
	    RPCServiceClient serviceClient2 = new RPCServiceClient();  
	    Options options2 = serviceClient2.getOptions();  
	    //指定调用WebService的URL  
	    EndpointReference targetEPR2 = new EndpointReference(  
	            "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl");  
	    options2.setTo(targetEPR2);  
	    options2.setAction("http://WebXml.com.cn/getSupportCityString");
	    //指定方法的参数值  
	    Object[] opAddEntryArgs2 = new Object[] {"北京"};  
	    //指定方法返回值的数据类型的Class对象  
	    Class[] classes2 = new Class[] {String.class};  
	    //指定要调用的方法及WSDL文件的命名空间  
	    QName opAddEntry2 = new QName("http://WebXml.com.cn/", "getSupportCityString");  
	    //调用法并输出该方法的返回值  
	    System.out.println(serviceClient2.invokeBlocking(opAddEntry2, opAddEntryArgs2, classes2));
	}
}  
Copy after login

其运行结果:

axis2客户端调用免费的webservice服务的实例之三axis2使用RPC方


有时还会出现下面这个错误:

axis2客户端调用免费的webservice服务的实例之三axis2使用RPC方


在网上查了好多,都没有什么解决方案,有了答案是让用方式一或方式二的方式

原因:说的都是webservice服务那边的问题。

所以大家可以更多的使用方式一或方式二去webserive开发


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VMware Horizon Client cannot be opened [Fix] VMware Horizon Client cannot be opened [Fix] Feb 19, 2024 pm 11:21 PM

VMware Horizon Client helps you access virtual desktops conveniently. However, sometimes the virtual desktop infrastructure may experience startup issues. This article discusses the solutions you can take when the VMware Horizon client fails to start successfully. Why won't my VMware Horizon client open? When configuring VDI, if the VMWareHorizon client is not open, an error may occur. Please confirm that your IT administrator has provided the correct URL and credentials. If everything is fine, follow the solutions mentioned in this guide to resolve the issue. Fix VMWareHorizon Client Not Opening If VMW is not opening on your Windows computer

VMware Horizon client freezes or stalls while connecting [Fix] VMware Horizon client freezes or stalls while connecting [Fix] Mar 03, 2024 am 09:37 AM

When connecting to a VDI using the VMWareHorizon client, we may encounter situations where the application freezes during authentication or the connection blocks. This article will explore this issue and provide ways to resolve this situation. When the VMWareHorizon client experiences freezing or connection issues, there are a few things you can do to resolve the issue. Fix VMWareHorizon client freezes or gets stuck while connecting If VMWareHorizon client freezes or fails to connect on Windows 11/10, do the below mentioned solutions: Check network connection Restart Horizon client Check Horizon server status Clear client cache Fix Ho

Where can I read Feilu novels for free? Feilu Novel reads free novel operation tutorials! Where can I read Feilu novels for free? Feilu Novel reads free novel operation tutorials! Mar 15, 2024 pm 03:10 PM

1. Where can I read Feilu novels for free? Feilu Novel reads free novel operation tutorials! 1. If you want to know where you can find free novels on the Feilu Novel App, then come and download the [Feilu Novel Free Version App] to experience it! Feilu Novel Free Edition app Category: News Reading Download Feilu Novel Free Edition app is an excellent mobile reading application, which provides users with a large number of high-quality novel resources. There are various types of novels on this platform, including fantasy, cultivation, history, romance, etc. Users can choose the genre they like to read. The reading experience of Feilu Novel Free Edition app is excellent. It has a good interface design, fast loading speed and smooth reading experience. 2. Open the downloaded app, enter the homepage, and click

How to open Remote Desktop Connection Service using command How to open Remote Desktop Connection Service using command Dec 31, 2023 am 10:38 AM

Remote desktop connection has brought convenience to many users' daily lives. Some people want to use commands to connect remotely, which is more convenient to operate. So how to connect? Remote Desktop Connection Service can help you solve this problem by using a command to open it. How to set up the remote desktop connection command: Method 1. Connect remotely by running the command 1. Press "Win+R" to open "Run" and enter mstsc2, then click "Show Options" 3. Enter the IP address and click "Connect". 4. It will show that it is connecting. Method 2: Connect remotely through the command prompt 1. Press "Win+R" to open "Run" and enter cmd2. In the "Command Prompt" enter mstsc/v:192.168.1.250/console

What is the correct way to restart a service in Linux? What is the correct way to restart a service in Linux? Mar 15, 2024 am 09:09 AM

What is the correct way to restart a service in Linux? When using a Linux system, we often encounter situations where we need to restart a certain service, but sometimes we may encounter some problems when restarting the service, such as the service not actually stopping or starting. Therefore, it is very important to master the correct way to restart services. In Linux, you can usually use the systemctl command to manage system services. The systemctl command is part of the systemd system manager

PHP MQTT Client Development Guide PHP MQTT Client Development Guide Mar 27, 2024 am 09:21 AM

MQTT (MessageQueuingTelemetryTransport) is a lightweight message transmission protocol commonly used for communication between IoT devices. PHP is a commonly used server-side programming language that can be used to develop MQTT clients. This article will introduce how to use PHP to develop an MQTT client and include the following content: Basic concepts of the MQTT protocol Selection and usage examples of the PHPMQTT client library: Using the PHPMQTT client to publish and

Inventory of free and easy-to-use mobile phone screen recording software_A collection of easy-to-use mobile phone screen recording apps Inventory of free and easy-to-use mobile phone screen recording software_A collection of easy-to-use mobile phone screen recording apps Mar 02, 2024 pm 12:46 PM

The editor of this website recently took stock of some free and easy-to-use mobile phone screen recording software to help you record the screen anytime and anywhere on your mobile phone. For example, for live broadcasters and gamers, you can record your own beautiful moments. In a moment, I will give you a summary report below. I hope you like it. Inventory of free and easy-to-use mobile phone screen recording software 1, EV screen recording 1, the editor has been using this EV screen recording, it is really simple and practical, as an office artifact, it has no ads, no plug-ins, and takes up a lot of space. The memory space of your mobile phone is small, so the phone will not become laggy, and there are more video editing functions for everyone to use. The recorded video is very clear, and it supports the lossless transfer of video files between mobile devices and computer devices. Isn’t it very frustrating? You are excited. to

What is the mobile client What is the mobile client Aug 16, 2023 pm 01:40 PM

A mobile client refers to an application that runs on a smartphone and provides users with various functions and services in the form of a native client or a web client. Mobile clients can be divided into two forms: original clients and web clients. Native clients refer to applications written for specific operating systems using specific programming languages ​​and development tools. The advantage of web clients is that they have good cross-platform compatibility. , can run on different devices without operating system restrictions, but compared to the native client, the performance and user experience of the web client may be reduced.

See all articles