【问题标题】:SOAP Client - Class not foundSOAP 客户端 - 找不到类
【发布时间】:2018-07-20 09:34:12
【问题描述】:

我在 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 时,我得到以下信息

异常:“soap_client_sales_order 类不存在”

转储:

/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.

希望你能给我一个提示。

谢谢,

手动

【问题讨论】:

  • 你好顺便说一句:) - 不知道为什么这部分在我的帖子中被删掉了

标签: php laravel soap client integration


【解决方案1】:

首先你从来没有在$app-&gt;singleton 范围之外定义$soapClient,所以$soapClient 是空的,这是一个错误的singleton implementation,这是来自 laravel 文档的official guide,接下来是你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;
    });
}

【讨论】:

  • 只是一个提示。您不必复制所有 OP 的代码。只需添加您更改的内容并将 OP 指向该特定行
  • 感谢@Akintunde007,注意
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-01
  • 1970-01-01
  • 2013-04-04
  • 1970-01-01
  • 2014-02-14
  • 1970-01-01
相关资源
最近更新 更多