繁体   English   中英

响应中包含非预期的text / html ContentType

[英]Response was of unexpected text/html ContentType

我创建了一个WebService实现,并使用Java2ws创建了客户端和服务器。

服务器实施接口:

@WebService(name = "McKreuzfahrtService", targetNamespace = "http://service.mc/")
public interface McKreuzfahrtService {
    @WebMethod(operationName = "getKreuzfahrten", action = "urn:GetKreuzfahrten")
    public String  getKreuzfahrten(@WebParam(name = "AbfahrtHafen") String abfahrthafen,
            @WebParam(name = "FahrtDatum") int fahrtDatum);

实现方式:

@WebService(targetNamespace = "http://service.mc/", endpointInterface = "mc.service.McKreuzfahrtService", portName = "McKreuzfahrtServiceImpPort", serviceName = "McKreuzfahrtServiceImpService")

public class McKreuzfahrtServiceImp implements McKreuzfahrtService {

    private ArrayList<McKreuzFahrt> kreuzFahrten = new ArrayList<McKreuzFahrt>();

    public McKreuzfahrtServiceImp() {
        createKreuzfahrten();

    }

    private void createKreuzfahrten() {
        kreuzFahrten.add(new McKreuzFahrt("Norway Cruises", "Hamburg", "Flaam", 216, 3000));
        kreuzFahrten.add(new McKreuzFahrt("Nordeuropa", "Hamburg", "Dublin", 216, 1050));

    }



    @Override
        public String getKreuzfahrten(String abfahrthafen, int fahrtDatum) {
            String msg = "";
            for (McKreuzFahrt mkf : kreuzFahrten) {

                if (mkf.getFahrtDatum() == fahrtDatum && (mkf.getAbfahrthafen().equals(abfahrthafen))) {
                    /*System.out.println(mkf.getAbfahrthafen());*/
                    msg = "ok";
                }else 
                    msg = "nein";


            }
            return msg;

        }
    }

客户端启动并发出调用消息。 但是,如果我调用我的方法,则会出现以下错误:org.apache.cxf.interceptor.Fault:响应是意外的text / html ContentType。 这个原因的起因是什么? WSDL等。

客户:

public final class McKreuzfahrtService_McKreuzfahrtServiceImpPort_Client {

    private static final QName SERVICE_NAME = new QName("http://service.mc/", "McKreuzfahrtServiceImpService");

    private McKreuzfahrtService_McKreuzfahrtServiceImpPort_Client() {
    }

    public static void main(String args[]) throws java.lang.Exception {
        URL wsdlURL = McKreuzfahrtServiceImpService.WSDL_LOCATION;
        if (args.length > 0 && args[0] != null && !"".equals(args[0])) {
            File wsdlFile = new File(args[0]);
            try {
                if (wsdlFile.exists()) {
                    wsdlURL = wsdlFile.toURI().toURL();
                } else {
                    wsdlURL = new URL(args[0]);
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }

        McKreuzfahrtServiceImpService ss = new McKreuzfahrtServiceImpService(wsdlURL, SERVICE_NAME);
        McKreuzfahrtService port = ss.getMcKreuzfahrtServiceImpPort();

        {
        System.out.println("Invoking getKreuzfahrten...");

        port.getKreuzfahrten("Hamburg", 216);

        }

        System.exit(0);
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM