..:: MX Studio Fóruns ::..: Como fazer um Webservice? - ..:: MX Studio Fóruns ::..

Jump to content

Publicidade




ATENÇÃO

Para evitar posts desnecessários e que não influam para o andamento e desenvolvimento do fórum, clique aqui e leia todas as regras.
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Como fazer um Webservice? Dúvida!!

#1 User is offline   Itasouza 

  • Group: Membros
  • Posts: 10
  • Joined: 30-October 06

Posted 31 October 2006 - 05:23 PM

Boa Tarde

Estou seguindo os exemplos do tutorial do alex criando um webservice e gostaria de saber com posso fazer.

fiz este exemplo:

<!---Função que vai selecionar os dados do banco--->
<cfcomponent>
<cffunction name="Selecionar" access="remote" returntype="any"
<cfquery name="Empresa" Datasource="Financeiro">
Select *
FROM Empresa
order by CadEmpresa
</query>
</cfreturn Empresa>
</cffunction>
</cfcomponent>


Gostaria se possível de saber como se faz um webservice para uma entidade: empresa
Que eu possa incluir, remover, atualizar, selecionar, tudo no mesmo componente, sei que esta e a próxima matéria do Alex, mais estou precisando estuda este conteúdo no momento.
Preciso de um exemplo para seguir!!

Agradeço!!

0

#2 User is offline   pcsilva 

  • Group: Moderadores
  • Posts: 1940
  • Joined: 23-January 05

Posted 01 November 2006 - 04:54 AM

blink.gif
http://localhost/cfusion/application/wsdl/...mpresa.cfc?wsdl

ColdFusion
<cfcomponent name="Empresas" extends="application.cfc.security.User">


<cfset this.assessor = "" >
<cfset this.inicializado = false >


<cffunction name="init" returntype="void" access="remote">

<cfargument name="username" type="string" required="true">
<cfargument name="password" type="string" required="true">
<cfargument name="tipo" type="string" required="true" hint="seus valore podem ser clientes,rh,compras,vendas,patrimonio....">

<cfif Autentica(arguments.username,arguments.password)>
<cftry>
<cfset this.assessor = createobject("component","application.cfc.operacoes.#arguments.tipo#").init() >
<cfset this.inicializado = true >
<cfcatch type="coldfusion.runtime.CfJspPage$NoSuchTemplateException">
<cfset this.inicializado = false >
</cfcatch>
<cfcatch type="coldfusion.runtime.TemplateProxy$InvalidMethodNameException">
<cfset this.inicializado = false >
</cfcatch>
</cftry>
</cfif>

</cffunction>



<cffunction name="get" returntype="query" access="remote">

<cfargument name="complex" required="true" type="any">

<cfset var Selecionar = "*">
<cfset var Criticar = false >
<cfif this.inicializado AND IsValidSession()>

<cfif IsStruct(arguments.complex)>

<cfif IsDefined("arguments.complex.itens") AND IsArray(arguments.complex.itens) AND ArrayLen(arguments.complex.itens)>
<cfset Selecionar = arguments.complex.itens>
</cfif>

<cfif IsDefined("arguments.complex.critica") AND IsStruct(arguments.complex.critica)>
<!--- arguments.complex.critica[coluna] = valor_para_critica --->
<cfset camposSelecionados = arguments.complex.critica>
</cfif>

</cfif>
<cftry>
<cfreturn this.assessor.get(Selecionar,Criticar)>
<cfcatch type="coldfusion.runtime.TemplateProxy$InvalidMethodNameException"></cfcatch>
<cfcatch type="coldfusion.xml.rpc.ServiceProxy$ServiceInvocationException"></cfcatch>
<cfcatch type="coldfusion.runtime.UDFMethod$InvalidArgumentTypeException"></cfcatch>
</cftry>
</cfif>
<cfreturn QueryNew("")>

</cffunction>


<cffunction name="set" returntype="boolean" access="remote">

<!--- arguments.complex[coluna] = valor --->
<cfargument name="complex" type="struct" required="true">
<cfargument name="isUpdate" type="boolean" required="true">

<cfif this.inicializado AND IsValidSession()>
<cfif arguments.isUpdate>
<cftry>
<cfreturn this.assessor.update(arguments.complex)>
<cfcatch type="coldfusion.runtime.TemplateProxy$InvalidMethodNameException"></cfcatch>
<cfcatch type="coldfusion.xml.rpc.ServiceProxy$ServiceInvocationException"></cfcatch>
<cfcatch type="coldfusion.runtime.UDFMethod$InvalidArgumentTypeException"></cfcatch>
</cftry>
</cfif>
<cftry>
<cfreturn this.assessor.add(arguments.complex)>
<cfcatch type="coldfusion.runtime.TemplateProxy$InvalidMethodNameException"></cfcatch>
<cfcatch type="coldfusion.xml.rpc.ServiceProxy$ServiceInvocationException"></cfcatch>
<cfcatch type="coldfusion.runtime.UDFMethod$InvalidArgumentTypeException"></cfcatch>
</cftry>
</cfif>
<cfreturn false>

</cffunction>



<cffunction name="remove" returntype="boolean" access="remote">

<cfargument name="id" type="numeric" required="true">

<cfif this.inicializado AND IsValidSession()>
<cftry>
<cfreturn this.assessor.del(arguments.id)>
<cfcatch type="coldfusion.runtime.TemplateProxy$InvalidMethodNameException"></cfcatch>
<cfcatch type="coldfusion.xml.rpc.ServiceProxy$ServiceInvocationException"></cfcatch>
<cfcatch type="coldfusion.runtime.UDFMethod$InvalidArgumentTypeException"></cfcatch>
</cftry>
</cfif>
<cfreturn false>

</cffunction>


<cffunction name="prepareCall" returntype="any" access="remote">

<cfargument name="username" type="string" required="true">
<cfargument name="password" type="string" required="true">
<cfargument name="tipo" type="string" required="true" hint="seus valore podem ser clientes,rh,compras,vendas,patrimonio....">
<cfargument name="action" type="string" required="true" >
<cfargument name="param" type="any" required="true" >

<cfset var obj = "">
<cfset var metodo = "">
<cfif Autentica(arguments.username,arguments.password)>
<cftry>
<cfset obj = createobject("component","application.cfc.operacoes.#arguments.tipo#").init()>
<cfset metodo = obj[arguments.action]>
<cfif IsDefined("arguments.param")>
<cfreturn metodo(arguments.param)>
</cfif>
<cfreturn metodo()>
<cfcatch type="coldfusion.runtime.CfJspPage$NoSuchTemplateException"></cfcatch>
<cfcatch type="coldfusion.runtime.TemplateProxy$InvalidMethodNameException"></cfcatch>
<cfcatch type="coldfusion.runtime.UndefinedElementException"></cfcatch>
<cfcatch type="coldfusion.xml.rpc.ServiceProxy$ServiceInvocationException"></cfcatch>
<cfcatch type="coldfusion.runtime.UDFMethod$InvalidArgumentTypeException"></cfcatch>
</cftry>
</cfif>
<cfreturn false>

</cffunction>


</cfcomponent>


/var/www/application/cfc/security/User.cfc
ColdFusion
<cfcomponent name="User" alias="application.cfc.security.User">

<cffunction name="IsValidSession" returntype="boolean" access="private" >

<cfif IsDefined("Session.clienteID") AND isValid("uuid", Session.clienteID) >
<cfreturn true >
</cfif>
<cfreturn false >

</cffunction>


<cffunction name="Autentica" returntype="boolean" access="private" >

<cfargument name="username" type="string" required="true">
<cfargument name="password" type="string" required="true">

<!---
<cfquery name="isUser" datasource="mxstudio">
select password from users where user = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.username#">
</cfquery>

<cfif Not isUser.recordcount OR isUser.password neq arguments.password>
<cfreturn false >
</cfif>
--->
<cfset Session.clienteID = CreateUUID() >
<cfreturn true >

</cffunction>

</cfcomponent>



/var/www/application/cfc/operacoes/cliente.cfc
ColdFusion
<cfcomponent name="cliente" alias="application.cfc.operacoes.cliente">

<cffunction name="init" returntype="any" access="public">
<cfreturn this>
</cffunction>

<cffunction name="get" returntype="query" access="public">
<cfreturn QueryNew("")>
</cffunction>

<cffunction name="update" returntype="boolean" access="public">
<cfreturn true>
</cffunction>

<cffunction name="add" returntype="boolean" access="public">
<cfreturn true>
</cffunction>

<cffunction name="remove" returntype="boolean" access="public">
<cfreturn true>
</cffunction>

<cffunction name="isVip" returntype="boolean" access="public">
<cfreturn true>
</cffunction>


</cfcomponent>


/var/www/application/cfc/operacoes/rh.cfc
ColdFusion
<cfcomponent name="rh" alias="application.cfc.operacoes.rh">

<cffunction name="init" returntype="any" access="public">
<cfreturn this>
</cffunction>

<cffunction name="get" returntype="query" access="public">
<cfreturn QueryNew("")>
</cffunction>

<cffunction name="update" returntype="boolean" access="public">
<cfreturn true>
</cffunction>

<cffunction name="add" returntype="boolean" access="public">
<cfreturn true>
</cffunction>

<cffunction name="remove" returntype="boolean" access="public">
<cfreturn true>
</cffunction>

<cffunction name="bloquear" returntype="boolean" access="public">
<cfargument name="id" type="numeric" required="true">
<cfreturn arguments.id>
</cffunction>


</cfcomponent>


/var/www/Application.cfc
ColdFusion
<cfcomponent name="Application">

<cfset this.name = 'GerenciarEmpresa' />
<cfset this.sessionmanagement = true />
<cfset this.applicationtimeout = CreateTimeSpan(0,3,0,0) />
<cfset this.sessiontimeout = CreateTimeSpan(0,3,0,0) />

</cfcomponent>


/var/www/teste.cfm
ColdFusion

<cfset wsdl = CreateObject("webservice","http://localhost/application/wsdl/movimenta/Empresa.cfc?wsdl") >

<cfset wsdl.init('pcsilva','senha','rh') >
<cfdump var="#wsdl.get('all')#">
<cfdump var="#wsdl.prepareCall('pcsilva','senha','rh','bloquear',1)#">

<cfset wsdl.init('pcsilva','pcsilva','cliente') >
<cfdump var="#wsdl.get('all')#">
<cfdump var="#wsdl.prepareCall('pcsilva','senha','cliente','isVip','null')#">


huh.gif

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic


Similar Topics Collapse

  Topic Forum Started By Stats Last Post Info
New Replies OpenGL Photoshop CS4
como ativar
Photoshop & Image Ready Bruce Gui 
  • 5 Replies
  • 3592 Views
New Replies paginação php/mysql
como faço para separar as mensagens
PHP juninhoguitarr 
  • 1 Reply
  • 1615 Views
New Replies Album de Fotos
Como criar uma galeria de imagens.
Flash & ActionScript André Balieiro 
  • 1 Reply
  • 812 Views
New Replies Saiba como integrar o Outlook 2007 e o Messenger Notícias Notícias 
  • 0 Replies
  • 682 Views
New Replies Como se faz? Fireworks reizin 
  • 3 Replies
  • 1238 Views
New Replies Problemas como prevFrames e NextFrames as3 [RESOLVIDO] Flash & ActionScript LucasCosta 
  • 5 Replies
  • 1595 Views
New Replies hitTest
Como estipular uma area?
Flash & ActionScript Nyto-RJ 
  • 12 Replies
  • 3098 Views
New Replies Como fazer uma pagina de busca
Necessidto de uma Busca por palavra interna no meu site mostrando pags
ASP e ASP.Net Designtroy 
  • 1 Reply
  • 1387 Views

Publicidade




2 User(s) are reading this topic
0 membro(s), 2 visitante(s) e 0 membros anônimo(s)