How to call a C # web service via PHP?

I wrote a web service using ASP.NET (in C #), and I'm trying to write an example PHP client using NuSOAP. Where I stumbled - examples of how to do this; some show soapval(and I don’t quite understand the parameters, for example, passing falseas stringtypes, etc.), while others just use the direct arrays. Let's say the WSDL for my reported web service http://localhost:3333/Service.asmx?wsdllooks something like this:

POST /Service.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/webservices/DoSomething"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <DoSomething xmlns="http://tempuri.org/webservices">
      <anId>int</anId>
      <action>string</action>
      <parameters>
        <Param>
          <Value>string</Value>
          <Name>string</Name>
        </Param>
        <Param>
          <Value>string</Value>
          <Name>string</Name>
        </Param>
      </parameters>
    </DoSomething>
  </soap:Body>
</soap:Envelope>

My first PHP attempt looks like this:

<?php
require_once('lib/nusoap.php');
$client = new nusoap_client('http://localhost:3333/Service.asmx?wsdl');

$params = array(
    'anId' => 3, //new soapval('anId', 'int', 3),
    'action' => 'OMNOMNOMNOM',
    'parameters' => array(
        'firstName' => 'Scott',
        'lastName' => 'Smith'
    )
);
$result = $client->call('DoSomething', $params, 'http://tempuri.org/webservices/DoSomething', 'http://tempuri.org/webservices/DoSomething');
print_r($result);
?>

, , Param , , , $array , - , WebMethod ( , DoSomething) - (int - 0, string - null ..).

PHP , Param?

+3
3

.

<?php
require_once('lib/nusoap.php');
$client = new nusoap_client('http://localhost:3333/Service.asmx?wsdl');

$params = array(
      'anId' => 3,
      'action' => 'OMNOMNOMNOM',
      'parameters' => array(
              'Param' => array(
                  array('Name' => 'firstName', 'Value' => 'Scott'),
                  array('Name' => 'lastName', 'Value' => 'Smith')
                       )
      )
);
$result = $client->call('DoSomething', array($params), 
                'http://tempuri.org/webservices/DoSomething', 
                'http://tempuri.org/webservices/DoSomething');
print_r($result);
?>
+6

, PHP5 SOAP.

$client = new SoapClient("some.wsdl");
$client->DoSomething($params);

.

http://se.php.net/soap

+3

SOAP:

    // Create a new soap client based on the service metadata (WSDL)
    $client = new SoapClient("http://some.wsdl",
        array('location' => 'http://127.0.0.100:80/IntegrationService/php'));

    $params = array();
    $params['lead']['Firstname']    = $user->firstname;
    $params['lead']['Lastname']     = $user->lastname;
    $params['lead']['Product']      = $product;
    $params['lead']['JobTitle']     = $user->job_title;
    $params['lead']['Email']        = $user->mail;
    $params['lead']['Phone']        = $user->phone;
    $params['lead']['CompanyName']  = $user->company_name;
    $params['lead']['City']         = $user->city;
    $params['lead']['Industry']     = $user->industry;

    $client->SubmitLead($params);

'.../IntegrationService/php' SoapClient ​​WCF:

<endpoint
            address="php"
            binding="basicHttpBinding"
            contract="Integration.Service.IDrupalIntegrationService" />
+1

Source: https://habr.com/ru/post/1699376/


All Articles