jax-ws中Undefined port type:{http://chillyc.info/api}Name.

来自http://blog.csdn.net/cctt_1/article/details/8639903

接口代码:

package myws;  
  
import javax.jws.WebParam;  
import javax.jws.WebService;  
  
/** 
 * 
 * @author 帐前卒 
 * 
 */  
@WebService(targetNamespace = "http://chillyc.info/api", name="HELLO")  
public interface WebServiceAPI {  
    String hello(@WebParam(name="name")String name);  
  
}  
View Code
这里要注意的是 那个hello函数,必须与webService发布的函数名相一致(要看wdsl文件中的名字。) 另外WebParam中的name也需要和发布函数中的参数名字一致。 这里WebService中传入了两个值。其中name就是刚才WebService中的name. 其实就是wsdl中的portType. 如果这里写错了。就会有Undefined port type:{http://chillyc.info/api}Name. 这个错误。所以要小心。
package myws;  
  
import java.io.IOException;  
import javax.jws.WebMethod;  
import javax.jws.WebParam;  
import javax.jws.WebResult;  
import javax.jws.WebService;  
import javax.xml.bind.annotation.XmlAccessType;  
import javax.xml.bind.annotation.XmlAccessorType;  
import javax.xml.bind.annotation.XmlRootElement;  
import javax.xml.ws.Endpoint;  
  
/** 
 * 
 * @author 帐前卒 
 * 
 */  
@WebService(  
        name="HELLO",  
        targetNamespace="http://chillyc.info/api",   
        serviceName="API",   
        portName="PortName")  
public class WebServiceHolder {  
    @WebMethod  
    @WebResult(name="return")  
    public String hello(@WebParam(name="name")String name) {  
        return "hello" + name;  
    }  
      
    public static void main(String[] args) throws IOException {  
        Endpoint.publish("http://localhost:80/fake/ws", new WebServiceHolder());  
        System.in.read();  
    }  
}  
View Code

 

调用接口代码:

package myws;  
  
import java.net.MalformedURLException;  
import java.net.URL;  
  
import javax.xml.namespace.QName;  
import javax.xml.ws.Service;  
  
/** 
 * 
 * @author 帐前卒 
 * 
 */  
public class Client {  
    public static void main(String[] args) throws MalformedURLException {  
        WebServiceAPI api = Service.create(  
                new URL("http://localhost:80/fake/ws?wsdl"),  
                new QName("http://chillyc.info/api", "API"))  
                .getPort(WebServiceAPI.class);  
        System.out.println(api.hello("sss"));  
    }  
}  
View Code

 

wsdl内容:

This XML file does not appear to have any style information associated with it. The document tree is shown below.  
<!-- 
 Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6.  
-->  
<!-- 
 Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6.  
-->  
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://chillyc.info/api" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://chillyc.info/api" name="API">  
<types>  
<xsd:schema>  
<xsd:import namespace="http://chillyc.info/api" schemaLocation="http://localhost/fake/ws?xsd=1"/>  
</xsd:schema>  
</types>  
<message name="hello">  
<part name="parameters" element="tns:hello"/>  
</message>  
<message name="helloResponse">  
<part name="parameters" element="tns:helloResponse"/>  
</message>  
<message name="getReturnInfo">  
<part name="parameters" element="tns:getReturnInfo"/>  
</message>  
<message name="getReturnInfoResponse">  
<part name="parameters" element="tns:getReturnInfoResponse"/>  
</message>  
<portType name="HELLO">  
<operation name="hello">  
<input message="tns:hello"/>  
<output message="tns:helloResponse"/>  
</operation>  
<operation name="getReturnInfo">  
<input message="tns:getReturnInfo"/>  
<output message="tns:getReturnInfoResponse"/>  
</operation>  
</portType>  
<binding name="PortNameBinding" type="tns:HELLO">  
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>  
<operation name="hello">  
<soap:operation soapAction=""/>  
<input>  
<soap:body use="literal"/>  
</input>  
<output>  
<soap:body use="literal"/>  
</output>  
</operation>  
<operation name="getReturnInfo">  
<soap:operation soapAction=""/>  
<input>  
<soap:body use="literal"/>  
</input>  
<output>  
<soap:body use="literal"/>  
</output>  
</operation>  
</binding>  
<service name="API">  
<port name="PortName" binding="tns:PortNameBinding">  
<soap:address location="http://localhost/fake/ws"/>  
</port>  
</service>  
</definitions>  
View Code

 

posted @ 2016-06-02 09:51  七夏之  阅读(307)  评论(0编辑  收藏  举报