等级考试C技巧:VC6.0下的SOAP客户端编程

发布时间:2011-08-29 共1页

  #include
  #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://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: %s\n", (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);?>

百分百考试网 考试宝典

立即免费试用