SOAP応答結果にnamespaceを指定する方法 - PHPプロ!Q&A掲示板
現在のSOAP応答結果
- <SOAP-ENV:Envelope
- xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
- xmlns:ns1="http://test.com/">
- <SOAP-ENV:Body>
- <ns1:ElementTrendCompareResponse>
- <ns1:label>2010/04</ns1:label>
- <ns1:value>814859</ns1:value>
- </ns1:ElementTrendCompareResponse>
- </SOAP-ENV:Body>
- </SOAP-ENV:Envelope>
期待するSOAP応答結果(細かい点はいいとして、「ns1:」という文字を各要素から消したいです)
- <SOAP-ENV:Envelope
- xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
- <SOAP-ENV:Body>
- <ElementTrendCompareResponse xmlns="http://test.com">
- <label>2010/04</label>
- <value>814859</value>
- </ElementTrendCompareResponse>
- </SOAP-ENV:Body>
- </SOAP-ENV:Envelope>
WSDLとプログラムの内容は次のとおりです。
- xml version="1.0" encoding="utf-8"
- <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
- xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
- xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
- xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
- xmlns:tns="http://test.com/"
- xmlns:s="http://www.w3.org/2001/XMLSchema"
- targetNamespace="http://test.com/"
- xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <!-- type -->
- <s:schema elementFormDefault="qualified" targetNamespace="http://test.com/">
- <!-- request -->
- <s:element name="ElementTrendCompareRequest">
- <s:complexType>
- <s:sequence>
- <s:element minOccurs="0" maxOccurs="1" name="month" type="s:string" />
- </s:sequence>
- </s:complexType>
- </s:element>
- <!-- response -->
- <s:element name="ElementTrendCompareResponse">
- <s:complexType>
- <s:sequence>
- <!-- current period -->
- <s:element minOccurs="1" maxOccurs="1" name="label" type="s:string" />
- <s:element minOccurs="1" maxOccurs="1" name="value" type="s:int" />
- </s:sequence>
- </s:complexType>
- </s:element>
- </s:schema>
- </wsdl:types>
- <!-- message -->
- <wsdl:message name="MessageTrendCompareRequest">
- <wsdl:part name="parameters" element="tns:ElementTrendCompareRequest" />
- </wsdl:message>
- <wsdl:message name="MessageTrendCompareResponse">
- <wsdl:part name="parameters" element="tns:ElementTrendCompareResponse" />
- </wsdl:message>
- <!-- port -->
- <wsdl:portType name="PortTypeTrendSoap">
- <wsdl:operation name="OperationTrendCompare">
- <wsdl:input message="tns:MessageTrendCompareRequest" />
- <wsdl:output message="tns:MessageTrendCompareResponse" />
- </wsdl:operation>
- </wsdl:portType>
- <!-- binding -->
- <wsdl:binding name="BindingTrendSoap" type="tns:PortTypeTrendSoap">
- <wsdl:operation name="OperationTrendCompare">
- <wsdl:input>
- <soap:body use="literal" />
- </wsdl:input>
- <wsdl:output>
- <soap:body use="literal" />
- </wsdl:output>
- </wsdl:operation>
- <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
- </wsdl:binding>
- <!-- service -->
- <wsdl:service name="ServiceTrend">
- <wsdl:port name="PortTrendSoap" binding="tns:BindingTrendSoap">
- <soap:address location="http://hostname/soap/qa/Server.php" />
- </wsdl:port>
- </wsdl:service>
- </wsdl:definitions>
サーバ側プログラム
- ini_set('soap.wsdl_cache_enabled', '0');
- ini_set('soap.wsdl_cache_ttl', '0');
- define( "WSDL_PATH", "./test.wsdl" );
- /*=======================================================================
- Soap Operations
- =======================================================================*/
- function OperationTrendCompare($param){
- // レスポンスの作成
- return array(
- "label" => "2010/04",
- "value" => 814859,
- );
- }
- /*=======================================================================
- Soap Server Main function
- =======================================================================*/
- // Soap server
- $server = new SoapServer( WSDL_PATH );
- $server->addFunction("OperationTrendCompare");
- if( $_SERVER["REQUEST_METHOD"] == "POST" ){
- $server->handle();
- } else {
- echo "このSOAPサーバのメソッド: ";
- $functions = $server->getFunctions();
- foreach( $functions as $func ){
- echo $func . " ";
- }
- }
以上よろしくお願いいたします。
この質問への意見の募集は締め切られ、ポイントは既に配分されました。
意見を投稿することはできますが、ポイントを受け取ることはできません。




ページのトップへ


GETのままでは検索エンジンのロボットが拾ってくれなかったためにSEO対策として有効だと言われていますね。