Explanation of a parameter problem that WebService uses the service class to obtain the Port Class

Source: Internet
Author: User

Finally, when learning WebService, we can see that the official example is written in this way.

privatestatic final QName PORT_NAME =newQName("http://server.hw.demo/","HelloWorldPort");Service service = Service.create(SERVICE_NAME);String endpointAddress = "http://localhost:9000/helloWorld";service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);HelloWorld hw = service.getPort(HelloWorld.class);

Note that the above port_name is defined as a QNAME, which has a namespaceuri and a name value. The interface name parameter is directly transmitted when Serivce is used to obtain the port.

This example can be run, which causes me to copy the corresponding code directly when writing the reference example, but changed the names of the items. At runtime, the error is

java.net.MalformedURLException: Invalid address. Endpoint address cannot be null.

The above error directly makes people unable to find the direction. The actual problem is that the Service builds a QNAME information by default when only interface information is transmitted Based on the transmitted information, search for it from the service. If it cannot be found, the above error will naturally occur.

In the official example, it will build a QNAME such as helloworldport by default to search for it, and the QNAME helloworldport is just added during service. Add, so it is exactly found.

In our example, due to a lot of processing, the port name added to the service by default is not a service. class. the combination of getname + port will naturally fail to find the corresponding port. The correct method is actually very simple, that is, when obtaining the port, manually specify the QNAME of the port class to be obtained, as shown below:

QName userServicePortQName = newQName("http://cxf.java.study.m_ylf.com/","abcPort");service.addPort(userServicePortQName, SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:8080/userService");UserService userService = service.getPort(userServicePortQName, UserService.class);

That is, what kind of port is added to the service, and what kind of QNAME will be used for obtaining. In another step, the addport method can be understood as appending a port to the service as a key-value pair, so the corresponding key value will naturally be provided when it is obtained. If this parameter is not provided, a key value will be created using the default generation policy. If the key value is different from the key value used by addport, the above error will naturally occur.

Remarks: This article Reprinted from: http://www.iflym.com/index.php/tag/cxf

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.