SOAP客户端 - 未找到类

时间:2018-02-09 15:13:04

标签: php laravel soap client integration

我在Laravel中使用SOAP客户端时遇到了问题。我想将销售人员/客户从商店发送到ERP系统。结构如下所示:在routes->web.php我调用我的控制器

Route::get('/show_orders', 'SalesOrdersController@store');

我创建了一个控制器SalesOrderController,它看起来像这样

<?php

namespace App\Http\Controllers;

class SalesOrdersController extends Controller
{
    private $soapClient;
    public function __construct()
    {
        $this->middleware('auth');

        $this->soapClient = app('soap_client_sales_order');
    }
    public function store()
    {

        $soapClient->__setLocation(env('BYD_DOMAIN') . $serviceUrl);

        $parameters['BasicMessageHeader'] = array(
            'ID' => '00000000000102dcade9bcb0aa000c68',
        );

        $parameters['Customer'] = array(
            'CategoryCode' => '1',
            'CustomerIndicator' => 'true',
            'Person' => array(
                'GivenName' => 'Frank',
                'FamilyName' => 'Sent',
            ),
        );

        $soapResult = $this->soapClient->MaintainBundle_V1($parameters);
    }
}

我创建了一个ServiceProvider SoapServiceProvider - 看起来像这样:

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class SoapServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('soap_client_sales_order', function () {
            $serviceUrl = '/sap/bc/srt/scs/sap/managecustomerin1';
            $wsdlPath = 'soap/managecustomerin1.wsdl';
            $soapClient = new \SoapClient(
                storage_path($wsdlPath),
                array(
                    'trace' => 1,
                    'soap_version' => SOAP_1_2,
                    'exceptions' => 1,
                    'login' => env('SOAP_USER'),
                    'password' => env('SOAP_PASSWORD'),
                )
            );
        });
        $soapClient->__setLocation(env('BYD_DOMAIN') . $serviceUrl);
        return $soapClient;
    }
}

当我拨打我的路线http://shop.test/show_orders时,我得到以下内容

  

异常:&#34;类soap_client_sales_order不存在&#34;

转储:

/home/vagrant/code/shop/vendor/laravel/framework/src/Illuminate/Container/Container.php
    }

    /**
     * Instantiate a concrete instance of the given type.
     *
     * @param  string  $concrete
     * @return mixed
     *
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
     */
    public function build($concrete)
    {
        // If the concrete type is actually a Closure, we will just execute it and
        // hand back the results of the functions, which allows functions to be
        // used as resolvers for more fine-tuned resolution of these objects.
        if ($concrete instanceof Closure) {
            return $concrete($this, $this->getLastParameterOverride());
        }

        $reflector = new ReflectionClass($concrete);

        // If the type is not instantiable, the developer is attempting to resolve
        // an abstract type such as an Interface of Abstract Class and there is
        // no binding registered for the abstractions so we need to bail out.
        if (! $reflector->isInstantiable()) {
            return $this->notInstantiable($concrete);
        }

        $this->buildStack[] = $concrete;

        $constructor = $reflector->getConstructor();

        // If there are no constructors, that means there are no dependencies then
        // we can just resolve the instances of the objects right away, without
        // resolving any other types or dependencies out of these containers.

希望你能给我一个提示。

谢谢,

马努

1 个答案:

答案 0 :(得分:0)

首先,您从未在$soapClient范围之外定义$app->singleton,因此$soapClient为空且错误singleton implementation,此处为official guide来自laravel docs,接下来就是return singleton scope里面的单身人士意味着这样的事情

/**
 * Register the application services.
 *
 * @return void
 */
public function register()
{
    $this->app->singleton('soap_client_sales_order', function () {
        ...
        ...

        $soapClient->__setLocation(env('BYD_DOMAIN') . $serviceUrl);
        return $soapClient;
    });
}