SOAP wsdl,授权

SOAP wsdl, Authorization

我正在尝试发出 SOAP 请求,但为此我必须获得授权。如果我试图在未经授权的情况下调用函数,我会收到错误消息,没关系。 但是当我尝试这样做时,我总是会收到错误消息:Parsing Schema: can't import schema from 'http://www.w3.org/2005/05/xmlmime' 但如果我用 SoapUI 这样做,一切正常。 我发现我必须将登录名和密码作为对象参数发送,这是我的代码示例,但对我来说 return 关于 Parsing Schema: can't....

的错误
$wsdl = 'source/my.wsdl';
$client = new SoapClient($wsdl,
    array(
        'trace' => 1,
        'exception' => 0,
        'login' => 'test',
        'password' => 'test123'
    ));

我没有找到任何其他方法来做到这一点,只能使用 NuSOAP,比如 setCredentials(),但这也不起作用。


现在我尝试用 NuSOAP 做到这一点:

ini_set('display_errors', '1');
ini_set('error_reporting', E_ALL &~ (E_NOTICE | E_STRICT));
//ini_set('error_reporting', E_ALL);

require_once 'lib/nusoap.php';

$params = array(
        'ID' => '',
        'Portal' => 'test1',
        'CK' => 'test2'
    );

$wsdl = 'source/test.wsdl';
$client = new nusoap_client($wsdl, true);

$client->setCredentials('test_login', 'test_password', 'basic');

$result = $client->call('testFunction', $params);

if ($client->fault) {
    echo "<h2>Fault</h2><pre>";
    print_r($result);
    echo "</pre>";
} else {
    $error = $client->getError();
    if ($error) {
        echo "<h2>Error</h2><pre>" . $error . "</pre>";
    } else {
        echo "<h2>Main</h2>";
        echo $result;
    }
}

echo "<h2>Request</h2>";
echo "<pre>" . htmlspecialchars($client->request, ENT_QUOTES) . "</pre>";
echo "<h2>Response</h2>";
echo "<pre>" . htmlspecialchars($client->response, ENT_QUOTES) . "</pre>";

print_r($client->response);

遇到同样的问题wsdl error: Getting http://www.w3.org/2005/05/xmlmime - HTTP ERROR: Unsupported HTTP response status 307 Temporary Redirect (soapclient->response has contents of the response) 如果我删除字符串 $client->setCredentials('test_login', 'test_password', 'basic'); 我会收到有关 Not Authorized 的错误消息。 http://www.w3.org/2005/05/xmlmime 有什么问题。这是我尝试调用测试函数的第三天,但总是出现该错误。我不知道我还能尝试做什么。 从 NuSOAP 一切正常,基本身份验证,所有请求,响应,都很好。


WSDL 内容:

<definitions targetNamespace="http://**.**.com/SM/7" xsi:schemaLocation="http://schemas.xmlsoap.org/wsdl/ http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:cmn="http://**.**.com/SM/7/Common" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:ns="http://**.**.com/SM/7" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <types>
        <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://**.**.com/SM/7" version="2014-10-02 Rev 1" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://**.**.com/SM/7" xmlns:xmime="http://www.w3.org/2005/05/xmlmime">
            <xs:import namespace="http://www.w3.org/2005/05/xmlmime" schemaLocation="http://www.w3.org/2005/05/xmlmime"/>
            <xs:import namespace="http://**.**.com/SM/7/Common" schemaLocation="http://***.**.**.**:8090/1/SM/7/Common.xsd"/>
            <xs:complexType name="HPSMInteractionsFromMosRuKeysType">
                <xs:sequence>
                    <xs:element minOccurs="0" name="ID" nillable="true" type="cmn:StringType"/>
                </xs:sequence>
                <xs:attribute name="query" type="xs:string" use="optional"/>
                <xs:attribute name="updatecounter" type="xs:long" use="optional"/>
            </xs:complexType>
            <xs:complexType name="HPSMInteractionsFromMosRuInstanceType">
                <xs:sequence>
                    <xs:element minOccurs="0" name="ID" nillable="true" type="cmn:StringType"/>
                    <xs:element minOccurs="0" name="Description">
                        <xs:complexType>
                            <xs:complexContent>
                                <xs:extension base="cmn:ArrayType">
                                    <xs:sequence>
                                        <xs:element maxOccurs="unbounded" minOccurs="0" name="Description" type="cmn:StringType"/>
                                    </xs:sequence>
                                </xs:extension>
                            </xs:complexContent>
                        </xs:complexType>
                    </xs:element>
                    <xs:element minOccurs="0" name="Resolution">
                        <xs:complexType>
                            <xs:complexContent>
                                <xs:extension base="cmn:ArrayType">
                                    <xs:sequence>
                                        <xs:element maxOccurs="unbounded" minOccurs="0" name="Resolution" type="cmn:StringType"/>
                                    </xs:sequence>
                                </xs:extension>
                            </xs:complexContent>
                        </xs:complexType>
                    </xs:element>
                    <xs:element minOccurs="0" name="ResolutionCode" nillable="true" type="cmn:StringType"/>
                    <xs:element minOccurs="0" name="Email" nillable="true" type="cmn:StringType"/>
                    <xs:element minOccurs="0" name="User" nillable="true" type="cmn:StringType"/>
                    <xs:element minOccurs="0" name="Title" nillable="true" type="cmn:StringType"/>
                    <xs:element minOccurs="0" name="Status" nillable="true" type="cmn:StringType"/>
                    <xs:element minOccurs="0" name="Rating" nillable="true" type="cmn:StringType"/>
                    <xs:element minOccurs="0" name="ProblemType" nillable="true" type="cmn:StringType"/>
                    <xs:element minOccurs="0" name="Deadline" nillable="true" type="cmn:DateTimeType"/>
                    <xs:element minOccurs="0" name="Feedback">
                        <xs:complexType>
                            <xs:complexContent>
                                <xs:extension base="cmn:ArrayType">
                                    <xs:sequence>
                                        <xs:element maxOccurs="unbounded" minOccurs="0" name="Feedback" type="cmn:StringType"/>
                                    </xs:sequence>
                                </xs:extension>
                            </xs:complexContent>
                        </xs:complexType>
                    </xs:element>
                    <xs:element minOccurs="0" name="UserID" nillable="true" type="cmn:StringType"/>
                    <xs:element minOccurs="0" name="Portal" nillable="true" type="cmn:StringType"/>
                    <xs:element minOccurs="0" name="SSOID" nillable="true" type="cmn:StringType"/>
                    <xs:element minOccurs="0" name="CK" nillable="true" type="cmn:StringType"/>
                    <xs:element minOccurs="0" name="Comments">
                        <xs:complexType>
                            <xs:complexContent>
                                <xs:extension base="cmn:ArrayType">
                                    <xs:sequence>
                                        <xs:element maxOccurs="unbounded" minOccurs="0" name="Comments" type="cmn:StringType"/>
                                    </xs:sequence>
                                </xs:extension>
                            </xs:complexContent>
                        </xs:complexType>
                    </xs:element>
                    <xs:element minOccurs="0" name="attachments" nillable="true" type="cmn:AttachmentsType"/>
                </xs:sequence>
                <xs:attribute name="query" type="xs:string" use="optional"/>
                <xs:attribute name="uniquequery" type="xs:string" use="optional"/>
                <xs:attribute name="recordid" type="xs:string" use="optional"/>
                <xs:attribute name="updatecounter" type="xs:long" use="optional"/>
            </xs:complexType>
            <xs:complexType name="HPSMInteractionsFromMosRuModelType">
                <xs:sequence>
                    <xs:element name="keys" type="HPSMInteractionsFromMosRuKeysType"/>
                    <xs:element name="instance" type="HPSMInteractionsFromMosRuInstanceType"/>
                    <xs:element minOccurs="0" name="messages" type="cmn:MessagesType"/>
                </xs:sequence>
                <xs:attribute name="query" type="xs:string" use="optional"/>
            </xs:complexType>
            <xs:element name="RetrieveHPSMInteractionsFromMosRuRequest">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="model" type="HPSMInteractionsFromMosRuModelType"/>
                    </xs:sequence>
                    <xs:attribute name="attachmentInfo" type="xs:boolean" use="optional"/>
                    <xs:attribute name="attachmentData" type="xs:boolean" use="optional"/>
                    <xs:attribute default="true" name="ignoreEmptyElements" type="xs:boolean" use="optional"/>
                    <xs:attribute name="updatecounter" type="xs:boolean" use="optional"/>
                    <xs:attribute name="handle" type="xs:string" use="optional"/>
                    <xs:attribute name="count" type="xs:long" use="optional"/>
                    <xs:attribute name="start" type="xs:long" use="optional"/>
                </xs:complexType>
            </xs:element>
            <xs:element name="RetrieveHPSMInteractionsFromMosRuResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="model" type="HPSMInteractionsFromMosRuModelType"/>
                        <xs:element minOccurs="0" name="messages" type="cmn:MessagesType"/>
                    </xs:sequence>
                    <xs:attribute name="status" type="cmn:StatusType" use="required"/>
                    <xs:attribute name="message" type="xs:string" use="required"/>
                    <xs:attribute name="schemaRevisionDate" type="xs:date" use="required"/>
                    <xs:attribute name="schemaRevisionLevel" type="xs:int" use="required"/>
                    <xs:attribute name="returnCode" type="xs:decimal" use="optional"/>
                    <xs:attribute name="query" type="xs:string" use="optional"/>
                    <xs:attribute name="handle" type="xs:string" use="optional"/>
                    <xs:attribute name="count" type="xs:long" use="optional"/>
                    <xs:attribute name="more" type="xs:boolean" use="optional"/>
                    <xs:attribute name="start" type="xs:long" use="optional"/>
                </xs:complexType>
            </xs:element>
            <xs:element name="RetrieveHPSMInteractionsFromMosRuKeysListRequest">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="model" type="HPSMInteractionsFromMosRuModelType"/>
                    </xs:sequence>
                    <xs:attribute name="attachmentInfo" type="xs:boolean" use="optional"/>
                    <xs:attribute name="attachmentData" type="xs:boolean" use="optional"/>
                    <xs:attribute default="true" name="ignoreEmptyElements" type="xs:boolean" use="optional"/>
                    <xs:attribute name="updatecounter" type="xs:boolean" use="optional"/>
                    <xs:attribute name="handle" type="xs:string" use="optional"/>
                    <xs:attribute name="count" type="xs:long" use="optional"/>
                    <xs:attribute name="start" type="xs:long" use="optional"/>
                </xs:complexType>
            </xs:element>
            <xs:element name="RetrieveHPSMInteractionsFromMosRuKeysListResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" name="keys" type="HPSMInteractionsFromMosRuKeysType"/>
                        <xs:element minOccurs="0" name="messages" type="cmn:MessagesType"/>
                    </xs:sequence>
                    <xs:attribute name="status" type="cmn:StatusType" use="required"/>
                    <xs:attribute name="message" type="xs:string" use="required"/>
                    <xs:attribute name="schemaRevisionDate" type="xs:date" use="required"/>
                    <xs:attribute name="schemaRevisionLevel" type="xs:int" use="required"/>
                    <xs:attribute name="returnCode" type="xs:decimal" use="optional"/>
                    <xs:attribute name="query" type="xs:string" use="optional"/>
                    <xs:attribute name="handle" type="xs:string" use="optional"/>
                    <xs:attribute name="count" type="xs:long" use="optional"/>
                    <xs:attribute name="more" type="xs:boolean" use="optional"/>
                    <xs:attribute name="start" type="xs:long" use="optional"/>
                </xs:complexType>
            </xs:element>
            <xs:element name="RetrieveHPSMInteractionsFromMosRuListRequest">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" name="keys" type="HPSMInteractionsFromMosRuKeysType"/>
                    </xs:sequence>
                    <xs:attribute name="attachmentInfo" type="xs:boolean" use="optional"/>
                    <xs:attribute name="attachmentData" type="xs:boolean" use="optional"/>
                    <xs:attribute default="true" name="ignoreEmptyElements" type="xs:boolean" use="optional"/>
                    <xs:attribute name="updatecounter" type="xs:boolean" use="optional"/>
                    <xs:attribute name="handle" type="xs:string" use="optional"/>
                    <xs:attribute name="count" type="xs:long" use="optional"/>
                    <xs:attribute name="start" type="xs:long" use="optional"/>
                    <xs:attribute name="attachmentType" type="xs:long" use="optional"/>
                </xs:complexType>
            </xs:element>
            <xs:element name="RetrieveHPSMInteractionsFromMosRuListResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" name="instance" type="HPSMInteractionsFromMosRuInstanceType"/>
                        <xs:element minOccurs="0" name="messages" type="cmn:MessagesType"/>
                    </xs:sequence>
                    <xs:attribute name="status" type="cmn:StatusType" use="required"/>
                    <xs:attribute name="message" type="xs:string" use="required"/>
                    <xs:attribute name="schemaRevisionDate" type="xs:date" use="required"/>
                    <xs:attribute name="schemaRevisionLevel" type="xs:int" use="required"/>
                    <xs:attribute name="returnCode" type="xs:decimal" use="optional"/>
                    <xs:attribute name="query" type="xs:string" use="optional"/>
                    <xs:attribute name="handle" type="xs:string" use="optional"/>
                    <xs:attribute name="count" type="xs:long" use="optional"/>
                    <xs:attribute name="more" type="xs:boolean" use="optional"/>
                    <xs:attribute name="start" type="xs:long" use="optional"/>
                </xs:complexType>
            </xs:element>
            <xs:element name="CreateHPSMInteractionsFromMosRuRequest">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="model" type="HPSMInteractionsFromMosRuModelType"/>
                    </xs:sequence>
                    <xs:attribute name="attachmentInfo" type="xs:boolean" use="optional"/>
                    <xs:attribute name="attachmentData" type="xs:boolean" use="optional"/>
                    <xs:attribute default="true" name="ignoreEmptyElements" type="xs:boolean" use="optional"/>
                    <xs:attribute name="updateconstraint" type="xs:long" use="optional"/>
                </xs:complexType>
            </xs:element>
            <xs:element name="CreateHPSMInteractionsFromMosRuResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="model" type="HPSMInteractionsFromMosRuModelType"/>
                        <xs:element minOccurs="0" name="messages" type="cmn:MessagesType"/>
                    </xs:sequence>
                    <xs:attribute name="status" type="cmn:StatusType" use="required"/>
                    <xs:attribute name="message" type="xs:string" use="required"/>
                    <xs:attribute name="schemaRevisionDate" type="xs:date" use="required"/>
                    <xs:attribute name="schemaRevisionLevel" type="xs:int" use="required"/>
                    <xs:attribute name="returnCode" type="xs:decimal" use="optional"/>
                    <xs:attribute name="query" type="xs:string" use="optional"/>
                </xs:complexType>
            </xs:element>
            <xs:element name="UpdateHPSMInteractionsFromMosRuRequest">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="model" type="HPSMInteractionsFromMosRuModelType"/>
                    </xs:sequence>
                    <xs:attribute name="attachmentInfo" type="xs:boolean" use="optional"/>
                    <xs:attribute name="attachmentData" type="xs:boolean" use="optional"/>
                    <xs:attribute default="true" name="ignoreEmptyElements" type="xs:boolean" use="optional"/>
                    <xs:attribute name="updateconstraint" type="xs:long" use="optional"/>
                </xs:complexType>
            </xs:element>
            <xs:element name="UpdateHPSMInteractionsFromMosRuResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="model" type="HPSMInteractionsFromMosRuModelType"/>
                        <xs:element minOccurs="0" name="messages" type="cmn:MessagesType"/>
                    </xs:sequence>
                    <xs:attribute name="status" type="cmn:StatusType" use="required"/>
                    <xs:attribute name="message" type="xs:string" use="required"/>
                    <xs:attribute name="schemaRevisionDate" type="xs:date" use="required"/>
                    <xs:attribute name="schemaRevisionLevel" type="xs:int" use="required"/>
                    <xs:attribute name="returnCode" type="xs:decimal" use="optional"/>
                    <xs:attribute name="query" type="xs:string" use="optional"/>
                </xs:complexType>
            </xs:element>
        </xs:schema>
    </types>
    <message name="RetrieveHPSMInteractionsFromMosRuRequest">
        <part element="ns:RetrieveHPSMInteractionsFromMosRuRequest" name="RetrieveHPSMInteractionsFromMosRuRequest"/>
    </message>
    <message name="RetrieveHPSMInteractionsFromMosRuResponse">
        <part element="ns:RetrieveHPSMInteractionsFromMosRuResponse" name="RetrieveHPSMInteractionsFromMosRuResponse"/>
    </message>
    <message name="RetrieveHPSMInteractionsFromMosRuKeysListRequest">
        <part element="ns:RetrieveHPSMInteractionsFromMosRuKeysListRequest" name="RetrieveHPSMInteractionsFromMosRuKeysListRequest"/>
    </message>
    <message name="RetrieveHPSMInteractionsFromMosRuKeysListResponse">
        <part element="ns:RetrieveHPSMInteractionsFromMosRuKeysListResponse" name="RetrieveHPSMInteractionsFromMosRuKeysListResponse"/>
    </message>
    <message name="RetrieveHPSMInteractionsFromMosRuListRequest">
        <part element="ns:RetrieveHPSMInteractionsFromMosRuListRequest" name="RetrieveHPSMInteractionsFromMosRuListRequest"/>
    </message>
    <message name="RetrieveHPSMInteractionsFromMosRuListResponse">
        <part element="ns:RetrieveHPSMInteractionsFromMosRuListResponse" name="RetrieveHPSMInteractionsFromMosRuListResponse"/>
    </message>
    <message name="CreateHPSMInteractionsFromMosRuRequest">
        <part element="ns:CreateHPSMInteractionsFromMosRuRequest" name="CreateHPSMInteractionsFromMosRuRequest"/>
    </message>
    <message name="CreateHPSMInteractionsFromMosRuResponse">
        <part element="ns:CreateHPSMInteractionsFromMosRuResponse" name="CreateHPSMInteractionsFromMosRuResponse"/>
    </message>
    <message name="UpdateHPSMInteractionsFromMosRuRequest">
        <part element="ns:UpdateHPSMInteractionsFromMosRuRequest" name="UpdateHPSMInteractionsFromMosRuRequest"/>
    </message>
    <message name="UpdateHPSMInteractionsFromMosRuResponse">
        <part element="ns:UpdateHPSMInteractionsFromMosRuResponse" name="UpdateHPSMInteractionsFromMosRuResponse"/>
    </message>
    <portType name="HPSMInteractionsFromMosRu">
        <operation name="RetrieveHPSMInteractionsFromMosRu">
            <documentation/>
            <input message="ns:RetrieveHPSMInteractionsFromMosRuRequest"/>
            <output message="ns:RetrieveHPSMInteractionsFromMosRuResponse"/>
        </operation>
        <operation name="RetrieveHPSMInteractionsFromMosRuKeysList">
            <documentation/>
            <input message="ns:RetrieveHPSMInteractionsFromMosRuKeysListRequest"/>
            <output message="ns:RetrieveHPSMInteractionsFromMosRuKeysListResponse"/>
        </operation>
        <operation name="RetrieveHPSMInteractionsFromMosRuList">
            <documentation/>
            <input message="ns:RetrieveHPSMInteractionsFromMosRuListRequest"/>
            <output message="ns:RetrieveHPSMInteractionsFromMosRuListResponse"/>
        </operation>
        <operation name="CreateHPSMInteractionsFromMosRu">
            <documentation/>
            <input message="ns:CreateHPSMInteractionsFromMosRuRequest"/>
            <output message="ns:CreateHPSMInteractionsFromMosRuResponse"/>
        </operation>
        <operation name="UpdateHPSMInteractionsFromMosRu">
            <documentation/>
            <input message="ns:UpdateHPSMInteractionsFromMosRuRequest"/>
            <output message="ns:UpdateHPSMInteractionsFromMosRuResponse"/>
        </operation>
    </portType>
    <binding name="HPSMInteractionsFromMosRu" type="ns:HPSMInteractionsFromMosRu">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="RetrieveHPSMInteractionsFromMosRu">
            <soap:operation soapAction="Retrieve" style="document"/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
        <operation name="RetrieveHPSMInteractionsFromMosRuKeysList">
            <soap:operation soapAction="RetrieveKeysList" style="document"/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
        <operation name="RetrieveHPSMInteractionsFromMosRuList">
            <soap:operation soapAction="RetrieveList" style="document"/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
        <operation name="CreateHPSMInteractionsFromMosRu">
            <soap:operation soapAction="Create" style="document"/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
        <operation name="UpdateHPSMInteractionsFromMosRu">
            <soap:operation soapAction="Update" style="document"/>
            <input>
                <soap:body use="literal"/>
            </input>
            <output>
                <soap:body use="literal"/>
            </output>
        </operation>
    </binding>
    <service name="HPSMInteractionsFromMosRu">
        <port binding="ns:HPSMInteractionsFromMosRu" name="HPSMInteractionsFromMosRu">
            <soap:address location="http://***.**.**.**:8090/1/SM/7/ws"/>
        </port>
    </service>
</definitions>

我找到了适合我的解决方案! 该错误的问题是我无法从我的脚本中获取该文件,因此您需要将它们保存在本地: 我将该文件 (http://www.w3.org/2005/05/xmlmime) 保存到我的工作目录中,并将 WSDL 文件路径 (schemaLocation=...) 也更改为我的本地副本 现在它看起来像这样(在 WSDL(

<xs:import namespace="http://www.w3.org/2005/05/xmlmime" schemaLocation="http://mydomain/xmlmime.xml"/>
<xs:import namespace="http://schemas.hp.com/SM/7/Common" schemaLocation="http://mydomain/Common.xsd"/>

并且还在我的 Common.xsd

本地副本中更改了该路径
<xs:import namespace="http://www.w3.org/2005/05/xmlmime" schemaLocation="http://mydomain/xmlmime.xml"/>

现在我没有收到那个错误!

P.S 在我的例子中,我从服务器端开发人员那里收到的 WSDL 文件中的文件路径还有一些其他错误,但在我的例子中尤其如此。所以总是检查 URI 路径。 :)