通过B1WS将PHP与SAP B1集成

时间:2018-08-22 11:09:19

标签: php xml soap sap

我正在努力与SAP B1实例建立连接。 连接应通过B1WS进行管理。 我通过VPN连接,因此该地址未开放供公众访问。

我已经使用wsdl2generator生成了类。 我将位置设置为http://10.0.190.4/B1WS/Service.asmx-此处一切正常,此url正确显示了有关无效xml的信息,因为我已经阅读了此行为,还可以。 http://10.0.190.4/B1WS/WebReferences/LoginService.wsdl LoginService可以访问,它需要以下参数:

<s:element name="Login">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="DatabaseServer" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="DatabaseName" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="DatabaseType">
<s:simpleType>
<s:restriction base="s:string">
<s:enumeration value="dst_MSSQL" />
<s:enumeration value="dst_DB_2" />
<s:enumeration value="dst_SYBASE" />
<s:enumeration value="dst_MSSQL2005" />
<s:enumeration value="dst_MAXDB" />
</s:restriction>
</s:simpleType>
</s:element>
<s:element minOccurs="0" maxOccurs="1" name="CompanyUsername" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="CompanyPassword" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="Language">
<s:simpleType>
<s:restriction base="s:string">
<s:enumeration value="ln_Hebrew" />
<s:enumeration value="ln_Spanish_Ar" />
<s:enumeration value="ln_English" />
<s:enumeration value="ln_Polish" />
<s:enumeration value="ln_English_Sg" />
<s:enumeration value="ln_Spanish_Pa" />
<s:enumeration value="ln_English_Gb" />
<s:enumeration value="ln_German" />
<s:enumeration value="ln_Serbian" />
<s:enumeration value="ln_Danish" />
<s:enumeration value="ln_Norwegian" />
<s:enumeration value="ln_Italian" />
<s:enumeration value="ln_Hungarian" />
<s:enumeration value="ln_Chinese" />
<s:enumeration value="ln_Dutch" />
<s:enumeration value="ln_Finnish" />
<s:enumeration value="ln_Greek" />
<s:enumeration value="ln_Portuguese" />
<s:enumeration value="ln_Swedish" />
<s:enumeration value="ln_English_Cy" />
<s:enumeration value="ln_French" />
<s:enumeration value="ln_Spanish" />
<s:enumeration value="ln_Russian" />
<s:enumeration value="ln_Spanish_La" />
<s:enumeration value="ln_Czech_Cz" />
<s:enumeration value="ln_Slovak_Sk" />
<s:enumeration value="ln_Korean_Kr" />
<s:enumeration value="ln_Portuguese_Br" />
<s:enumeration value="ln_Japanese_Jp" />
<s:enumeration value="ln_Turkish_Tr" />
<s:enumeration value="ln_TrdtnlChinese_Hk" />
</s:restriction>
</s:simpleType>
</s:element>
<s:element minOccurs="0" maxOccurs="1" name="LicenseServer" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>

我的index.php文件:

<?php

ini_set('display_errors', 1);

require_once __DIR__ . '/vendor/autoload.php';
/**
 * Minimal options
 */
$options = array(
    \WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_URL => 'http://10.0.190.4/B1WS/WebReferences/LoginService.wsdl',
    \WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_CLASSMAP => ClassMap::get(),
    \WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_TRACE => true,
    \WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_LOCATION => 'http://10.0.190.4/B1WS/Service.asmx',
    \WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_EXCEPTIONS => true,
    \WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_ENCODING => 'UTF-8',
    \WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_LOGIN => 'username',
    \WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_PASSWORD => 'password',

);
/**
 * Samples for Login ServiceType
 */
$login = new \ServiceType\Login($options);
/**
 * Sample call for Login operation/method
 */


echo "<pre>";
if ($login->Login(new \StructType\Login("10.0.190.3", "databaseName", \EnumType\DatabaseType::VALUE_DST_MSSQL, "companyUsername", "companyPassword", \EnumType\Language::VALUE_LN_ENGLISH,  "10.0.190.4:30000")) !== false) {
    echo 'success' . PHP_EOL;
} else {
    print_r($login->getLastError());
}

操作登录返回了我无效的XML行号= 2,列号= 1,说明=无效的文档结构。

文件ServiceType / Login.php(由wsdl2phpgenerator自动生成):

<?php

namespace ServiceType;

use \WsdlToPhp\PackageBase\AbstractSoapClientBase;

/**
 * This class stands for Login ServiceType
 * @subpackage Services
 */
class Login extends AbstractSoapClientBase
{
    /**
     * Method to call the operation originally named Login
     * @uses AbstractSoapClientBase::getSoapClient()
     * @uses AbstractSoapClientBase::setResult()
     * @uses AbstractSoapClientBase::getResult()
     * @uses AbstractSoapClientBase::saveLastError()
     * @param \StructType\Login $parameters
     * @return \StructType\LoginResponse|bool
     */
    public function Login(\StructType\Login $parameters)
    {
        try {
            $this->setResult($this->getSoapClient()->Login($parameters));
            return $this->getResult();
        } catch (\SoapFault $soapFault) {
            $this->saveLastError(__METHOD__, $soapFault);
            return false;
        }
    }
    /**
     * Returns the result
     * @see AbstractSoapClientBase::getResult()
     * @return \StructType\LoginResponse
     */
    public function getResult()
    {
        return parent::getResult();
    }
    /**
     * Method returning the class name
     * @return string __CLASS__
     */
    public function __toString()
    {
        return __CLASS__;
    }
}

Filee StructType / Login.php:

<?php

namespace StructType;

use \WsdlToPhp\PackageBase\AbstractStructBase;

/**
 * This class stands for Login StructType
 * @subpackage Structs
 */
class Login extends AbstractStructBase
{
    /**
     * The DatabaseServer
     * Meta informations extracted from the WSDL
     * - maxOccurs: 1
     * - minOccurs: 0
     * @var string
     */
    public $DatabaseServer;
    /**
     * The DatabaseName
     * Meta informations extracted from the WSDL
     * - maxOccurs: 1
     * - minOccurs: 0
     * @var string
     */
    public $DatabaseName;
    /**
     * The DatabaseType
     * Meta informations extracted from the WSDL
     * - maxOccurs: 1
     * - minOccurs: 0
     * @var string
     */
    public $DatabaseType;
    /**
     * The CompanyUsername
     * Meta informations extracted from the WSDL
     * - maxOccurs: 1
     * - minOccurs: 0
     * @var string
     */
    public $CompanyUsername;
    /**
     * The CompanyPassword
     * Meta informations extracted from the WSDL
     * - maxOccurs: 1
     * - minOccurs: 0
     * @var string
     */
    public $CompanyPassword;
    /**
     * The Language
     * Meta informations extracted from the WSDL
     * - maxOccurs: 1
     * - minOccurs: 0
     * @var string
     */
    public $Language;
    /**
     * The LicenseServer
     * Meta informations extracted from the WSDL
     * - maxOccurs: 1
     * - minOccurs: 0
     * @var string
     */
    public $LicenseServer;
    /**
     * Constructor method for Login
     * @uses Login::setDatabaseServer()
     * @uses Login::setDatabaseName()
     * @uses Login::setDatabaseType()
     * @uses Login::setCompanyUsername()
     * @uses Login::setCompanyPassword()
     * @uses Login::setLanguage()
     * @uses Login::setLicenseServer()
     * @param string $databaseServer
     * @param string $databaseName
     * @param string $databaseType
     * @param string $companyUsername
     * @param string $companyPassword
     * @param string $language
     * @param string $licenseServer
     */
    public function __construct($databaseServer = null, $databaseName = null, $databaseType = null, $companyUsername = null, $companyPassword = null, $language = null, $licenseServer = null)
    {
        $this
            ->setDatabaseServer($databaseServer)
            ->setDatabaseName($databaseName)
            ->setDatabaseType($databaseType)
            ->setCompanyUsername($companyUsername)
            ->setCompanyPassword($companyPassword)
            ->setLanguage($language)
            ->setLicenseServer($licenseServer);
    }
    /**
     * Get DatabaseServer value
     * @return string|null
     */
    public function getDatabaseServer()
    {
        return $this->DatabaseServer;
    }
    /**
     * Set DatabaseServer value
     * @param string $databaseServer
     * @return \StructType\Login
     */
    public function setDatabaseServer($databaseServer = null)
    {
        // validation for constraint: string
        if (!is_null($databaseServer) && !is_string($databaseServer)) {
            throw new \InvalidArgumentException(sprintf('Invalid value, please provide a string, "%s" given', gettype($databaseServer)), __LINE__);
        }
        $this->DatabaseServer = $databaseServer;
        return $this;
    }
    /**
     * Get DatabaseName value
     * @return string|null
     */
    public function getDatabaseName()
    {
        return $this->DatabaseName;
    }
    /**
     * Set DatabaseName value
     * @param string $databaseName
     * @return \StructType\Login
     */
    public function setDatabaseName($databaseName = null)
    {
        // validation for constraint: string
        if (!is_null($databaseName) && !is_string($databaseName)) {
            throw new \InvalidArgumentException(sprintf('Invalid value, please provide a string, "%s" given', gettype($databaseName)), __LINE__);
        }
        $this->DatabaseName = $databaseName;
        return $this;
    }
    /**
     * Get DatabaseType value
     * @return string|null
     */
    public function getDatabaseType()
    {
        return $this->DatabaseType;
    }
    /**
     * Set DatabaseType value
     * @uses \EnumType\DatabaseType::valueIsValid()
     * @uses \EnumType\DatabaseType::getValidValues()
     * @throws \InvalidArgumentException
     * @param string $databaseType
     * @return \StructType\Login
     */
    public function setDatabaseType($databaseType = null)
    {
        // validation for constraint: enumeration
        if (!\EnumType\DatabaseType::valueIsValid($databaseType)) {
            throw new \InvalidArgumentException(sprintf('Value "%s" is invalid, please use one of: %s', $databaseType, implode(', ', \EnumType\DatabaseType::getValidValues())), __LINE__);
        }
        $this->DatabaseType = $databaseType;
        return $this;
    }
    /**
     * Get CompanyUsername value
     * @return string|null
     */
    public function getCompanyUsername()
    {
        return $this->CompanyUsername;
    }
    /**
     * Set CompanyUsername value
     * @param string $companyUsername
     * @return \StructType\Login
     */
    public function setCompanyUsername($companyUsername = null)
    {
        // validation for constraint: string
        if (!is_null($companyUsername) && !is_string($companyUsername)) {
            throw new \InvalidArgumentException(sprintf('Invalid value, please provide a string, "%s" given', gettype($companyUsername)), __LINE__);
        }
        $this->CompanyUsername = $companyUsername;
        return $this;
    }
    /**
     * Get CompanyPassword value
     * @return string|null
     */
    public function getCompanyPassword()
    {
        return $this->CompanyPassword;
    }
    /**
     * Set CompanyPassword value
     * @param string $companyPassword
     * @return \StructType\Login
     */
    public function setCompanyPassword($companyPassword = null)
    {
        // validation for constraint: string
        if (!is_null($companyPassword) && !is_string($companyPassword)) {
            throw new \InvalidArgumentException(sprintf('Invalid value, please provide a string, "%s" given', gettype($companyPassword)), __LINE__);
        }
        $this->CompanyPassword = $companyPassword;
        return $this;
    }
    /**
     * Get Language value
     * @return string|null
     */
    public function getLanguage()
    {
        return $this->Language;
    }
    /**
     * Set Language value
     * @uses \EnumType\Language::valueIsValid()
     * @uses \EnumType\Language::getValidValues()
     * @throws \InvalidArgumentException
     * @param string $language
     * @return \StructType\Login
     */
    public function setLanguage($language = null)
    {
        // validation for constraint: enumeration
        if (!\EnumType\Language::valueIsValid($language)) {
            throw new \InvalidArgumentException(sprintf('Value "%s" is invalid, please use one of: %s', $language, implode(', ', \EnumType\Language::getValidValues())), __LINE__);
        }
        $this->Language = $language;
        return $this;
    }
    /**
     * Get LicenseServer value
     * @return string|null
     */
    public function getLicenseServer()
    {
        return $this->LicenseServer;
    }
    /**
     * Set LicenseServer value
     * @param string $licenseServer
     * @return \StructType\Login
     */
    public function setLicenseServer($licenseServer = null)
    {
        // validation for constraint: string
        if (!is_null($licenseServer) && !is_string($licenseServer)) {
            throw new \InvalidArgumentException(sprintf('Invalid value, please provide a string, "%s" given', gettype($licenseServer)), __LINE__);
        }
        $this->LicenseServer = $licenseServer;
        return $this;
    }
    /**
     * Method called when an object has been exported with var_export() functions
     * It allows to return an object instantiated with the values
     * @see AbstractStructBase::__set_state()
     * @uses AbstractStructBase::__set_state()
     * @param array $array the exported values
     * @return \StructType\Login
     */
    public static function __set_state(array $array)
    {
        return parent::__set_state($array);
    }
    /**
     * Method returning the class name
     * @return string __CLASS__
     */
    public function __toString()
    {
        return __CLASS__;
    }
}

我已经阅读了有关将编码自动添加到XML的问题。 我试图修复它,创建Custom SoapClient并重写__doRequest,但是在返回数据之前检查请求时,它只是纯文本,不是有效的XML文件。 也许我应该手动创建XML文件?

是否有人通过PHP通过B1WS成功连接到SAP并可以共享有关此问题的知识?

0 个答案:

没有答案