Novice Build call WebService those pits

Source: Internet
Author: User
Tags soap wsdl

Today mainly to share with you build Java version webservice, and PHP call WebService encountered some pit < (^-^) > Concise version of the tutorial (blog content mostly purely hand-hit, Pure Pro Test) Note: There are many tutorials on the web that use Eclipse to build WebService, but the configuration is cumbersome and may not be accessible in the end. Therefore, this blog uses MyEclipse to build. It is important to note that MyEclipse10 and the following cannot support the pattern library, so the published project will contain Java.util.regex.Pattern;is not supported, which is why bloggers change the IDE.

Development environment: MYECLIPSE2014,JAX-WS build (easy to use), Tomcat 7

What is WebService? It is a universal model of building applications that can be run in any operating system that supports network communication; it is a new branch of Web application that is a self-contained, self-describing, modular application that can be published, positioned, and called through the web. A Web service is an application component that logically provides data and services to other applications. Each application accesses a Web service through a network protocol and some standard data formats (HTTP,XML,SOAP), through the web Service internal execution gets the desired results. WEB Service can perform any function from simple requests to complex business processing. Once deployed, other Web service applications can discover and invoke the services it deploys.
Key Technologies and rules

The following key techniques and rules are used when building and using Web service:

  1. XML: A standard way to describe data.
  2. SOAP: The protocol that represents the exchange of information.
  3. Wsdl:web Service Description Language.
  4. UDDI: General description, Discovery, and integration, a platform-independent, XML-based protocol for describing commerce on the Internet.
XML

Extensible Markup Language (XML) is the basic format for representing data in a Web service platform. In addition to being easy to establish and easy to analyze, the main advantage of XML is that it is platform-independent and vendor-independent. Independence is more important than technical superiority: Software vendors do not choose a technology invented by competitors.

SOAP

SOAP is the standard communication protocol for Web service, and SOAP is the abbreviation for simple Object access Protocoll. It is a standardized XML message format for transmitting messages.

WSDL

The full name of the WSDL is the Web service Description Language, which is a descriptive language for Web services based on XML format. The main purpose of the Web service provider is to provide all relevant content of their Web services, such as the transmission of the services provided, service method interfaces, interface parameters, service paths, etc., to generate the corresponding full document, published to the user. The user can create the corresponding SOAP request message via HTTP to the WebService provider through this WSDL document, and the Web service passes the SOAP return message back to the requestor after the service request is completed. The service requester then parses the SOAP return message from the WSDL document into what it can understand.

UDDI

To publish a Web service for UDDI registration, UDDI is a specification for creating a registry service so that everyone can register their Web service for publication for the user to find. However, when a service provider wants to publish its Web service to the world, In order to find its services externally, the service provider can register its own web service with the appropriate UDDI business registration site, which currently has 4 UDDI business registration sites worldwide, such as IBM. Because the address URI of the Web service is already given in the WSDL file, the external can make the corresponding Web service call directly from the URI provided by the WSDL. So UDDI is not a required Web service component, and the service party can completely register without UDDI.

Start building WebServicePrerequisite: First install good MyEclipse2014, ensure that the JDK environment is configured, there is Tomcat server (no, it's okay, MyEclipse comes with MyEclipse Tomcat 7, pro-test, the default port is 8080).
  • Create a release WebService
  • Configure Tomcat
  • Deploy the project and start the Tomcat server
  • Add JAX-WS libraries
  • Test WebService
Create a release WebServiceCreate a new web Service Project

Then fill in the information and next.

Next, you can choose to generate Web. Xml. This is the newly created project structure

Then create a new class of files Userinfo.java

Sample source code:

package com.yuan.webservice;/** *  * @author Joryun * */publicclass UserInfo {    publicGetUserInfo(){        return"源哥";    }    publicParameterTest(String user, String pwd){        return user+":"+pwd;    }}
Next publish the Web service

Choose to create a Web service from a Java class

Select the Java class to access

Generate WSDL (WSDL above has introduction, do not know can go back to see)

Post-release project structure is as follows

Configure TomcatAssuming you need to use your own native Tomcat, the tutorial is as follows: Window-preferences-myeclipse-servers-tomcat

Apply-ok after configuration. deploy the project and start the Tomcat serverDeploy this project to the server

After you finish selecting Finish, start the Tomcat server

The server has started the legend

add JAX-ws librariesAdd a library file to the project's build path

Test WebServiceEnter the URL and the schema effect appears for the publication to succeed.

url:http://localhost:8080/webservicedemo/userinfoport?wsdl

PHP Call WebServiceNote: Bloggers Use the CI framework test, but not the same as the framework. and the PHP project file is published on the XAMPP, directly accessible locally to see the effect. About PHP Call WebService, the two methods of pro-test:
1. Introduction of nusoap.php, Call () method Special Note: The following two is the pit point of the red circle, the first test with the WebService interface name parameters, that is, user, PWD. But it was actually printed on the Web page before the parameters were found to be arg0 and arg1 ...

2. PHP5 self-function test, Classmap mode pass value

The following PHP implementation of the source code:
<?phpheader (' content-type:text/html; Charset=utf-8 ');/** * Class Test * Joryun * * Call WebService Test class * * class Test extends ci_controller {Public Function __construct () {parent::__construct (); } public Function index () {/** * nusoap.php need to be downloaded online, and the PHP file included in the project space * introduced nusoap.php, call () method *///require_once ("libs/nusoap.php");////// Create the client instance//$client = new Nusoap_client (' http://localhost:8080/WeixinDemo/UserInfoPort?wsdl ', true);//$client->soap_defencoding = ' utf-8 ';//$client->decode_utf8 = false;//$client->xml_encoding = ' utf-8 ';////$param = Array (' arg0 ' = ' Joryun ', ' arg1 ' = ' 666666 ');//webservice parameter array//$result = $client->call (' parametertest ', $param);//interfaces and Parameters//Print_r ($result);        /** * php5 own function Test * classmap mode value */$client =NewSoapClient ("HTTP://LOCALHOST:8080/WEIXINDEMO/USERINFOPORT?WSDL"); Echo ("Open function provided by the SOAP server:"); Echo' <pre> '; Var_dump ($client->__getfunctions ());//Get methods available on the serverEcho' </pre> '; Echo' <br> '; Echo ("The type provided by the SOAP server:"); Echo' <pre> '; Var_dump ($client->__gettypes ());//Get data types on the serverEcho' </pre> '; $Object=NewStdclass $Object->arg0=' Joryun '; $Object->arg1=' 666666 '; $result = $client->parametertest ($Object);//$result =get_object_vars ($result); Convert an object to an arrayVar_dump ($result); }}?>
Well, today's tutorial is about here. < ( ̄︶ ̄) > Of course, the reason to share is because there are some pits in it, and it took more than a day to get it done. Welcome to communicate, there is no guide to speak frankly haha haha ~ ~

Novice Build call WebService those pits

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.