Solved

Send xml string to web service

Posted on 2013-01-17
6
1,335 Views
Last Modified: 2013-02-05
Hello friends,

I trying to send a xml string to a web service and i'm having trouble with sending..

My code is something like this:
LOCAL loBasicHttpBinding_IOrdensEnviadas AS "XML Web Service"
* LOCAL loBasicHttpBinding_IOrdensEnviadas AS "MSSOAP.SoapClient30"
* Do not remove or alter following line. It is used to support IntelliSense for your XML Web service.
*__VFPWSDef__: loBasicHttpBinding_IOrdensEnviadas = http://svr-vmstgbiz1.city.Fornecedor.net/SGP_WS/OrdensEnviadas.svc?wsdl , OrdensEnviadasService , BasicHttpBinding_IOrdensEnviadas
LOCAL loException, lcErrorMsg, loWSHandler
TRY
	&&loWSHandler = NEWOBJECT("WSHandler",IIF(VERSION(2)=0,"",HOME()+"FFC\")+"_ws3client.vcx")
	loWSHandler = NEWOBJECT("WSHandler", "C:\Program Files (x86)\Microsoft Visual FoxPro 9\Ffc\_ws3client.vcx")
	loBasicHttpBinding_IOrdensEnviadas = loWSHandler.SetupClient("http://svr-myserver.city.Fornecedor.net/SGP_WS/OrdensEnviadas.svc?wsdl", "OrdensEnviadasService", "BasicHttpBinding_IOrdensEnviadas")
	* Call your XML Web service here.  ex: leResult = loBasicHttpBinding_IOrdensEnviadas.SomeMethod()
	xmlSend = f_xmlText()
	leResult = loBasicHttpBinding_IOrdensEnviadas.RegistaLotesMovimentos(xmlSend)
	MSG(leResult)
CATCH TO loException
	lcErrorMsg="Error: "+TRANSFORM(loException.Errorno)+" - "+loException.Message
	DO CASE
	CASE VARTYPE(loBasicHttpBinding_IOrdensEnviadas)#"O"
		* Handle SOAP error connecting to web service
	CASE !EMPTY(loBasicHttpBinding_IOrdensEnviadas.FaultCode)
		* Handle SOAP error calling method
		lcErrorMsg=lcErrorMsg+CHR(13)+loBasicHttpBinding_IOrdensEnviadas.Detail
	OTHERWISE
		* Handle other error
	ENDCASE
	* Use for debugging purposes
	MSG(lcErrorMsg)
FINALLY
ENDTRY


PROCEDURE f_xmlText
LOCAL retxml
Text To retxml noshow textmerge
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Fornecedor.SGP.Services.OrdensEnviadas" xmlns:fin="http://schemas.datacontract.org/2004/07/Fornecedor.SGP.Services.Interfaces.OrdensEnviadas" xmlns:fin1="http://schemas.datacontract.org/2004/07/Fornecedor.SGP.Business.OrdensEnviadas">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:RegistaLotesMovimentos>
         <!--Optional:-->
         <urn:pedido>
            <fin:Lotes>
               <!--Zero or more repetitions:-->
               <fin1:LoteMovimentos>
                  <fin1:DataLiquidacao>2013-01-18T00:00:00+00:00</fin1:DataLiquidacao>
                  <fin1:IdMotivoISO>16</fin1:IdMotivoISO>
                  <fin1:IdentificadorIntervenientes>
                     <fin1:IdentificadorInterveniente>
                        <fin1:IdInterveniente>0</fin1:IdInterveniente>
                                                                                         <fin1:TipoInterveniente>1</fin1:TipoInterveniente>
                        <fin1:IntervenienteNome>INSTITUIÇÃO FINANCEIRA DE CRÉDITO, SA</fin1:IntervenienteNome>
                     </fin1:IdentificadorInterveniente>
                     <fin1:IdentificadorInterveniente>
                        <fin1:IdInterveniente>0</fin1:IdInterveniente>
                                                                                         <fin1:TipoInterveniente>2</fin1:TipoInterveniente>
                        <fin1:IntervenienteNome>INSTITUIÇÃO FINANCEIRA DE CRÉDITO, SA</fin1:IntervenienteNome>
                     </fin1:IdentificadorInterveniente>
                  </fin1:IdentificadorIntervenientes>
                  <fin1:Instrucaos>
                     <fin1:Instrucao>
                        <fin1:IdInstrucaoOrigem>141608</fin1:IdInstrucaoOrigem>
                        <fin1:IdInstrucao>0</fin1:IdInstrucao>
                        <fin1:IdOrdem>0</fin1:IdOrdem>
                        <fin1:Montante>6212.50</fin1:Montante>
                        <fin1:DestinatarioIBAN>PT5000387577148</fin1:DestinatarioIBAN>
                        <fin1:IdentificadorIntervenientes>
                           <fin1:IdentificadorInterveniente>
                              <fin1:IdInterveniente>0</fin1:IdInterveniente>
                              <fin1:TipoInterveniente>3</fin1:TipoInterveniente>
                              <fin1:IntervenienteNome>SOME GUY 1</fin1:IntervenienteNome>
                           </fin1:IdentificadorInterveniente>
                           <fin1:IdentificadorInterveniente>
                              <fin1:IdInterveniente>0</fin1:IdInterveniente>
                              <fin1:TipoInterveniente>4</fin1:TipoInterveniente>
                              <fin1:IntervenienteNome>SOME GUY 1</fin1:IntervenienteNome>
                           </fin1:IdentificadorInterveniente>
                        </fin1:IdentificadorIntervenientes>
                     </fin1:Instrucao>
                     <fin1:Instrucao>
                        <fin1:IdInstrucaoOrigem>141610</fin1:IdInstrucaoOrigem>
                        <fin1:IdInstrucao>0</fin1:IdInstrucao>
                        <fin1:IdOrdem>0</fin1:IdOrdem>
                        <fin1:Montante>9443.00</fin1:Montante>
                        <fin1:DestinatarioIBAN>PT5000100098000196</fin1:DestinatarioIBAN>
                        <fin1:IdentificadorIntervenientes>
                           <fin1:IdentificadorInterveniente>
                              <fin1:IdInterveniente>0</fin1:IdInterveniente>
                              <fin1:TipoInterveniente>3</fin1:TipoInterveniente>
                              <fin1:IntervenienteNome>SOME GUY 2</fin1:IntervenienteNome>
                           </fin1:IdentificadorInterveniente>
                           <fin1:IdentificadorInterveniente>
                              <fin1:IdInterveniente>0</fin1:IdInterveniente>
                              <fin1:TipoInterveniente>4</fin1:TipoInterveniente>
                              <fin1:IntervenienteNome>SOME GUY 2</fin1:IntervenienteNome>
                           </fin1:IdentificadorInterveniente>
                        </fin1:IdentificadorIntervenientes>
                     </fin1:Instrucao>
                     <fin1:Instrucao>
                        <fin1:IdInstrucaoOrigem>141611</fin1:IdInstrucaoOrigem>
                        <fin1:IdInstrucao>0</fin1:IdInstrucao>
                        <fin1:IdOrdem>0</fin1:IdOrdem>
                        <fin1:Montante>20990.31</fin1:Montante>
                        <fin1:DestinatarioIBAN>P00005011828747305</fin1:DestinatarioIBAN>
                        <fin1:IdentificadorIntervenientes>
                           <fin1:IdentificadorInterveniente>
                              <fin1:IdInterveniente>0</fin1:IdInterveniente>
                              <fin1:TipoInterveniente>3</fin1:TipoInterveniente>
                              <fin1:IntervenienteNome>SOME GUY 3</fin1:IntervenienteNome>
                           </fin1:IdentificadorInterveniente>
                           <fin1:IdentificadorInterveniente>
                              <fin1:IdInterveniente>0</fin1:IdInterveniente>
                              <fin1:TipoInterveniente>4</fin1:TipoInterveniente>
                              <fin1:IntervenienteNome>SOME GUY 3</fin1:IntervenienteNome>
                           </fin1:IdentificadorInterveniente>
                        </fin1:IdentificadorIntervenientes>
                     </fin1:Instrucao>
                  </fin1:Instrucaos>
                  <fin1:LoteOrigem>10000</fin1:LoteOrigem>
                  <fin1:MontanteTotal>36645.81</fin1:MontanteTotal>
                  <fin1:OrdenanteIBAN>PT50010100100009134</fin1:OrdenanteIBAN>
                  <fin1:Urgente>false</fin1:Urgente>
                  <fin1:ValorComissao>0</fin1:ValorComissao>
                  <fin1:ValorIS>0</fin1:ValorIS>
               </fin1:LoteMovimentos>
            </fin:Lotes>
            <fin:Origem>PHC</fin:Origem>
            <fin:UserName>DOMAIN\someduede</fin:UserName>
         </urn:pedido>
      </urn:RegistaLotesMovimentos>
   </soapenv:Body>
</soapenv:Envelope>
EndText
RETURN retxml

ENDPROC

Open in new window

If i test the webservice on the soapui app it works,  i grab that xml code inside the retxml variable and put it directly on the Request 1 on the RegistaLotesMovimentos method and works great.
Using that foxpro code i allways get xml structure error messages like this:
The InnerException message was 'Error in line 96 position 29. 'EndElement' 'pedido' from namespace 'urn:Fornecedor.SGP.Services.OrdensEnviadas' is not expected. 
Expecting element 'Lotes'.'.  Please see InnerException for more details...

Open in new window


Maybe i can't send the xml like that, i don't know.. does anyone knows the best way to send strings with xml directly to the web services methods?

Thx in advanced
0
Comment
Question by:justaphase
  • 2
  • 2
  • 2
6 Comments
 
LVL 16

Expert Comment

by:theo kouwenhoven
ID: 38792115
Hi justaphase,

Did you use the target WSDL for testing the XML message?

It looks like that the webservicehost, expext a required element .
The message tells you that a <Lotes> tag is expected where you defined a </pedido>

An other possibility is that the server has some problems with the 'ÇÃÉ' contents of <IntervenienteNome> If it''s UTF-8 encoding, and you don't send the UTF-Characters then the results can pe unpredictable.

http://en.wikipedia.org/wiki/UTF-8
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 38792117
No, as the comment says you should Call your XML Web service here.  ex: leResult = loBasicHttpBinding_IOrdensEnviadas.SomeMethod()

It will generate and send the xml and retrieve the xml answer and extract the result for you, that's what this wrapper is all about, saving you this low level stuff.

Bye, Olaf.
0
 
LVL 16

Expert Comment

by:theo kouwenhoven
ID: 38792142
The xml structure error is generated by the WebserviceHost, that process don't agree with the data you send:

The return data (error) tells you 3 tings:
- 'EndElement' 'pedido'  is not expected.
- Expecting element 'Lotes'
- Please see InnerException for more details

did you check the 'InnerException'
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Accepted Solution

by:
justaphase earned 0 total points
ID: 38839943
Since i couldn't find a answer here I bought a plugin from chilkat software.

Thx anyway
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 38841252
Never mind, but you also didn't came back to this.

You didn't get at all what the registering of a web service does for you, you don't need to pt together XML, send it, receive it and extract a result from it, like you also don't need to put together HTTP requests sending them via winsock, receiving responses and rendring the HTML etc coming back, for browsing a website. You use a browser instead.

And for using web services you use VFPs WSHandler.

Try this:
loWSHandler = NEWOBJECT("WSHandler",IIF(VERSION(2)=0,"",HOME()+"FFC\")+"_ws3client.vcx")
loGBNIRHolidayDates = loWSHandler.SetupClient("http://www.holidaywebservice.com/Holidays/GBNIR/Dates/GBNIRHolidayDates.asmx?WSDL", "GBNIRHolidayDates", "GBNIRHolidayDatesSoap")
* Call your XML Web service here.  ex: leResult = loGBNIRHolidayDates.SomeMethod() && don't take "SomeMethod" literally...
ltEastern2013 = loGBNIRHolidayDates.GetEaster(2013)
? ltEastern2013

Open in new window

This is essentially the beginning of your code, code the Task Pane generates, when you register a web service. I just removed error handling via try catch. Behind the scenes XML (Soap XML) is sent to www.holidaywebservice.com and eastern 2013 is computed and returned in XML, which is then evaluated to a VFP DateTime.

You can compare this to a class you use, that is instanciated remotely, but the usage is local. All the upper lines before ltEastern2013 = loGBNIRHolidayDates.GetEaster(2013) are just the instanciation of the loGBNIRHolidayDates object. So the only thing different from the usage of any local normal class is, that the initialisation is a bit more complicated. Assume you had a VFP class computing eastern by a method called GetEaster(nYear). Assume this class is called holidaydates, then you'd use it via:

loGBNIRHolidayDates= CreateObject("holidaydates")
ltEastern2013 = loGBNIRHolidayDates.GetEaster(2013)
? ltEastern2013

Open in new window

Do you see how the final two lines - the usage of the class or the web service - don't differ? A web service merely is a remotely running instance of a class with methods and only has a more complicated initialisation process and communication.

Unfortunately that doesn't work with any webservice, because that's how it is with standards. They would be fine, if there wouldn't be so many of them.

I have to assume the documentation of the web service you are now finally using is very awful. Sorry to hear so late from you only, but instead of ignoring our answers you could have asked, what I meant. You perhaps really just missed one line of code to use one method of the webservice. May a few lines, if several methods. Like with any normal created object, of course you don't need to go through initialisation once for each method call.

So what lines need to follow after loBasicHttpBinding_IOrdensEnviadas=loWSHandler.SetupClient(...) is depending on what methods the web service offers and what you want to use. You could also ask what to do after creating oObj = CreateObject("class"), that depends on the class. All you need to know is what methods the class has, and how they are parameterizd and what they return. And the same goes for a web service.

Do you see a light at the end of the tunnel now?

Without knowing what exactly you have put together now, I congratulate you to what you have achieved. It can easily compare to putting together a webbrowser with sockets sending and receiving http protocol messages and rendering a result. But in the same way you don't need to know what a webbrowser sends out to a webserver to get a web page and render it, you don't have to kneel into puzzling together XML, send it, receive XML back and parse it to use a web service.

Bye, Olaf.
0
 
LVL 1

Author Closing Comment

by:justaphase
ID: 38854290
No one resolved my problem, so i bought a external software plugin to do what i want.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
New Relic recently released its Synthetics product that allows for the creation of performance monitors that periodically test a site's performance. If you wish to test an interactive workflow New Relic employs Selenium WebDriverJS to run those test…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now