#include
#import "msXML4.dll"
using namespace MSXML2;
#import "C:Program FilesCommon FilesMSSoapBinarIEsmssoap30.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://localhost/05_server_sample.PHP";
Connector->Connect();
// Begin the message.
//Connector->Property["SoapAction"] = "uri:AddNumbers";
Connector->Property["SoapAction"] = "http://localhost/Reziproke";
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("","","");
Serializer->StartBody("");
Serializer->StartElement("Reziproke","http://webservice.teserco.de/PHPug/","","");
Serializer->StartElement("ReziprokeRequest","","","");
Serializer->WriteString("1000000");
Serializer->EndElement();
// Serializer->StartElement("NumberTwo","","","");
// 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: %sn", (const char*)Reader->RpcResult->text);
}
int main()
{
CoInitialize(NULL);
Add();
CoUninitialize();
return 0;
}
PHP服務端
05_server_sample.PHP:
soap_defencoding = 'ISO-8859-1';
$serviceName = 'PHPugSample5';
$targetNameSpace = 'http://webservice.teserco.de/PHPug/';
$endPoint = 'http://localhost/05_server_sample.PHP';
$bindingStyle = 'rpc';
$bindingTransport = 'http://schemas.XMLsoap.org/soap/http';
$server->configureWSDL(
$serviceName,
$targetNameSpace,
$endPoint,
$bindingStyle,
$bindingTransport);
$server->wsdl->schemaTargetNamespace = 'http://webservice.teserco.de/PHPug';
$methodName = 'Reziproke';
$inParam = array('income'=>'xsd:float');
$outParam = array('return'=>'xsd:float');
$OperationNameSpace = 'http://webservice.teserco.de/PHPug/';
$soapAction = 'http://localhost/Reziproke';
$soapActionStyle = 'rpc';
$soapActionUse = 'encoded';
$documentation = 'Reziproke Doc';
$server->register(
$methodName,
$inParam,
$outParam,
$OperationNameSpace,
$soapAction,
$soapActionStyle,
$soapActionUse,
$documentation);
function Reziproke($value) {
$faultcode = 'Server';
$faultactor = 'Actor 1';
$faultstring = 'Devision by Zero';
$faultdetail = 'Fehlercode 7';
if ($value == 0) {
return new soap_fault($faultcode, $faultactor, $faultstring, $faultdetail);
} else {
return 1 / $value;
}
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);?>