Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How do i create this specific xml output by SOAP using SoapHeader and __setSoapHeaders? I can't do the same XML like i want. i don't want this ns1 and ns2 in envelope tag, and in header i need this Action SOAP-ENV:mustUnderstand="1" ...

This is my code:

try{

    $client = new SoapClient('https://thesite.com.br/wcf/SvcContratos.svc?wsdl', array('trace' => 1,'use' => SOAP_LITERAL));

    $usuario='user_1';
    $senha='1234';
    $tipo='1';  

    $header = new SoapHeader("http://schemas.microsoft.com/ws/2005/05/addressing/none","Action", "http://tempuri.org/ISvcContratos/GerarToken");
    $client->__setSoapHeaders($header); 


    $params = new SoapVar("<objLogin xmlns:d4p1='http://schemas.datacontract.org/2004/07/EPFWeb.Repository.Default.WCF' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'><d4p1:DsSenha>".$senha."</d4p1:DsSenha><d4p1:DsUsuario>".$usuario."</d4p1:DsUsuario><d4p1:IdTipoConsulta>".$tipo."</d4p1:IdTipoConsulta></objLogin>", XSD_ANYXML);

    $data = $client->GerarToken($params);

    echo $client->__getLastRequest();

}catch(SoapFault $fault){ 

    echo $client->__getLastRequest()."<br>".$fault->getMessage(); 
} 

With this php code i had this wrong XML:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/" xmlns:ns2="http://schemas.microsoft.com/ws/2005/05/addressing/none">
    <SOAP-ENV:Header>
        <ns2:Action>http://tempuri.org/ISvcContratos/GerarToken</ns2:Action>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <GerarToken>
            <objLogin xmlns:d4p1='http://schemas.datacontract.org/2004/07/EPFWeb.Repository.Default.WCF' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
                <d4p1:DsSenha>1234</d4p1:DsSenha>
                <d4p1:DsUsuario>user_1</d4p1:DsUsuario>
                <d4p1:IdTipoConsulta>1</d4p1:IdTipoConsulta>
            </objLogin>
        </GerarToken>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

I need to send this XML by soap:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/ISvcContratos/GerarToken</Action>
  </s:Header>
  <s:Body>
    <GerarToken xmlns="http://tempuri.org/">
      <objLogin xmlns:d4p1="http://schemas.datacontract.org/2004/07/EPFWeb.Repository.Default.WCF" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <d4p1:DsSenha>1234</d4p1:DsSenha>
        <d4p1:DsUsuario>USER_1</d4p1:DsUsuario>
        <d4p1:IdTipoConsulta>1</d4p1:IdTipoConsulta>
      </objLogin>
    </GerarToken>
  </s:Body>
</s:Envelope>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
288 views
Welcome To Ask or Share your Answers For Others

1 Answer

well, finally I got an affirmative answer from the server, which opens the doors for me now to try to consume the wsdl follows below the code that I used to solve the problem:

try{


    $client = new SoapClient('https://thesite.com.br/wcf/SvcContratos.svc?wsdl', array('trace' => 1,'use' => SOAP_LITERAL, 'style' => SOAP_DOCUMENT,));

    $usuario='user_1';
    $senha='1234';


    $params = new SoapVar("<GerarToken  xmlns='http://tempuri.org/'><objLogin xmlns:d4p1='http://schemas.datacontract.org/2004/07/EPFWeb.Repository.Default.WCF' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'><d4p1:DsUsuario>".$usuario."</d4p1:DsUsuario><d4p1:DsSenha>".$senha."</d4p1:DsSenha><d4p1:IdTipoConsulta>Data</d4p1:IdTipoConsulta></objLogin></GerarToken>", XSD_ANYXML); 
    $data = $client->GerarToken($params);

    $xml = json_decode(json_encode($data),true);
    print_r($xml);

    echo $client->__getLastRequest();

}catch(SoapFault $fault){ 

    echo $client->__getLastRequest()."<br>".$fault->getMessage(); 
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...