How to C# Soap Request Convert to PHP Code?

Viewed 152

I'm trying to integrate SOAP with PHP, but the example given is C #.

I've been trying for a long time, but I guess I couldn't send the parameters correctly.

WSDL Address : https://betatest.elogo.com.tr/webservice/PostBoxService.svc?singlewsdl

Example c# code;

using (PostBoxService.PostBoxServiceClient svc = new PostBoxService.PostBoxServiceClient()) { 
    PostBoxService.LoginType login = new PostBoxService.LoginType();
    login.userName = “test”;
    login.passWord = “test”; 
    
    string sessionId;
        if (svc.Login(login, out sessionId)) { 
        }
}

Example SOAP Request

<soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:tem="http://tempuri.org/"
    xmlns:efat="http://schemas.datacontract.org/2004/07/eFaturaWebService">
    <soapenv:Header/>
    <soapenv:Body>
        <tem:Login>
            <tem:login>
                <efat:appStr></efat:appStr>
                <efat:passWord>XXXXX</efat:passWord>
                <efat:source></efat:source>
                <efat:userName>XXXXX</efat:userName>
                <efat:version></efat:version>
            </tem:login>
        </tem:Login>
    </soapenv:Body>
</soapenv:Envelope>

I m PHP code;

                $data = array(
                    'login' => array(
                        'userName'=>self::username,
                        'password'=>self::password
                    )
                );
                $client = new SoapClient(self::url,$client_params);
                $client->Login($data);

It shows the following error in PHP code;


[previous:Exception:private] =>
    [faultstring] => String reference not set to an instance of a String.
Parameter name: s
    [faultcode] => a:InternalServiceFault
    [detail] => stdClass Object
        (
            [ExceptionDetail] => stdClass Object
                (
                    [HelpLink] =>
                    [InnerException] =>
                    [Message] => String reference not set to an instance of a String.
Parameter name: s
                    [StackTrace] =>    at System.Text.Encoding.GetBytes(String s)
   at CommonLib.Helper.HelperLib.ComputeMd5Hash(String input)
   at CommonLib.Documents.LoginLogout.Login(LoginType login, String& sessionID)
   at SyncInvokeLogin(Object , Object[] , Object[] )
   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
                    [Type] => System.ArgumentNullException
                )

        )

Thank you very much for your help.

1 Answers

Your example SOAP request shows the password key is "passWord" (notice the capital W) but in your PHP you send "password". So there is nothing wrong with the PHP code except for the data array should be:

            $data = array(
                'login' => array(
                    'userName'=>self::username,
                    'passWord'=>self::password
                )
            );
Related