• Hello,

    I’m developing a WordPress plugin to access an ASP.Net SOAP service.

    For some reason the ASP server does not like the ns1
    <ns1:User_Credentials>

    even though it’s bound properly:

    xmlns:ns1="https://www...

    but prefers

    <User_Credentials xmlns="https://www...

    I don’t see any option to control this.

    Just wondering if there are any other plugin developers that have experience with using SOAP to talk to an ASP.NET server in a WordPress plugin.

    From the headers received it’s a :

    
    Server: Microsoft-IIS/8.5
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    
Viewing 9 replies - 1 through 9 (of 9 total)
  • Dion

    (@diondesigns)

    PHP has an easy way to communicate with a SOAP server:

    https://secure.php.net/manual/en/book.soap.php

    The SOAP extension must be installed for this to work; you can check the PHP info page or type php -m at the command line to verify.

    Thread Starter Ken Stone

    (@wpstoneblue)

    Hi DionDesigns,

    Yes I’m using

    
    $client = new SoapClient($wsdl,
                                    array(
                                            'trace' => 1,
                                            'cache_wsdl' => WSDL_CACHE_NONE,
                                            'soap_version' => SOAP_1_2
                                    ));
    

    
      $authvalues = new SoapVar($User_Credentials, SOAP_ENC_OBJECT);
    

    
     $header = new SoapHeader($tns, 'User_Credentials', $authvalues, false);
    

    
     $client->__setSoapHeaders(array($header));
    
    

    
    $soapResponse = $client->Is_Alive();
    $lastRespHeaders = $client->__getLastResponseHeaders();
    $lastResquest = $client->__getLastRequest();
    $lastResponse = $client->__getLastResponse();
    
    

    but microsoft is not accepting ns1

    Thread Starter Ken Stone

    (@wpstoneblue)

    If I use the online https://wsdlbrowser.com/
    and enter the WSDL is also creates XML with the ns1 bound to the xmlns

    So I would think the ASP server should accept it but it doesn’t.

    • This reply was modified 6 years, 8 months ago by Ken Stone.
    Thread Starter Ken Stone

    (@wpstoneblue)

    Got it working:

    I removed the soapvar from the header and just use the PHP class straight away.

    The difference is that now

     
    <env:Header>
    <ns1:User_Credentials>
    <ns1:str_Username>jklsafdljk</ns1:str_Username>
    <ns1:str_Password>jkasdjl</ns1:str_Password>
    </ns1:User_Credentials>
    </env:Header>
    

    ns1 is also on the username and password
    where previously it was not:

    
    <SOAP-ENV:Header>
    <ns1:User_Credentials>
    <str_Username>asdasdasd</str_Username>
    <str_Password>asdasdads</str_Password>
    </ns1:User_Credentials>
    </SOAP-ENV:Header>
    

    I got a clue from a google search result. I didn’t even click through but I saw ‘you don’t have to use a soapvar in the header you can use a regular php class’. At this point I was willing to try anything…

    So I immediately did

    
    //$header = new SoapHeader($tns, 'User_Credentials', $authvalues, false);
    $header = new SoapHeader($tns, 'User_Credentials', $User_Credentials, false);
    
    • This reply was modified 6 years, 8 months ago by Ken Stone.
    Dion

    (@diondesigns)

    I haven’t needed to access a SOAP server in a couple years, but I remember having all sorts of problems until I added the following line to php.ini and restarting php-fpm:

    soap.wsdl_cache_enabled=0
    

    Maybe that will be of some help to you.

    Thread Starter Ken Stone

    (@wpstoneblue)

    At this point though I’m wondering since the online SOAP client at wsdlbrowser.com created the same XML as the PHP code based on the WSDL file if there is some issue with the WSDL file?

    Thread Starter Ken Stone

    (@wpstoneblue)

    Hi Dion,

    I have:

    
    'cache_wsdl' => WSDL_CACHE_NONE,
    

    in the instantiation of the soap client.

    Working now. but THANKS

    Thread Starter Ken Stone

    (@wpstoneblue)

    I have a similar issue now when calling a method that has parameters in the body.

    PHP SOAP is using xsi:type=”ns1… instead of adding ns1 to each value in the parameter object. Does anyone know if there is a way to modify this behavior?

    
    <SOAP-ENV:Body>
    <ns1:Process_Credit_Application xsi:type="ns1:obj_Credit_Application">
    <ApplicantIP>192.168.1.1</ApplicantIP>
    

    I think what is needed is:

    
    <SOAP-ENV:Body>
    <ns1:Process_Credit_Application>
    <ns1:obj_Credit_Application>
    <ns1:ApplicantIP>192.168.1.1</ns1:ApplicantIP>
    
    • This reply was modified 6 years, 8 months ago by Ken Stone.
    Thread Starter Ken Stone

    (@wpstoneblue)

    I still have no idea how to do it within the PHP SOAP library so I went ahead and just rolled my own XML for now.

    
    public function get_xml($method, $type, $data_assoc_array){
    
            $my_xml = '<ns1:' . $method . '><ns1:'. $type . '>';
    
            foreach($data_assoc_array as $key => $val){
                $my_xml .= '<ns1:' . $key . '>' . $val . '</ns1:' . $key . '>';
            }
    
            $my_xml .= '</ns1:' . $type . '></ns1:' . $method . '>';
    
            return $my_xml;
        }
    
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘SOAP XML ns1’ is closed to new replies.