Jump to content

about SOAP ues PHP something question


joymis

Recommended Posts

Hello!

 

I reference Internet example try to practice SOAP, but I get a problem

 

I didn't use NUSOAP, this is my code

 

server.php

<?phpinclude("webservice.class.php"); ini_set("soap.wsdl_cache_enabled", "0");$server = new SoapServer('webservice.wsdl', array('soap_version' => SOAP_1_2,'uri' => "abcd")); $server->setClass("webservice"); $server->handle();?>

webservice.class.php

<?php	class webservice{		public function Add($a, $ 		{			return $a + $b;		}		public function bbbbb()		{			return "Hello1234";		}	}?>

webservice.wsdl

<?xml version="1.0" ?><definitions name="test" targetNamespace="urn:test" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="urn:test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns="http://schemas.xmlsoap.org/wsdl/"><types xmlns="http://schemas.xmlsoap.org/wsdl/" /><portType name="testPort">	<operation name="Add">		<input message="tns:AddRequest" />		<output message="tns:AddResponse" />	</operation>	<operation name="HelloWorld">		<input message="tns:HelloWorldRequest" />		<output message="tns:HelloWorldResponse" />	</operation></portType><binding name="testBinding" type="tns:testPort"><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /><operation name="Add"><soap:operation soapAction="urn:test#webservice#Add" /><input><soap:body use="encoded" namespace="urn:test" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /></input><output><soap:body use="encoded" namespace="urn:test" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /></output></operation><operation name="HelloWorld"><soap:operation soapAction="urn:test#webservice#HelloWorld" /><input><soap:body use="encoded" namespace="urn:test" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /></input><output><soap:body use="encoded" namespace="urn:test" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /></output></operation></binding><service name="test"><documentation /><port name="testPort" binding="tns:testBinding"><soap:address location="http://10.0.0.51:80/creat_wsdl.php" /></port></service><message name="AddRequest"><part name="a" type="xsd:string" /><part name="b" type="xsd:string" /></message><message name="AddResponse"><part name="Add" type="xsd:string" /></message><message name="HelloWorldRequest"></message><message name="HelloWorldResponse"><part name="HelloWorld" type="xsd:string" /></message></definitions>

client.php

<?phpini_set("soap.wsdl_cache_enabled", "0");$soap = new SoapClient("webservice.wsdl");echo $soap->Add('2', '4').'<br>';	// no displayecho $soap->bbbbb().'<br>';		// no displayvar_dump($soap->__getFunctions());	// can get function//=== no use WSDL , it's work ===========================$soap = new SoapClient(null, array("location" => "http://10.0.0.51/server.php","uri" => "abcd"));echo '<br>'.$soap->bbbbb();?>

Internet example explanation client.php use first and second "echo" can be display data

 

but it always only third "echo" can be display data....I don't know why

 

I look log, it's not print any error , use dump function that can get function

 

Hope anyone can helpMy English isn't very good, please don't mind.Thanks

Link to comment
Share on other sites

What does the var_dump show?

It's show this.

 

array(2) { [0]=> string(32) "string Add(string $a, string $b)" [1]=> string(14) "string bbbbb()" }

 

Thank you very much.

Edited by joymis
Link to comment
Share on other sites

Use the full URL to the WSDL file, not just a filename.

 

it's the same as before

<?phpini_set("soap.wsdl_cache_enabled", "0");$soap = new SoapClient("http://10.0.0.51/webservice.wsdl");echo $soap->Add('2', '4').'<br>';	// no displayecho $soap->bbbbb().'<br>';		// no displayvar_dump($soap->__getFunctions());	// can get function//=== no use WSDL , it's work ===========================$soap = new SoapClient(null, array("location" => "http://10.0.0.51/server.php","uri" => "abcd"));echo '<br>'.$soap->bbbbb();?>

Thank you very much.

Link to comment
Share on other sites

I got the answer, it's because of the code in the wsdl is wrong

<soap:address location="http://10.0.0.51:80/creat_wsdl.php" />

I modified it to server.php, and then it's work.

 

Thanks for your help! :lol:

Edited by joymis
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...