“失踪”使用 Suds 时的方法属性

发布于 2025-01-07 13:10:36 字数 2588 浏览 1 评论 0原文

我正在使用 Suds 开发 Soap 客户端,但遇到了问题。我创建客户端并打印它以了解可用的方法:

    wsdl_url='http://ws04.iula.upf.edu/soaplab2-axis/typed/services/tokenization.freeling_tokenizer?wsdl'
    FL_ws=Client(wsdl_url)
    print FL_ws

我的输出是(我删除了一些部分以方便阅读):

   Ports (1):
  (freeling_tokenizerPort)
     Methods (11):
        clear(ns2:jobId jobId, )
        describe()
        getLastEvent(ns2:jobId jobId, )
        getResults(ns2:jobId jobId, )
        run(ns1:language language, )
        runAndWaitFor(ns1:language language, )
     Types (22):
        ns1:RunAndWaitFor
        ns1:appInputs
        ns1:appResults
        ns2:describeRequest
        ns2:jobId

请注意,有许多方法缺少属性,例如: runAndWaitFor(ns1:语言语言,)。根据 WISDL,这个缺失的属性是一个文本,可以作为直接数据或 url 给出:

<xs:complexType name="appInputs">
 <xs:sequence>
  <xs:choice id="input">
   <xs:element name="input_direct_data" type="xs:string"/>
   <xs:element name="input_url" type="xs:string"/>
  </xs:choice>
  <xs:element name="language">
   <xs:simpleType>
    <xs:restriction base="xs:string">
     <xs:enumeration value="en"/>
     <xs:enumeration value="es"/>
    </xs:restriction>
   </xs:simpleType>
  </xs:element>
 </xs:sequence>
</xs:complexType>

然后,我不知道如何调用这个方法。在 Perl 中,它可以很好地定义和输入结构,如下所示:

# Inputs structure
my $inputs = {
    input_direct_data => "$input_direct_data",
    language => "$language"
};

所以我尝试了以下操作:

    input = FL_ws.factory.create('ns1:appInputs')
    input['input_direct_data']='The house is red.'
    input['language']='en'
    result=FL_ws.service.runAndWaitFor(input)
    print result

但是 Suds 生成的 xml 不正确:

<ns1:Body>
  <ns0:runAndWaitFor>
     <language>
        <input_direct_data>The house is red.</input_direct_data>
        <language>en</language>
     </language>
  </ns0:runAndWaitFor>
</ns1:Body>

因为它将 input_direct_data 放在 下。我发现 这篇 帖子也有类似的 XML 问题,但他们的解决方案不适用于我。在我看来,我的问题与 Suds 如何处理选择输入有关,因为它似乎不接受 input_direct_data 作为参数。

我得到的错误总是:

suds.WebFault: Server raised fault: 'Soaplab not able to process the input request: '

所以看来输入没有正确到达服务...

任何关于如何解决这个问题的想法,或者我如何弄清楚 Suds 期望这个输入如何,将非常有帮助。

非常感谢您的帮助。

I am developing a Soap client with Suds, and I have a problem. I create the client and just print it to know the available methods:

    wsdl_url='http://ws04.iula.upf.edu/soaplab2-axis/typed/services/tokenization.freeling_tokenizer?wsdl'
    FL_ws=Client(wsdl_url)
    print FL_ws

And my output is (I deleted some parts to ease reading):

   Ports (1):
  (freeling_tokenizerPort)
     Methods (11):
        clear(ns2:jobId jobId, )
        describe()
        getLastEvent(ns2:jobId jobId, )
        getResults(ns2:jobId jobId, )
        run(ns1:language language, )
        runAndWaitFor(ns1:language language, )
     Types (22):
        ns1:RunAndWaitFor
        ns1:appInputs
        ns1:appResults
        ns2:describeRequest
        ns2:jobId

Note that there are many methods that have a missing attribute ate the end, for example: runAndWaitFor(ns1:language language, ). According to the WISDL, this missing attribute is a text, that may be given as direct data or as url:

<xs:complexType name="appInputs">
 <xs:sequence>
  <xs:choice id="input">
   <xs:element name="input_direct_data" type="xs:string"/>
   <xs:element name="input_url" type="xs:string"/>
  </xs:choice>
  <xs:element name="language">
   <xs:simpleType>
    <xs:restriction base="xs:string">
     <xs:enumeration value="en"/>
     <xs:enumeration value="es"/>
    </xs:restriction>
   </xs:simpleType>
  </xs:element>
 </xs:sequence>
</xs:complexType>

Then, I am not sure how to call this method. In Perl, it works fine defining and input structure like this:

# Inputs structure
my $inputs = {
    input_direct_data => "$input_direct_data",
    language => "$language"
};

So I tried the following:

    input = FL_ws.factory.create('ns1:appInputs')
    input['input_direct_data']='The house is red.'
    input['language']='en'
    result=FL_ws.service.runAndWaitFor(input)
    print result

But the xml generated by Suds is incorrect:

<ns1:Body>
  <ns0:runAndWaitFor>
     <language>
        <input_direct_data>The house is red.</input_direct_data>
        <language>en</language>
     </language>
  </ns0:runAndWaitFor>
</ns1:Body>

Since it puts input_direct_data under <language>. I found this post with a similar problem with XML, but their solution does not work for me. It seems to me that my problem is related to how Suds deals with the choice input, since it does not seem to accept input_direct_data as a parameter.

The error I got is always:

suds.WebFault: Server raised fault: 'Soaplab not able to process the input request: '

So it seems that the input is not reaching correctly the service...

Any ideas about how to solve this, or how can I figure out how Suds expect this input to be, will be very helpful.

Thank you very much for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南风几经秋 2025-01-14 13:10:36

我找到了一个解决方案:

我正在使用 "typed" wisdl 创建客户端,但是,由于某种原因 Suds 无法从中正确获取参数。然后,我了解到还有另一个 “非类型化” wisdl 可用于相同的服务。使用它来创建 Suds 客户端,它能够正确获取方法的复杂参数,并且我成功地构建了客户端。

我尝试访问的服务是使用 SoapLab 创建的。首先,我认为不同 WISDL 的问题与 SoapLab 创建它们的方式有关,但我不是 SoapLab 的专家,只是这些服务的用户,所以我真的不知道发生了什么......另一方面,我能够使用第一个 wisdl 创建一个 perl 客户端,所以也许这是 Suds 的问题。

I have found a solution:

I was using the "typed" wisdl to create the Client, but, for some reason Suds is not able to get the parameters correctly from it. Then, I learnt that there was another "non-typed" wisdl available for the same service. Using it to create the Suds client, it is able to correctly get the complex parameters for the methods and I succesfully built the client.

The services I am trying to acces have been created with SoapLab. First I though that this issue with different WISDLs was related to how SoapLab creates them, but I am not an expert in SoapLab, only a user of these services, so I really don't know what's going on... On the other hand, I was able to create a perl client using the first wisdl, so maybe it is a problem with Suds.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文