Webservice

i created a webservice in yii,

this is my controller:




<?php

class ApplicationController extends Controller{

	

	public function actions(){

	

        return array(

            'service'=>array(

                'class'=>'CWebServiceAction',

            ),

        );

    }


  /**

     * @return string

     * @soap

     */

	public function testWebService(){

		

		return "Something";

	}	

	

}

?>



I’m trying to call this webservice in CSharp,

It’s my code:




ServiceReference1.ApplicationControllerPortTypeClient p = new TestMySqlSynchronizeWebService.ServiceReference1.ApplicationControllerPortTypeClient();

string a = p.testWebService();



[size="3"]but i got this error:[/size]

There is a problem with the XML that was received from the network. See inner exception for more details.

[size="3"]

inner exception: [/size]

{"CData elements not valid at top level of an XML document. Line 1, position 3."}

What should I do ?

Shoud I set something ?

I am not able to see your C# code calling the service URL but have you?

http://hostname/path/to/index.php?r=CONTROLLERID/service’ ?

Watching the server response XML code would also help to find out what is happening.

URL: http://127.0.0.1/synchronize/index.php/application/service




This XML file does not appear to have any style information associated with it. The document tree is shown below.

      

−

<definitions name="ApplicationController" targetNamespace="urn:ApplicationControllerwsdl">

<wsdl:message name="testWebServiceRequest"/>

−

<wsdl:message name="testWebServiceResponse">

<wsdl:part name="return" type="xsd:string"/>

</wsdl:message>

−

<wsdl:portType name="ApplicationControllerPortType">

−

<wsdl:operation name="testWebService">

<wsdl:documentation/>

<wsdl:input message="tns:testWebServiceRequest"/>

<wsdl:output message="tns:testWebServiceResponse"/>

</wsdl:operation>

</wsdl:portType>

−

<wsdl:binding name="ApplicationControllerBinding" type="tns:ApplicationControllerPortType">

<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

−

<wsdl:operation name="testWebService">

<soap:operation soapAction="urn:ApplicationControllerwsdl#testWebService" style="rpc"/>

−

<wsdl:input>

<soap:body use="encoded" namespace="urn:ApplicationControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>

</wsdl:input>

−

<wsdl:output>

<soap:body use="encoded" namespace="urn:ApplicationControllerwsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>

</wsdl:output>

</wsdl:operation>

</wsdl:binding>

−

<wsdl:service name="ApplicationControllerService">

−

<wsdl:port name="ApplicationControllerPort" binding="tns:ApplicationControllerBinding">

<soap:address location="http://127.0.0.1/synchronize/index.php/application/service?ws=1"/>

</wsdl:port>

</wsdl:service>

</definitions>



dear Antonio Ramirez:

i used rewrite url

Csharp adds and compiles the webservice before running application, and i dont know what will happening when a soap method call in Csharp !

It looks correct.

Are you sure that you are not printing the debug info also? (the Yii log table)

When I browsed http://127.0.0.1/synchronize/index.php/application/service?ws=1 ,

I got this error:

[b][size="4"][color="#FF0000"]Internal Server Error[/color]

include(SoapServer.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory

An internal error occurred while the Web server was processing your request.

Please contact the webmaster to report this problem.

Thank you.

2010-10-26 13:09:34 [/size][/b]

Have you checked that the SOAP extension is installed ?

For some reason I had to use the service URL when testing web service calls from a C# client.

In get format:


http://server/app/index.php?r=controller/webservice&ws=1

or in path format:


http://server/app/controller/webservice/ws/1

/Tommy

Edit:

In PHP SoapClient we use the wsdl URL.

i installed soap extension

Now when I browsing http://127.0.0.1/syn...ication/service?ws=1 ,

I getting this error:

[color="#FF0000"][size="4"][b]XML Parsing Error: no element found

Location: http://127.0.0.1/synchronize/index.php/application/service?ws=1

Line Number 1, Column 1:

^

[/b][/size][/color]

Why are you appending the ?ws=1… just remove that…

After reading all the posts, I have to say that is very weird isn’t working now from browser URL as the xml seemed ok. Have you tried with a simple php file to consume that service?




$client=new SoapClient(’http://127.0.0.1/synchronize/index.php/application/service’);


echo $client->testWebService();



Lets see what happens after…

thanks all, my web service is working

I had the wrong about SOAP Extension

Hey Ramin,

Could you please post the right solution so others would be able to learn from?

Thanks and congratulations!

we must first be sure about installing SOAP Extension on our apache server