概述
本人这两天在学WebService.按照教学视频里的教程尝试做了一个最简单的Demo,但出现了一下问题。百思不得其解,在网上找了很久也没有找到答案。故此在这里发帖求各位大神指点下。
下面是问题描述:
照理说能访问到wsdl文件就说明web Service 已发布出去了,定义的接口也能调用,SOAP Request Envelope和SOAP Response Envelope应该是.xml格式的内容。但这里只有参数值跟返回结果。这是为何?求知道的大神指点下。
还有其他的错误信息,请看:
在浏览器上访问 http://localhost:8080/WebServiceDemo/services/HelloWorldImplPort 得到以下内容:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>
No binding operation info while invoking unknown method with params unknown.
</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
此时,控制台错误信息:
三月 14, 2014 4:02:17 下午 org.apache.cxf.services.HelloWorldImplService.HelloWorldImplPort.HelloWorld
信息: Inbound Message
----------------------------
ID: 4
Address: http://localhost:8080/WebServiceDemo/services/HelloWorldImplPort
Http-Method: GET
Content-Type:
Headers: {Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8], accept-encoding=[gzip,deflate,sdch], accept-language=[zh-CN,zh;q=0.8], cache-control=[max-age=0], connection=[keep-alive], Content-Type=[null], host=[localhost:8080], user-agent=[Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36]}
--------------------------------------
三月 14, 2014 4:02:17 下午 org.apache.cxf.service.invoker.AbstractInvoker invoke
严重: Invocation without a binding operation.
三月 14, 2014 4:02:17 下午 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
警告: Interceptor for {http://com.shaobin.ji/}HelloWorldImplService has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: No binding operation info while invoking unknown method with params unknown.
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:59)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:107)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153)
at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:167)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:286)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:211)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:262)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
三月 14, 2014 4:02:17 下午 org.apache.cxf.services.HelloWorldImplService.HelloWorldImplPort.HelloWorld
信息: Outbound Message
---------------------------
ID: 4
Response-Code: 500
Encoding: UTF-8
Content-Type: text/xml
Headers: {}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>No binding operation info while invoking unknown method with params unknown.</faultstring></soap:Fault></soap:Body></soap:Envelope>
--------------------------------------
源码如下:
接口:HelloWorld.java
package ji.shaobin.com;
import javax.jws.WebMethod;
@WebService(name = "HelloWorld", targetNamespace = "http://com.shaobin.ji/")
public interface HelloWorld {
@WebMethod(operationName = "sayHello", action = "urn:SayHello")
@RequestWrapper(className = "ji.shaobin.com.jaxws.SayHello", localName = "sayHello", targetNamespace = "http://com.shaobin.ji/")
@ResponseWrapper(className = "ji.shaobin.com.jaxws.SayHelloResponse", localName = "sayHelloResponse", targetNamespace = "http://com.shaobin.ji/")
@WebResult(name = "return")
String sayHello();
@WebMethod(operationName = "sayHi", action = "urn:SayHi")
@RequestWrapper(className = "ji.shaobin.com.jaxws.SayHi", localName = "sayHi", targetNamespace = "http://com.shaobin.ji/")
@ResponseWrapper(className = "ji.shaobin.com.jaxws.SayHiResponse", localName = "sayHiResponse", targetNamespace = "http://com.shaobin.ji/")
@WebResult(name = "return")
String sayHi(@WebParam(name = "arg0") String name);
}
接口实现类:HelloWorldImpl.java
package ji.shaobin.com;
import javax.jws.WebService;
@WebService(targetNamespace = "http://com.shaobin.ji/",
endpointInterface = "ji.shaobin.com.HelloWorld",
portName = "HelloWorldImplPort",
serviceName = "HelloWorldImplService")
public class HelloWorldImpl implements HelloWorld {
public String sayHello() {
return "hello";
}
@Override
public String sayHi(String name) {
return "Hi,"+name;
}
}
测试类:TestClient.java
package ji.shaobin.com;
import java.net.MalformedURLException;
public class TestClient {
public static void main(String[] args){
try {
URL url=new URL("http://localhost:8080/WebServiceDemo/services/HelloWorldImplPort?wsdl");
QName sname=new QName("http://com.shaobin.ji/","HelloWorldImplService");
Service service=Service.create(url, sname);
HelloWorld hell=service.getPort(HelloWorld.class);
System.out.println(hell.sayHello());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
wsdl文件:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="HelloWorldImplService" targetNamespace="http://com.shaobin.ji/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://com.shaobin.ji/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://com.shaobin.ji/" schemaLocation="helloworld_schema1.xsd"/>
</schema>
</wsdl:types>
<wsdl:message name="sayHi">
<wsdl:part name="parameters" element="tns:sayHi">
</wsdl:part>
</wsdl:message>
<wsdl:message name="sayHello">
<wsdl:part name="parameters" element="tns:sayHello">
</wsdl:part>
</wsdl:message>
<wsdl:message name="sayHelloResponse">
<wsdl:part name="parameters" element="tns:sayHelloResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="sayHiResponse">
<wsdl:part name="parameters" element="tns:sayHiResponse">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="HelloWorld">
<wsdl:operation name="sayHi">
<wsdl:input name="sayHi" message="tns:sayHi">
</wsdl:input>
<wsdl:output name="sayHiResponse" message="tns:sayHiResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayHello">
<wsdl:input name="sayHello" message="tns:sayHello">
</wsdl:input>
<wsdl:output name="sayHelloResponse" message="tns:sayHelloResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloWorldImplServiceSoapBinding" type="tns:HelloWorld">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sayHello">
<soap:operation soapAction="urn:SayHello" style="document"/>
<wsdl:input name="sayHello">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHelloResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayHi">
<soap:operation soapAction="urn:SayHi" style="document"/>
<wsdl:input name="sayHi">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHiResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWorldImplService">
<wsdl:port name="HelloWorldImplPort" binding="tns:HelloWorldImplServiceSoapBinding">
<soap:address location="http://localhost:8080/WebServiceDemo/services/HelloWorldImplPort"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
还有一些由cxf自动生成的代码就不贴出来了。
求大神们指点。这几天都会关注这个贴的,一旦能解决问题就马上结贴。谢谢
最后
以上就是和谐柜子为你收集整理的WebService 问题求指点的全部内容,希望文章能够帮你解决WebService 问题求指点所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复