Webservice abfragen



  • Hallo,

    ich hoffe ihr könnt mir helfen!

    Ich habe einen simplen Webservice erstellt der 2 Zahlen annimmt und damit rechnet, das ganze in php wie folgt aus:

    <?php 
    
    function add($a, $b, $c) 
    { 
    	$c=2;
    	$d=($a+$b)*$c;
    	return $d;
    } 
    
    $server = new SoapServer("licence.wsdl"); 
    $server->addFunction("add");
    $server->handle(); 
    ?>
    

    Dateiname: server.php

    Dazu habe ich eine wsdl-Datei erstellt:

    <?xml version="1.0" encoding="UTF-8"?>
     	<wsdl:definitions 
    		targetNamespace="http://www.intercms.net/licence" 
    		xmlns:apachesoap="http://xml.apache.org/xml-soap" 
    		xmlns:impl="http://www.intercms.net/licence"
    		xmlns:intf="http://www.intercms.net/licence"
    		xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    		xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    		xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
    		xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    
    		<wsdl:message name="addRequest">
    			<part name="a" type="xsd:int"/>
    			<part name="b" type="xsd:int"/>
    		</wsdl:message>
    
    		<wsdl:message name="addResponse">
    			<wsdl:part name="addReturn" type="xsd:int" />
    		</wsdl:message>
    
    		<wsdl:portType name="Server1">
    			<wsdl:operation name="add">
    				<wsdl:input message="impl:addRequest" 
    					name="addRequest"  />
    				<wsdl:output message="impl:addResponse" 
    					name="addResponse" />
    			</wsdl:operation>
    		</wsdl:portType>
    
    		<wsdl:binding name="server1SoapBinding" type="impl:server1">
    			<wsdlsoap:binding style="rpc" 
    				transport="http://schemas.xmlsoap.org/soap/http" />
    			<wsdl:operation name="add">
    				<wsdlsoap:operation soapAction="" />
    			<wsdl:input name="addRequest">
    				<wsdlsoap:body 
    					encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
    					namespace="http://DefaultNamespace" use="encoded" />
    				</wsdl:input>
    			<wsdl:output name="addResponse">
    				<wsdlsoap:body 
    					encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
    					namespace="http://www.intercms.net/licence" use="encoded" />
    			</wsdl:output>
    			</wsdl:operation>
    		</wsdl:binding>
    
    		<wsdl:service name="server1Service">
    		<wsdl:port binding="impl:server1SoapBinding" name="server1">
    			<wsdlsoap:address location="http://www.intercms.net/licence" />
    		</wsdl:port>
    		</wsdl:service>
    
    	</wsdl:definitions>
    

    Dateiname: licence.wsdl

    Um das Ergebnis der Rechnung mit c++ abzufragen habe ich folgenden Code abgetippt:

    // server_abfrage.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
    //
    
    #include "stdafx.h"
    #include "stdio.h"
    #import "msxml4.dll" 
    //using namespace MSXML2;
    #import "C:\Program Files\Common Files\MSSoap\Binaries\mssoap30.dll" \
                exclude("IStream", "IErrorInfo", "ISequentialStream", "_LARGE_INTEGER", \
                        "_ULARGE_INTEGER", "tagSTATSTG", "_FILETIME")
    using namespace MSSOAPLib30;
    
    void Add()
    {
       ISoapSerializerPtr Serializer;
       ISoapReaderPtr Reader;
       ISoapConnectorPtr Connector;
       // Connect to the service.
       Connector.CreateInstance(__uuidof(HttpConnector30));
       Connector->Property["EndPointURL"] = "http://www.intercms.net/server.php";
       Connector->Connect();
    
       // Begin the message.
       //Connector->Property["SoapAction"] = "uri:AddNumbers";
       Connector->Property["SoapAction"] = "http://www.intercms.net/server:add";
       Connector->BeginMessage();
    
       // Create the SoapSerializer object.
       Serializer.CreateInstance(__uuidof(SoapSerializer30));
    
       // Connect the serializer object to the input stream of the connector object.
       Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));
    
       // Build the SOAP Message.
       Serializer->StartEnvelope("http://www.intercms.net/licence","","");
       Serializer->StartBody("");
       //Serializer->StartElement("addRequest","http://www.intercms.net/licence","","");
       Serializer->StartElement("a","","","");
       Serializer->WriteString("5");
       Serializer->EndElement();
       Serializer->StartElement("b","","","");
       Serializer->WriteString("10");
       Serializer->EndElement();
       //Serializer->EndElement();
       Serializer->EndBody();
       Serializer->EndEnvelope();
    
       // Send the message to the XML Web service.
       Connector->EndMessage();      
    
       // Read the response.
       Reader.CreateInstance(__uuidof(SoapReader30));
    
       // Connect the reader to the output stream of the connector object.
       Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");
    
       // Display the result.
       printf("Answer: %s\n", (const char*)Reader->RpcResult->text);
    
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {   CoInitialize(NULL);
       Add();
       CoUninitialize();
       return 0;
    }
    

    Ergebnis, wenn ich das in cmd ausgebe lautet:
    "SOAP-ENV:Client"

    Ich muss zugeben, dass ich nach dem c++-Code im Internet gegoogelt habe und mich null auskenne! Da bin ich auf euer Forum gelandet und hoffe nun, dass mir jemand helfen kann! 😕

    Vielen Dank schonmal

    milojohzak


Log in to reply