axis2客户端调用免费的webservice服务的实例之三axis2使用RPC方
前面两节我们分别说了调用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>
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()); }*/ } }
相同的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>
//指定调用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)); } }
其运行结果:
有时还会出现下面这个错误:
在网上查了好多,都没有什么解决方案,有了答案是让用方式一或方式二的方式
原因:说的都是webservice服务那边的问题。
所以大家可以更多的使用方式一或方式二去webserive开发

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
![VMware Horizon Client cannot be opened [Fix]](https://img.php.cn/upload/article/000/887/227/170835607042441.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
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]](https://img.php.cn/upload/article/000/887/227/170942987315391.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
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

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

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? 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

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

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

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.
