使用SOAP与WSDL进行通信,我不知道如何正确地形成我的SOAP以与远程服务器中的WSDL交互

时间:2013-01-15 21:21:47

标签: soap wsdl axis2

我必须向使用Axis2的Web服务发出请求,我太接近它了,但我不断收到错误消息,我确信它正在构建我的SOAP XML。这是SOAP:

<?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
        <soap:Header>
            <RequestsoapHeader>
                <spId>SPID</spId>
                <spPassword>RandomPass</spPassword>
                <timeStamp>20130115160251</timeStamp>
            </RequestsoapHeader>
        </soap:Header>
        <soap:Body>
            <operation>
                <name>getSPToken</name>
                <input>http://zzz.zzz.zzz.zzz/my/redirection/url/</input>
            </operation>
        </soap:Body>
    </soap:Envelope>

UPDATE !!!!肥皂是这样的:

<?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
        <soap:Header>
            <RequestsoapHeader>
                <spId>SPID</spId>
                <spPassword>RandomPass</spPassword>
                <timeStamp>20130115160251</timeStamp>
            </RequestsoapHeader>
        </soap:Header>
        <soap:Body>
            <getSPTokenRequest>
                <SPredirectURL>http://zzz.zzz.zzz.zzz/my/redirection/url/</SPredirectURL>
            </getSPTokenRequest>
        </soap:Body>
    </soap:Envelope>

我无法修复的部分是Body,我试图以不同的方式调用该操作,例如我使用<operation>代替<operation name="getSPToken">,我也尝试不使用操作并创建了标记为<getSPToken>的标记,但没有任何作用。

这是描述我试图在Web服务中调用的操作的WSDL部分:

    <wsdl:operation name="getSPToken">
        <soap:operation soapAction="" style="document"/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal"/>
        </wsdl:output>
        <wsdl:fault name="ServiceException">
            <soap:fault name="ServiceException" use="literal"/>
        </wsdl:fault>
        <wsdl:fault name="PolicyException">
            <soap:fault name="PolicyException" use="literal"/>
        </wsdl:fault>
    </wsdl:operation>

UPDATE !!!这是我之前未发布的接口XML(WSDL的一部分):

<wsdl:types>
    <xsd:schema elementFormDefault="qualified" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
        targetNamespace="http://www.csapi.org/schema/parlayx/sicoweb/v1_0/local">
        <xsd:element name="getSPTokenRequest" type="osg_sicoweb_local_xsd:getSPTokenRequest"/>
        <xsd:complexType name="getSPTokenRequest">
            <xsd:sequence>
                <xsd:element name="SPredirectURL"
                    type="xsd:string" maxOccurs="1" minOccurs="1">
                    <xsd:annotation>
                        <xsd:documentation></xsd:documentation>
                    </xsd:annotation>
                </xsd:element>
            </xsd:sequence>
        </xsd:complexType>

        <xsd:element name="getSPTokenResponse" type="osg_sicoweb_local_xsd:getSPTokenResponse"/>
        <xsd:complexType name="getSPTokenResponse">
            <xsd:sequence>
                <xsd:element name="SPToken" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:schema>
</wsdl:types>

这是我得到的回应:

HTTP/1.1 500 Internal Server Error
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=UTF-8
Date: Tue, 15 Jan 2013 21:10:49 GMT
Connection: close
<?xml version='1.0' encoding='UTF-8'?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Body>
            <soapenv:Fault xmlns:axis2ns73="http://schemas.xmlsoap.org/soap/envelope/">
                <faultcode>axis2ns73:Client</faultcode>
                <faultstring>The endpoint reference (EPR) for the Operation not found is http://xxx.xxx.xxx.xxx:xxx/path/to/service/ and the WSA Action = </faultstring>
                <detail />
            </soapenv:Fault>
        </soapenv:Body>
    </soapenv:Envelope>

UPDATE !!!!随着新的变化,我得到的回应就是这个:

<?xml version='1.0' encoding='UTF-8'?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Body>
            <soapenv:Fault>
                <faultcode>soapenv:Server</faultcode>
                <faultstring>org.apache.axis2.databinding.ADBException: Unexpected subelement getSPTokenRequest</faultstring>
                <detail />
            </soapenv:Fault>
        </soapenv:Body>
    </soapenv:Envelope>

操作getSPToken收到一个名为SPredirectURL的参数,其中包含重定向的网址,请提供帮助。

1 个答案:

答案 0 :(得分:1)

尝试以下其中一项作为您的身体:

<soap:Body>
  <SPredirectURL>http://zzz.zzz.zzz.zzz/my/redirection/url/</SPredirectURL>
</soap:Body>

<soap:Body>
  <getSPTokenRequest xmlns="http://www.csapi.org/schema/parlayx/sicoweb/v1_0/local">
    <SPredirectURL>http://zzz.zzz.zzz.zzz/my/redirection/url/</SPredirectURL>
  </getSPTokenRequest>
</soap:Body>

基于WSDL片段,Web服务端点正在使用文档/文字约定来获取消息,但是没有WSDL消息声明,不清楚是“裸”(第一个示例)还是“包装”(第二个示例)版本是期待。此地址的帖子(http://www.ibm.com/developerworks/webservices/library/ws-whichwsdl/)可以很好地了解WSDL描述的各种方言。

更新: 根据wsdl:types部分中的模式,服务所期望的元素的完全限定名称(基于schema元素的声明的targetNamespace属性)是http://www.csapi.org/schema/parlayx/sicoweb/v1_0/local {getSPTokenRequest}

建立该名称(内联名称空间声明)的一种方法显示在上面更新的第二个主体中。

回复下一次迭代。