在Worklight HTTP Adapter中使用参数时出错 [英] Error when using Parameters in Worklight HTTP Adapter

查看:140
本文介绍了在Worklight HTTP Adapter中使用参数时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Worklight 6.2.0.0。

Using Worklight 6.2.0.0.

我正在尝试通过Worklight的HTTP适配器使用我们的企业Web服务之一。我有Web服务的WSDL,我使用发现后端服务工具生成适配器JavaScript和XML。

I'm trying to consume one of our corporate web services via Worklight's HTTP Adapter. I have the WSDL for the web service, and I used the "Discover Backend Services" tool to generate the adapter JavaScript and XML.

Web服务有2个输入参数和3个输出参数,所有字符串。

The web service has 2 input parameters and 3 output parameters, all strings.

当我来调用客户端上的程序时,我这样做:

When I come to invoke the procedure on the client, I'm doing this:

    var invocationData = {
        adapter : 'messageHandlerAdapter',
        procedure : 'messageHandlerService_messageHandler',
        parameters : ['a','b']
};

var invocationOptions = {
        onSuccess : messageHandlerSuccess,
        onFailure : messageHandlerFailure   
};  

WL.Client.invokeProcedure(invocationData,invocationOptions);

您可以在invocationData数组中看到虚拟参数。运行此会导致以下错误:

You can see the dummy parameters in the invocationData array. Running this results in the following error:


java.lang.String无法强制转换为org.mozilla.javascript.Scriptable

java.lang.String cannot be cast to org.mozilla.javascript.Scriptable

如果删除参数,我没有收到错误,Web服务调用似乎成功,但我没有得到任何回复(很明显)。

If I remove the parameters, I don't get an error and the web service call appears to be successful, but I don't get any response (obviously).

在论坛上搜索引导我:

http://stackoverflow.com/questions/23192346/class-cast-java-lang-string-不能被强制转换为org-mozilla-javascript-scriptable
这是相同的,反应是某处可能存在无效的JSON对象。但是,我所做的就是使用自动生成的适配器代码并调用它。

http://stackoverflow.com/questions/23192346/class-cast-java-lang-string-cannot-be-cast-to-org-mozilla-javascript-scriptable Which is along the same lines, and the response was that there might be an invalid JSON object somewhere. However, all I've done is used the auto-generated adapter code and called it.

我是Worklight的新手,所以感谢任何建议!

I'm very new to Worklight, so any advice is gratefully received!

WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="messageHandler" targetNamespace="urn:messageHandler" xmlns:tns="urn:messageHandler" xmlns:S2="urn:messageHandler:messageHandler" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:S1="urn:soap-fault:details" xmlns="http://schemas.xmlsoap.org/wsdl/">
<wsdl:documentation>EncodingType=DOC_LITERAL, WSA_Product=10.1A - N/A</wsdl:documentation>
  <wsdl:types>
<schema elementFormDefault="unqualified" targetNamespace="urn:soap-fault:details" xmlns="http://www.w3.org/2001/XMLSchema"><element name="FaultDetail"><complexType><sequence><element name="errorMessage" type="xsd:string"/><element name="requestID" type="xsd:string"/></sequence></complexType></element></schema>
<schema elementFormDefault="qualified" targetNamespace="urn:messageHandler:messageHandler" xmlns="http://www.w3.org/2001/XMLSchema"><element name="messageHandler"><complexType><sequence><element name="ipMessageParams" nillable="true" type="xsd:string"/><element name="ipMessageData" nillable="true" type="xsd:string"/></sequence></complexType></element><element name="messageHandlerResponse"><complexType><sequence><element name="result" nillable="true" type="xsd:string"/><element name="opMessageResponse" nillable="true" type="xsd:string"/><element name="opMessageData" nillable="true" type="xsd:string"/></sequence></complexType></element></schema>
  </wsdl:types>
  <wsdl:message name="messageHandler_messageHandlerResponse">
    <wsdl:part name="parameters" element="S2:messageHandlerResponse"/>
  </wsdl:message>
  <wsdl:message name="FaultDetailMessage">
    <wsdl:part name="FaultDetail" element="S1:FaultDetail"/>
  </wsdl:message>
  <wsdl:message name="messageHandler_messageHandler">
    <wsdl:part name="parameters" element="S2:messageHandler"/>
  </wsdl:message>
  <wsdl:portType name="messageHandlerObj">
    <wsdl:operation name="messageHandler">
      <wsdl:input message="tns:messageHandler_messageHandler"/>
      <wsdl:output message="tns:messageHandler_messageHandlerResponse"/>
      <wsdl:fault name="messageHandlerFault" message="tns:FaultDetailMessage"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="messageHandlerObj" type="tns:messageHandlerObj">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="messageHandler">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input>
    <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
    <soap:body use="literal"/>
      </wsdl:output>
      <wsdl:fault name="messageHandlerFault">
    <soap:fault name="messageHandlerFault" use="literal"/>
      </wsdl:fault>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="messageHandlerService">
    <wsdl:port name="messageHandlerObj" binding="tns:messageHandlerObj">
<documentation></documentation>
      <soap:address location="redacted"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

这是Project Explorer中服务描述图片的链接。

Here is a link to a pic of the Service description in Project Explorer.

推荐答案

通常我们将XML传递给基于SOAP的Web服务。对于worklight,我们必须将XML转换为JSON并将其传递给适配器。考虑您的输入SOAP就像

Generally we pass XML to SOAP based web services. With the case to worklight we have to convert XML to JSON and pass it to adapter. Considering your input SOAP is like

<a>
   <b>value1</b>
   <c>value2</c>
</a> 

您的上述XML的JSON将是

Your JSON for above XML would be

 params= {
      a:{
          b:value1,
          c:value2
        }
     }

所以你必须将JSON作为参数传递给上面

So u will have to pass above JSON as parameter

headers={
        "SOAPAction": "YOUR ACTION NAME"
    }

所以你的适配器调用看起来像这样,

And so your adapter call will look like this,

var invocationData = {
        adapter : 'messageHandlerAdapter',
        procedure : 'messageHandlerService_messageHandler',
        parameters : [params,headers]
};

var invocationOptions = {
        onSuccess : messageHandlerSuccess,
        onFailure : messageHandlerFailure   
};  

WL.Client.invokeProcedure(invocationData,invocationOptions);

这篇关于在Worklight HTTP Adapter中使用参数时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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