Axis2的始终接收空参数,即使SOAP请求被正确发送? [英] Axis2 always receives null parameters even if SOAP request is sent correctly?

查看:1748
本文介绍了Axis2的始终接收空参数,即使SOAP请求被正确发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:我已经解决了这个问题,现在 - 请滚动到底以获取有关FIX

我有一个Web服务用Java编写,主持一个Axis2 / Tomcat的/ Apache服务器上。我的客户端软件是用C#。

I have a web-service written in Java, hosted on an Axis2 / Tomcat / Apache server. My client software is written in C#.

我曾与方式的Java2WS​​DL一些刺激性的问题时生成WSDL文件,这也引起了我几个头痛早期,但这个问题我彻底难倒。

I have had a few irritating problems with the way java2wsdl generates the wsdl file, which did cause me a few headaches early on, but with this problem I am completely stumped.

基本上正在发生的事情是,客户端看到的Web服务的罚款,并发送一个完全有效的(或至少,它看起来有效对我来说)与参数的SOAP请求。

Basically what is happening is that the client sees the web service fine, and sends a perfectly valid (or at least, it looks valid to me) SOAP request with parameters.

在服务器上,执行正确的Web方法,但参数均为空。我的web服务检测到这一点,并建立了一个响应,客户端接收并理解得很清楚。

On the server, the correct web method is executed, but the parameters are all null. My web service detects this and builds up a response, which the client receives and understands perfectly well.

我的直觉是,Axis2的是它跌得鼻青脸肿的地方,但由于,头痛我曾与的Java2WS​​DL,也许我需要的是在我的WSDL文件中的变化

My hunch is that Axis2 is falling flat on its face somewhere, but given the headaches I have had with java2wsdl, perhaps all I need is a change in my wsdl file.

下面是WSDL文件:

    <?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:axis2="http://stws/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns0="http://stws/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://stws/">
    <wsdl:types>
        <xs:schema xmlns:ns="http://stws/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://stws/xsd">
            <xs:element name="GetGroups">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="GetGroupsResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ns0:Group"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:complexType name="Group">
                <xs:sequence>
                    <xs:element minOccurs="0" name="ID" type="xs:int"/>
                    <xs:element minOccurs="0" name="Name" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
            <xs:element name="GetMessages">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="groupids" type="xs:int"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="GetMessagesResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ns0:Message"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:complexType name="Message">
                <xs:sequence>
                    <xs:element minOccurs="0" name="date" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="group" type="xs:int"/>
                    <xs:element minOccurs="0" name="messageID" type="xs:int"/>
                    <xs:element minOccurs="0" name="text" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="GetMessagesRequest">
        <wsdl:part name="parameters" element="ns0:GetMessages"/>
    </wsdl:message>
    <wsdl:message name="GetMessagesResponse">
        <wsdl:part name="parameters" element="ns0:GetMessagesResponse"/>
    </wsdl:message>
    <wsdl:message name="GetGroupsRequest">
        <wsdl:part name="parameters" element="ns0:GetGroups"/>
    </wsdl:message>
    <wsdl:message name="GetGroupsResponse">
        <wsdl:part name="parameters" element="ns0:GetGroupsResponse"/>
    </wsdl:message>
    <wsdl:portType name="MyProjectPortType">
        <wsdl:operation name="GetMessages">
            <wsdl:input message="axis2:GetMessagesRequest" wsaw:Action="urn:GetMessages"/>
            <wsdl:output message="axis2:GetMessagesResponse" wsaw:Action="urn:GetMessagesResponse"/>
        </wsdl:operation>
        <wsdl:operation name="GetGroups">
            <wsdl:input message="axis2:GetGroupsRequest" wsaw:Action="urn:GetGroups"/>
            <wsdl:output message="axis2:GetGroupsResponse" wsaw:Action="urn:GetGroupsResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="MyProjectSOAP11Binding" type="axis2:MyProjectPortType">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="GetMessages">
            <soap:operation soapAction="urn:GetMessages" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="GetGroups">
            <soap:operation soapAction="urn:GetGroups" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="MyProjectSOAP12Binding" type="axis2:MyProjectPortType">
        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="GetMessages">
            <soap12:operation soapAction="urn:GetMessages" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="GetGroups">
            <soap12:operation soapAction="urn:GetGroups" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="MyProjectHttpBinding" type="axis2:MyProjectPortType">
        <http:binding verb="POST"/>
        <wsdl:operation name="GetMessages">
            <http:operation location="MyProject/GetMessages"/>
            <wsdl:input>
                <mime:content type="text/xml" part="GetMessages"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="GetMessages"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="GetGroups">
            <http:operation location="MyProject/GetGroups"/>
            <wsdl:input>
                <mime:content type="text/xml" part="GetGroups"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="GetGroups"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="MyProject">
        <wsdl:port name="MyProjectSOAP11port_http" binding="axis2:MyProjectSOAP11Binding">
            <soap:address location="http://localhost:8080/axis2/services/MyProject"/>
        </wsdl:port>
        <wsdl:port name="MyProjectSOAP12port_http" binding="axis2:MyProjectSOAP12Binding">
            <soap12:address location="http://localhost:8080/axis2/services/MyProject"/>
        </wsdl:port>
        <wsdl:port name="MyProjectHttpport" binding="axis2:MyProjectHttpBinding">
            <http:address location="http://localhost:8080/axis2/services/MyProject"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>



这里是一个样本请求和响应:

And here is a sample request and response:

请求:

<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soap:Body>
    <GetGroups xmlns="http://stws/xsd">
      <serialcode>123456-654321</serialcode>
    </GetGroups>
  </soap:Body>
</soap:Envelope>



响应

Response

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <GetGroupsResponse xmlns="http://stws/xsd">
      <return>
        <ID>-101</ID>
        <name>ERROR: Empty Serial</name>
      </return>
    </GetGroupsResponse>
  </soapenv:Body>
</soapenv:Envelope>



没有任何人有任何想法可能是什么回事?

Does anybody have any idea what could be going wrong?

在请求中的serialcode参数为空/空只能发送应答中的错误信息,所以我猜有什么错误使用Axis2是怎么看我的参数。

The error message in the response can only be sent when the serialcode parameter in the request is empty / null, so I'm guessing there is something wrong with how Axis2 is reading my parameters.

任何帮助深表感谢。

==================== ========================================

============================================================

如何解决此问题:

这是在响应奥尔多的请求,我怎么修复这个问题的详细信息。

This is in response to Aldo's request for more information about how I fixed this problem.

我不确定为什么这个修复功能 - 也许它只是在Axis2中或某事的错误。无论哪种方式,情况因人而异,因为我不知道是否该问题是由我的设置或别的东西造成的。我可以说的是,通过执行以下操作,一切都开始工作。

I am unsure of why this fix works - perhaps it is just a bug in Axis2 or something. Either way, YMMV as I don't know whether the problem was caused by my setup or something else. All I can say is that by doing the following, everything started working.

总之,自动生成WSDL文件创建Web请求及其参数的复杂元素类型,即使是唯一的参数是简单类型,如字符串或整数。我所做的是通过和创建参数(如serialcode或日期字符串')​​正确的简单类型的变量,然后更换到复杂类型使用对简单类型的引用WSDL文件的其他地方引用。

Anyway, the auto-generated WSDL file creates complex-element types for web requests and their parameters, even when the only parameters are simple types such as strings or integers. What I did was go through and create the correct simple-type tags for parameters (such as 'serialcode' or 'date-string'), then replace the references to the complex types elsewhere in the WSDL file with references to the simple types.

下面是一个例子:

自动生成的WSDL的方法和参数

<!--Requests-->    
<wsdl:message name="RegisterClientRequest">
    <wsdl:part name="parameters" element="ns0:RegisterClient"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
    <wsdl:part name="parameters" element="ns0:GetGroups"/>
</wsdl:message>

<!--Parameters-->
<xs:element name="RegisterClient">
    <xs:complexType>
        <xs:sequence>
           <xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="GetGroups">
    <xs:complexType>
        <xs:sequence>
            <xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
 </xs:element>



基本上你应该做的是放弃自动生成的参数,并创建简单的类型。然后,修改请求标签使用类型,而不是元素,并使用新创建的简单类型。

Basically what you should do is discard the auto-generated parameters and create simple-types. You then modify the 'request' tags to use 'type' rather than 'element', and use your newly created simple-types.

修改/固定WSDL

<!--Requests-->    
<wsdl:message name="RegisterClientRequest">
    <wsdl:part name="parameters" type="ns0:SerialCode"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
    <wsdl:part name="parameters" type="ns0:SerialCode"/>
</wsdl:message>

<!--Parameters-->
<xs:simpleType name="SerialCode">
    <xs:restriction base="xs:string"/>
</xs:simpleType>



显然,这取决于你的参数其实都是。在我的情况下,他们都是标准的简单类型,如字符串和整数。如果您传递多个参数,你可能需要通过保留自动生成的元素,但在确保元素引用简单类型,而不是仅仅包括类型属性作为玩弄的xs:字符串'或东西的性质

Obviously it depends on what your parameters actually are. In my case they are all standard simple types such as strings and integers. If you are passing more than one parameter, you may need to play around by retaining the auto-generated elements but making sure that the element refers to simple types rather than just including the type attribute as 'xs:string' or something of that nature.

道歉我不能对这个更清晰,但正如我刚才所说 - 我不知道为什么这个作品

Apologies I can't be more clear on this, but as I said earlier - I don't know why this works.

最后一件事:通过删除请求标记中的元素的参考属性 - 您可以在您的Axis2日志接收解析器警告。到目前为止,这并没有引起我任何问题,但它的东西要知道如果你遇到麻烦的。

One final thing: By removing the 'element' reference attribute in the request tags - you may receive a parser warning in your Axis2 logs. So far this has not caused me any problems, but it's something to be aware of in case you run into trouble.

推荐答案

我通过我的WSDL文件将解决这一问题,并尽可能打破元素融入他们的简单类型的同行和更新相应的XML元素之间的引用。

I solved this issue by going through my WSDL file and, wherever possible, breaking down elements into their simple type counterparts and updating the references between the XML elements accordingly.

我不确定为什么这个工作,但它无论如何解决我的问题。

I am unsure why this works, but it has solved my problem anyway.

这篇关于Axis2的始终接收空参数,即使SOAP请求被正确发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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