2011-11-22 9 views
5

私の会社内でリモートWebサービスを呼び出そうとしています。独自の理由から、私はWebサービスにURLを提供できません。 Webサービスには、getItemFieldという単一の関数があります。それは次のようにサービスの説明があり、私は反対PHPを実行しようとしている小規模なテストサービスである:PHPとSoapアクションヘッダなし

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://www.oracle.com/ws/MyFirstWebService" xmlns:intf="http://www.oracle.com/ws/MyFirstWebService" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://www.w3.org/1999/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.oracle.com/ws/MyFirstWebService"> 
<!-- 
WSDL created by Apache Axis version: 1.2alpha Built on Oct 23, 2007 (12:09:54 IST) 
--> 
<wsdl:types> 
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.oracle.com/ws/MyFirstWebService"> 
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/> 
<complexType name="ArrayOf_xsd_string"> 
<complexContent> 
<restriction base="soapenc:Array"> 
<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/> 
</restriction> 
</complexContent> 
</complexType> 
</schema> 
</wsdl:types> 
<message name="getItemFieldRequest"> 
<part name="args" type="impl:ArrayOf_xsd_string"/> 
</message> 
<message name="getItemFieldResponse"> 
<part name="getItemFieldReturn" type="soapenc:string"/> 
</message> 
<portType name="MyFirstWebService"> 
<operation name="getItemField" parameterOrder="args"> 
<input message="impl:getItemFieldRequest" name="getItemFieldRequest"/> 
<output message="impl:getItemFieldResponse" name="getItemFieldResponse"/> 
</operation> 
</portType> 
<binding name="MyFirstWebServiceSoapBinding" type="impl:MyFirstWebService"> 
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> 
<operation name="getItemField"> 
<wsdlsoap:operation soapAction=""/> 
<input name="getItemFieldRequest"> 
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://first" use="encoded"/> 
</input> 
<output name="getItemFieldResponse"> 
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://www.oracle.com/ws/MyFirstWebService" use="encoded"/> 
</output> 
</operation> 
</binding> 
<service name="MyFirstWebServiceService"> 
<port binding="impl:MyFirstWebServiceSoapBinding" name="MyFirstWebService"> 
<wsdlsoap:address location="http://myWebsite.com/services/MyFirstWebService"/> 
</port> 
</service> 
</definitions> 

私はサービスにうまく接続して、単一の機能とタイプの名前をプリントアウトすることができ、しかし、関数を呼び出そうとすると、'SOAPActionヘッダがありません!'というメッセージが表示されます。エラー。次のようにサービス機能を呼び出すために私のPHPコードは次のようになります。定義されたのSOAPActionを持っているように見えないサービスの説明に基づいて

$options = array(
       // Dev 
       'soap_version'=>SOAP_1_2, 
       'exceptions'=>true, 
       'trace'=>1, 
       'cache_wsdl'=>WSDL_CACHE_NONE, 
       'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 

       // Credentials 
       'login' => 'user', 
       'password' => 'pass' 
      );   

// Connected successfully 
      $client = new SoapClient("http://myWebsite.com/services/MyFirstWebService?wsdl", $options); 

    //Params 
     $params = array('123456'); 

     //Options 
     $options = array('soapaction' => '""'); 

     //Call function (Both methods below throw the same 'no SOAPAction header!' error) 
     //$result = $client->getItemField(new SoapParam($params, "getItemFieldRequest")); 
     $result = $client->__soapCall("getItemField", array('123456'), $options); 

。 soapActionで見られる行は<wsdlsoap:operation soapAction=""/>です。何も定義されていないので空のsoapActionを指定しようとしましたが、それはうまくいかないようです。 Webサービス定義自体は不完全ですか?または、クライアントサイドのアプリケーション呼び出しでパラメータが不足していますか?前もって感謝します。

UPDATE:

は、SOAPアクションとしてメソッド名を指定しようとしましたが、htatは動作しませんでした。

//Params 
    $params = array('123456'); 

    //Options 
    $options = array('soapaction' => 'getItemField'); 

    //Call function (STILL THROWS 'no SOAPAction header!') 
    $result = $client->__soapCall("getItemField", $params, $options); 

私は、それが「」に設定されていますつまりあれば何のsoapActionは、WSDLで指定されていない場合に行うことになっています。

+0

これに関する更新はありますか?私はZend soapを介して接続できるWebサービス上のカールを介して接続しようとしているときに同じ問題に直面しているので、いくつかのオプションやヘッダーに関連していると思います。 –

+0

SOAPActionヘッダーがHTTPヘッダーに関連していませんか? http://www.oreillynet.com/xml/blog/2002/11/unraveling_the_mystery_of_soap.html – pedromanoel

答えて

-1

その必要なすべての詳細をせずに手助けするのが難しいが、私はあなたが次のことを試してアドバイスします:

//Replace accordingly: see PHP Manual 
//(http://www.php.net/manual/en/soapheader.soapheader.php) 

$header = new SoapHeader($namespace, $name, $data, $mustunderstand, $actor); 
$client->__setSoapHeaders($header); 

//Main soap call follows.... 

SOAPサービスへの呼び出しを行う前に。 これが役立つことを願っています。

+0

なぜdownvoteを確認しますか? @profnotimeと、ここで答えを探している皆さんには本当に失礼です。 – pedromanoel

+0

SoapHeaderは、SOAPリクエストのセクションを設定します。 HTTPヘッダーは設定されません。 – Andrew

2

解決策は同じかもしれませんが、cURLではなくSoapClientではなく、同様の問題がありました。

エンドサービスにリクエストを送信するときは、Content-Typeを指定するヘッダーを送信する必要があります。このヘッダーでは、actionまたは「soap action」を指定することもできます。私の場合は

$headers = array(); 
$headers[] = 'Content-Type: application/soap+xml; charset=utf-8; action="[soap action goes here]"'; 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

、そしてどのようなWSDLは、次のことを示しています、あなたと同じように表示されます。

<wsdl:operation name="getProducts"> 
    <soap:operation soapAction=""/> 
    <!-- trimmed --> 
</wsdl:operation> 

まず、私はsoapAction=""を参照してくださいので、私は、送信されるヘッダにaction=""を設定。これは失敗しました。ヘッダーに入力される正しいデータはoperationで、action="getProducts"となります。

SoapClientのためのマニュアルとphp using SOAP with a different SoapActionへの回答をもとに、あなたの要求をして働いているはずです:

$client = new SoapClient("http://myWebsite.com/services/MyFirstWebService?wsdl", $options); 
$result = $client->__soapCall("getItemField", array('123456')); 

あなたは単にむしろに渡すよりも、(アクションを指定しないこと__soapCall()に送ら$optionsを省略しました空白のもの)?