从JavaScript调用JAX-WS Web服务时的空参数 [英] Null parameters when calling a JAX-WS Web Service from JavaScript

查看:168
本文介绍了从JavaScript调用JAX-WS Web服务时的空参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JAX-WS Web服务,它可以从任何客户端(即Java destkop应用程序)调用,但不能从JavaScript调用。

I have a JAX-WS web service that is working fine when it gets called from any clients (i.e. Java destkop application) but not from JavaScript.

My WS界面如下所示:

My WS interface looks like this:

@WebService
public interface LicenseService {

    @WebMethod
    String getLicense(
            @WebParam(name="coupon") String coupon,
            @WebParam(name="licenseCode") String licenseCode,
            @WebParam(name="secret") String secret);
    }

我从这样的javascript中调用它:

and I call it from javascript like this:

var request = new XMLHttpRequest();
request.open("POST", url, false);

request.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
request.send(envelope);

和发送的信封如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <getLicense xmlns="http://ws.licenseman.elevelcbt.eu/">
            <coupon>SYcj1J9I</coupon>
            <licenseCode>BEPRO</licenseCode>
            <secret>1234567890</secret>
        </getLicense>
    </soap:Body>
</soap:Envelope>

调用该方法(我可以在Java端跟踪),但所有传递的参数都为null。我的信封格式/内容一定有问题。

The method gets called (I can track on the Java side) but all passed parameters are null. There must be something wrong on my envelope format/contents.

推荐答案

好,我知道了。
我需要更改我的信封格式,看起来像这样(我是通过在从java客户端成功调用WS时跟踪原始xml消息得到的):

Ok I got it. I needed to change my envelope format to look like this (I got it by tracing the raw xml message when successfully calling the WS from java client):

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header />
    <SOAP-ENV:Body>
        <ns1:getLicense xmlns:ns1="http://ws.licenseman.elevelcbt.eu/">
            <coupon>1111</coupon>
            <licenseCode>BEPRO</licenseCode>
            <secret>xxxxxxx</secret>
        </ns1:getLicense>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

似乎JAX-WS不喜欢这样的方法声明:

It seems JAX-WS doesn't like method declaration like this:

<getLicense xmlns="http://ws.licenseman.elevelcbt.eu/">

并希望如此:

<ns1:getLicense xmlns:ns1="http://ws.licenseman.elevelcbt.eu/">

这篇关于从JavaScript调用JAX-WS Web服务时的空参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆