下面是一个使用javax.ws
. 我想获取服务 URL,可从 Web 浏览器或 curl 调用。这是玩具服务代码:
package packagename;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@WebService
@Path("/service")
public class testserver
{
@GET
@Path("/test")
@WebMethod
public String test()
{
return "<html>Test text here</html>";
}
}
这是服务部署程序功能:
package packagename;
import javax.xml.ws.Endpoint;
public class deploy
{
public static void main(String [] args)
{
String endpointURL = "http://localhost:7777/";
Endpoint.publish(endpointURL,new testserver());
}
}
我通过 bash 运行 java 文件没有错误。
不应该导航http://localhost:7777/service/test
生成 test()
函数的文本吗?我从浏览器收到未找到服务器的错误。
下面是 wsdl 文件http://localhost:7777/?wsdl
。我正在寻找的信息在这里吗?我通过从下面(testserverService 等)获取信息尝试了一些 url,但没有成功。
<!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e.
-->
<!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e.
-->
<definitions targetNamespace="http://packagename/" name="testserverService">
<types>
<xsd:schema>
<xsd:import namespace="http://packagename/" schemaLocation="http://localhost:7777/?xsd=1"/>
</xsd:schema>
</types>
<message name="test">
<part name="parameters" element="tns:test"/>
</message>
<message name="testResponse">
<part name="parameters" element="tns:testResponse"/>
</message>
<portType name="testserver">
<operation name="test">
<input wsam:Action="http://packagename/testserver/testRequest" message="tns:test"/>
<output wsam:Action="http://packagename/testserver/testResponse" message="tns:testResponse"/>
</operation>
</portType>
<binding name="testserverPortBinding" type="tns:testserver">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="test">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="testserverService">
<port name="testserverPort" binding="tns:testserverPortBinding">
<soap:address location="http://localhost:7777/"/>
</port>
</service>
</definitions>
我猜答案很简单,或者我的代码中出现了严重的语法错误。你能帮我吗 ?