Page 1 of 1

php calling .net web service

Posted: Tue Jan 27, 2009 5:08 pm
by yacahuma
Hello,

I really need help on this, and quickly. I am trying to call .net webservices using soap. I have no problem calling services without a header. But If i need to call a service with a header, it does not work. Using visual studio, the person that receives the request get an empty header , so obviously , my request die. I am setting the header as specified in different sites. but they just don't work. What I hate even more if that I get the. "It works in .net and java", ie. php is junk not use it. I hate that!!

For what I can see(so many post), php has not done a very good job when it relates to the headers.

Option 1

Code: Select all

 
 
$SessionKey  = new SOAPHeader($ns, 'SessionKey', $LoginResponse->LoginResult->SessionKey);
$SessionRole = new SOAPHeader($ns, 'SessionRole',$LoginResponse->LoginResult->SessionRole);
$UserType    = new SOAPHeader($ns, 'UserType', $LoginResponse->LoginResult->UserType);
$UserName    = new SOAPHeader($ns, 'UserName',$LoginResponse->LoginResult->UserName);
$headers = array($SessionKey, $SessionRole, $UserType, $UserName);
 
$this->soapClient->__setSoapHeaders($headers);       
 
Option2

Code: Select all

 
 
 $authvalues = new SoapVar($AuthHeader,SOAP_ENC_OBJECT);
$ns = 'name space here';
$header =  new SoapHeader($ns, 
                                "AuthHeader", // Rename this to the tag you need
                                 $authvalues, 
                                 false);
 
The guy from .net tells me tha he does not have to worry about the header, that .net does that automatically. So the complexity of creating header objects, is hidden from them.

Re: php calling .net web service

Posted: Tue Jan 27, 2009 8:05 pm
by yacahuma
I solved my problem. It was in one of the note in php.net
I had to creat the header by myself

Code: Select all

 
$strHeaderComponent_Session = "<ns1:AuthHeader>"
."<ns1:SessionKey>{$LoginResponse->LoginResult->SessionKey}</ns1:SessionKey>"
."<ns1:SessionRole>{$LoginResponse->LoginResult->SessionRole}</ns1:SessionRole>"
."<ns1:UserType>{$LoginResponse->LoginResult->UserType}</ns1:UserType>"
."<ns1:UserName>{$LoginResponse->LoginResult->UserName}</ns1:UserName>"
."</ns1:AuthHeader>";
 
$objVar_Session_Inside = new SoapVar($strHeaderComponent_Session, XSD_ANYXML, null, null, null);
$header = new SoapHeader($ns, 'AuthHeader', $objVar_Session_Inside);
     
     $this->soapClient->__setSoapHeaders(array($header)); 
 
the header will look like this
<SOAP-ENV:Header>
<ns1:AuthHeader>
<ns1:SessionKey>xxxxxx</ns1:SessionKey>
<ns1:SessionRole>xxxxxx</ns1:SessionRole>
<ns1:UserType>x</ns1:UserType>
<ns1:UserName>xxxxxx</ns1:UserName>
</ns1:AuthHeader>
</SOAP-ENV:Header>



BUT WHY, WHY, do I have to do this manually, and not in an OO way? I am sure I am missing something. BUT anyway with the option1 and 2 the request was like
</SOAP-ENV:Header>
<ns1:SessionKey>xxxxxx</ns1:SessionKey>
<ns1:SessionRole>xxxxxx</ns1:SessionRole>
<ns1:UserType>x</ns1:UserType>
<ns1:UserName>xxxxxx</ns1:UserName>
</SOAP-ENV:Header>

Notice, no AuthHeader. That's why it was failing.