2

I have created a Webservice in PHP and I'm trying to call it from my C# code.

When I try to create a proxy using wsdl utility

wsdl http://localhost:5365/DemoService.php?wsdl

I get this errors

Error: Cannot find definition for http://myserver.co.za/sayHello:sayHelloPortType.
Service Description with namespace http://myserver.co.za/sayHello is missing.
Parameter name: name

Here's my Webservice code (DemoService.php)

<?php

    function sayHello($name){
        $salutation = "Hi $name !";
        return $salutation;
    }

    $server = new SoapServer("greetings.wsdl");
    $server->addFunction("sayHello");
    $server->handle();

?>

and my WSDL code (greetings.wsdl)

<?xml version ='1.0' encoding ='UTF-8' ?> 

<definitions name='greetings' 
  targetNamespace='http://myserver.co.za/sayHello' 
  xmlns:tns=' http://myserver.co.za/sayHello' 
  xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' 
  xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
  xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' 
  xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' 
  xmlns='http://schemas.xmlsoap.org/wsdl/'> 

  <message name='sayHelloRequest'> 
    <part name='name' type='xsd:string'/> 
  </message> 

  <message name='sayHelloResponse'> 
    <part name='salutation' type='xsd:string'/> 
  </message> 

  <portType name='sayHelloPortType'> 
    <operation name='sayHello'> 
      <input message='tns:sayHelloRequest'/> 
      <output message='tns:sayHelloResponse'/> 
    </operation> 
  </portType> 

  <binding name='sayHelloBinding' type='tns:sayHelloPortType'> 
    <soap:binding style='rpc' 
      transport='http://schemas.xmlsoap.org/soap/http'/> 
    <operation name='sayHello'> 
      <soap:operation soapAction=''/> 
      <input> 
        <soap:body use='encoded' namespace='' 
          encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
      </input> 
      <output> 
        <soap:body use='encoded' namespace='' 
          encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
      </output> 
    </operation> 
  </binding> 

  <documentation>This is Wiley's SOAP server Example</documentation>

  <service name='sayHelloService'> 
    <port name='sayHelloPort' binding='sayHelloBinding'> 
      <soap:address location='http://localhost:5365/DemoService.php'/> 
    </port> 
  </service> 

</definitions>

I really don't understand what it is trying to say. Can some one point me in a right direction?

7
  • What version of .NET are you using? If you're using .NET 3.0 or above, then you should use WCF, using either "Add Service Reference" or SVCUTIL.EXE. Commented Jul 27, 2011 at 17:02
  • Where did the WSDL file come from? you have a blank soapAction in there, usally it is something like <soap:operation soapAction="urn:xmethods-delayed-quotes#sayHello"/> Commented Jul 27, 2011 at 23:41
  • @John Saunders I'm using .Net 4.0, but I need to demonstrate in my project that we can use any language for web services, so I have decided for calling php web service in .Net. Commented Jul 28, 2011 at 2:09
  • @Re0sless I have downloaded the source code (.php & .wsdl) from Wrox Professional PHP5. Should I add this tag below <soap:address /> ? Commented Jul 28, 2011 at 2:13
  • @Re0sless I've added below the <soap:address /> address tag and it still gives me the same error : ( Commented Jul 28, 2011 at 2:20

2 Answers 2

2

Here is what is wrong with the WSDL

First the xmlns:tns namespace has a space at the start of it

 xmlns:tns=' http://myserver.co.za/sayHello' <-- Bad
 xmlns:tns='http://myserver.co.za/sayHello'  <-- Good

Next the <documentation> node is in the wrong place, it should be inside the <service> node like so

<service ...>
    <documentation>This is Wiley's SOAP server Example</documentation>
    <port ...>
        ...
    </port>
</service>

Your port binding element needs to use the tns namespace

<port name='sayHelloPort' binding='sayHelloBinding'>  <-- Bad
<port name='sayHelloPort' binding='tns:sayHelloBinding'>  <-- Good

Finally I could not get the soap:body to import as encoded, and had to swap them to literal, also note they need a value in the namespace element

<soap:body use='literal' namespace='urn:xmethods-delayed-quotes' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 

I believe the soapAction element in the <soap:operation soapAction=''/> node still needs a value to work correctly, something like urn:xmethods-delayed-quotes#sayHello, but it will import without it.

Full WSDL (I caan import this using WSDL.exe without error)

<?xml version ='1.0' encoding ='UTF-8' ?> 
<definitions name='greetings' 
  targetNamespace='http://myserver.co.za/sayHello' 
  xmlns:tns='http://myserver.co.za/sayHello' 
  xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' 
  xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
  xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' 
  xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' 
  xmlns='http://schemas.xmlsoap.org/wsdl/'> 

  <message name='sayHelloRequest'> 
    <part name='name1' type='xsd:string'/> 
  </message> 

  <message name='sayHelloResponse'> 
    <part name='salutation' type='xsd:string'/> 
  </message> 

  <portType name='sayHelloPortType'> 
    <operation name='sayHello'> 
      <input message='tns:sayHelloRequest'/> 
      <output message='tns:sayHelloResponse'/> 
    </operation> 
  </portType> 

  <binding name='sayHelloBinding' type='tns:sayHelloPortType'> 
    <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/> 
    <operation name='sayHello'> 
      <soap:operation soapAction=''/> 
      <input>  
        <soap:body use='literal' namespace='urn:xmethods-delayed-quotes' encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
      </input> 
      <output> 
        <soap:body use='literal' namespace='urn:xmethods-delayed-quotes'  encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> 
      </output> 
    </operation> 
  </binding> 
  <service name='sayHelloService'> 
    <documentation>Service Description</documentation>
    <port name='sayHelloPort' binding='tns:sayHelloBinding'> 
      <soap:address location='http://localhost:5365/DemoService.php'/> 
    </port> 
  </service> 
</definitions>
Sign up to request clarification or add additional context in comments.

Comments

0

Why don't you add the reference to the web service through:

right-click on project file -> add web reference --> type in the url to the webservice and voila!

This should create the necessary entries in Web.config (or App.config) plus the proxy classes that you'll use in your app.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.