pluis3103 Posted September 19, 2012 at 04:31 PM Report #475904 Posted September 19, 2012 at 04:31 PM (edited) Boas, Preciso de uma ajuda com a utilização de webservices e nusoap. Estou a programar um site que tem de ir buscar informação a webservices. Nunca utilizei a classe nusoap e por isso estou com alguma dificuldade. Aqui fica o que necessito e o código que tenho: require_once('lib/nu-soap/nusoap.php'); $client = new nusoap_client('https://www.xxxxxxxxxxxxxxxx.pt/Rentway_Internacional_Reservations_WS/getGroups.asmx'); $err = $client->getError(); if ($err) { echo ' [b] Constructor error[/b] ' . $err . ''; } // Doc/lit parameters get wrapped $param = array( 'companyCode' => 9999, 'customerCode' => 10005 ); $result = $client->call('getGroups', array('parameters' => $param)); // Check for a fault if ($client->fault) { echo ' [b] Fault[/b] '; print_r($result); echo ''; } else { // Check for errors $err = $client->getError(); if ($err) { // Display the error echo ' [b] Error[/b] ' . $err . ''; } else { // Display the result echo ' [b] Result[/b] '; print_r($result); echo ''; } } echo ' [b] Request[/b] ' . htmlspecialchars($client->request, ENT_QUOTES) . ''; echo ' [b] Response[/b] ' . htmlspecialchars($client->response, ENT_QUOTES) . ''; echo ' [b] Debug[/b] ' . htmlspecialchars($client->debug_str, ENT_QUOTES) . ''; Os parametros são do webservice são: Request: companyCode e customerCode Response: errorCode, groups(dataset),GroupID,Group_Name,SIPP,Group_OrderToShow O request e o response que devo obter são os seguintes: POST /Rentway_Internacional_Reservations_WS/getGroups.asmx HTTP/1.1 Host: www.xxxxxxxxxxxxxxx.pt Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://www.xxxxxxxxxxxxxxx.pt/Rentway_Reservations_WS/getGroups/getGroups" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <getGroups xmlns="http://www.xxxxxxxxxxxxxxxxxxxx.pt/Rentway_Reservations_WS/getGroups"> <objRequest> <companyCode>string</companyCode> <customerCode>string</customerCode> </objRequest> </getGroups> </soap:Body> </soap:Envelope> HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <getGroupsResponse xmlns="http://www.xxxxxxxxxxxxxxxxxxxxx.pt/Rentway_Reservations_WS/getGroups"> <getGroupsResult> <errorCode>string</errorCode> <groups> <xsd:schema>schema</xsd:schema>xml</groups> </getGroupsResult> </getGroupsResponse> </soap:Body> </soap:Envelope> 1) Primeiro, o que utilizar na primeira linha? Se utilizar : $client = new nusoap_client('https://www.jimpisoft.pt/Rentway_Internacional_Reservations_WS/getGroups.asmx'); dá-me: Fault Array ( [faultcode] => soap:Server [faultstring] => Server was unable to process request. ---> Object reference not set to an instance of an object. [detail] => ) Se utilizar: $client = new nusoap_client('https://www.xxxxxxxxxxxxxxxxx.pt/Rentway_Internacional_Reservations_WS/getGroups.asmx','wsdl'); Dá-me: Error wsdl error: XML error parsing WSDL from https://www.xxxxxxxxxxxxxxxxxxxxxxxxxx.pt/Rentway_Internacional_Reservations_WS/getGroups.asmx on line 59: Mismatched tag Alguém me pode ajudar com isto? Edited September 20, 2012 at 07:32 AM by pluis3103
HappyHippyHippo Posted September 19, 2012 at 05:12 PM Report #475914 Posted September 19, 2012 at 05:12 PM (edited) tenta assim: $client = new nusoap_client('https://www.jimpisoft.pt/Rentway_Internacional_Reservations_WS/getGroups.asmx?wsdl', true); PS : desculpa, só agora que reparei no teu erro, ele encontrasse aqui: <getGroups xmlns="http://www.jimpisoft.pt/Rentway_Reservations_WS/getGroups"> <objRequest> <companyCode>string</companyCode> <customerCode>string</customerCode> </objRequest> </getGroups> no entanto tu estas a dar o nome : "parameters" $param = array( 'companyCode' => 9999, 'customerCode' => 10005 ); $result = $client->call('getGroups', array('parameters' => $param)); para resolver o teu problema basta alterar a chamada do webservice desta forma: $param = array( 'companyCode' => 9999, 'customerCode' => 10005 ); $result = $client->call('getGroups', array('objRequest' => $param)); Edited September 19, 2012 at 05:48 PM by HappyHippyHippo IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
pluis3103 Posted September 19, 2012 at 09:22 PM Author Report #475937 Posted September 19, 2012 at 09:22 PM Em 9/19/2012 às 18:12, HappyHippyHippo disse: tenta assim: $client = new nusoap_client('https://www.jimpisoft.pt/Rentway_Internacional_Reservations_WS/getGroups.asmx?wsdl' true); PS : desculpa, só agora que reparei no teu erro, ele encontrasse aqui: no entanto tu estas a dar o nome : "parameters" para resolver o teu problema basta alterar a chamada do webservice desta forma: $param = array( 'companyCode' => 9999, 'customerCode' => 10005 ); $result = $client->call('getGroups', array('objRequest' => $param)); Muito obrigado, grande ajuda mesmo. É isso mesmo. Já agora aproveito para te perguntar como extraio isto? Sabes? Result Array ( [getGroupsResult] => Array ( [groups] => Array ( [schema] => Array ( [element] => Array ( [complexType] => Array ( [choice] => Array ( [element] => Array ( [complexType] => Array ( [sequence] => Array ( [element] => Array ( [0] => Array ( [!name] => GroupID [!minOccurs] => 0 ) [1] => Array ( [!name] => Group_Name [!minOccurs] => 0 ) [2] => Array ( [!name] => SIPP [!minOccurs] => 0 ) [3] => Array ( [!name] => Group_OrderToShow [!minOccurs] => 0 ) ) ) ) [!name] => Table ) [!minOccurs] => 0 [!maxOccurs] => unbounded ) ) [!name] => Groups [!msdata:IsDataSet] => true [!msdata:UseCurrentLocale] => true ) [!id] => Groups ) [diffgram] => Array ( [Groups] => Array ( [Table] => Array ( [0] => Array ( [GroupID] => 01 [Group_Name] => Group 01 [sIPP] => SIP01 [Group_OrderToShow] => 3 [!diffgr:id] => Table1 [!msdata:rowOrder] => 0 ) [1] => Array ( [GroupID] => A [Group_Name] => GROUP A [sIPP] => ADMR [Group_OrderToShow] => 17 [!diffgr:id] => Table2 [!msdata:rowOrder] => 1 ) [2] => Array ( [GroupID] => ANGO [Group_Name] => ANGOLA [sIPP] => [Group_OrderToShow] => 18 [!diffgr:id] => Table3 [!msdata:rowOrder] => 2 ) [3] => Array ( [GroupID] => B [Group_Name] => GROUP B [sIPP] => BDMR [Group_OrderToShow] => 19 [!diffgr:id] => Table4 [!msdata:rowOrder] => 3 ) [4] => Array ( [GroupID] => C [Group_Name] => GROUP C [sIPP] => CCMR [Group_OrderToShow] => 20 [!diffgr:id] => Table5 [!msdata:rowOrder] => 4 ) [5] => Array ( [GroupID] => F [Group_Name] => GROUP F [sIPP] => [Group_OrderToShow] => 54 [!diffgr:id] => Table6 [!msdata:rowOrder] => 5 ) [6] => Array ( [GroupID] => FVMD [Group_Name] => Group FVMD [sIPP] => SIP01 [Group_OrderToShow] => 69 [!diffgr:id] => Table7 [!msdata:rowOrder] => 6 ) [7] => Array ( [GroupID] => Z [Group_Name] => GROUP Z [sIPP] => Z [Group_OrderToShow] => 154 [!diffgr:id] => Table8 [!msdata:rowOrder] => 7 ) ) ) ) ) ) )
HappyHippyHippo Posted September 19, 2012 at 11:16 PM Report #475948 Posted September 19, 2012 at 11:16 PM não faço ideia para que serve o webservice. se ele não é teu deverias ao menos saber para que serve ... IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
pluis3103 Posted September 20, 2012 at 07:30 AM Author Report #475961 Posted September 20, 2012 at 07:30 AM não faço ideia para que serve o webservice. se ele não é teu deverias ao menos saber para que serve ... Eu sei para que serve, não fiz bem foi a pergunta, mas já me safei 🙂 Muito obrigado pela ajuda.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now