WS document/literal wrapped schema

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

WS document/literal wrapped schema

Postby fortiz » Wed Mar 02, 2011 11:45 am

Hi, i'm new in this forum, maybe i'll introduce myself later on another post.

I'm using VAST 8.0.3 and having problems consuming a third party WS which uses a WSLD with a document/literal wrapped schema. I've been through the WS' help, first the examples then the whole documentation without luck for a couple of days.

As i undestand VAST WS deals with this kind of schema in a different way, there's a special instance creation message on SstWSContainer to set up the container.

I'm getting a debugger at some point and i'm at dead end. Has anyone faced this situation?

Code: Select all
[
  | aContainer aServiceCollection containerName |
  SstWSContainer clearAll.
  containerName := SciSocketManager default getHostName.
  aContainer := SstWSContainer containerNamed: containerName ifNone: [ SstWSContainer createContainerUsingDocLiteralWrappedNamed: containerName ].
  aServiceCollection := aContainer deploy: 'http://www.holidaywebservice.com/Holidays/US/Dates/USHolidayDates.asmx?WSDL'.
  (aServiceCollection first invoke: 'GetAbrahamLincolnsBirthday' withArguments: (Array with: '2007')) inspect
] fork


Here's another example
Code: Select all
[
  | aContainer aServiceCollection containerName schemas datesSchema mappedElement |
  SstWSContainer clearAll.
  containerName := SciSocketManager default getHostName.
  aContainer := SstWSContainer containerNamed: containerName ifNone: [ SstWSContainer createContainerUsingDocLiteralWrappedNamed: containerName ].
  aServiceCollection := aContainer deploy: 'http://demo.argentinaclearing.com.ar/webservice/businessservices.asmx?WSDL'.
  schemas := (aContainer serializationManager schemas at: 'https://www.argentinaclearing.com.ar/webservice/businessservices.asmx') content.
  datesSchema := schemas detect: [ :s | s name = 'Fechas' ].
  mappedElement := datesSchema asMappedElement.
  mappedElement TipoFecha: 1.
  mappedElement Parametro1: 1.
  mappedElement Parametro2: 1.
  (aServiceCollection first invoke: 'Fechas' withArguments: (Array with: mappedElement)) inspect
] fork



Thanks in advance for your help and time,
Francisco
fortiz
 
Posts: 7
Joined: Tue Mar 01, 2011 11:28 am

Re: WS document/literal wrapped schema

Postby benvandijk » Thu Mar 03, 2011 2:22 pm

Francisco,

Always willing to help.
I corrected your first example and got a correct result

Code: Select all
[
  | aContainer aServiceCollection containerName |
  SstWSContainer clearAll.
  containerName := SciSocketManager default getHostName.
  aContainer := SstWSContainer containerNamed: containerName ifNone: [ SstWSContainer createContainerUsingDocLiteralWrappedNamed: containerName ].
  aServiceCollection := aContainer deploy: 'http://www.holidaywebservice.com/Holidays/US/Dates/USHolidayDates.asmx?WSDL'.
  (aServiceCollection first GetAbrahamLincolnsBirthday: (Array with: '2007')) inspect
] fork


In short, do not use invoke: but call the operation as if you would call a smalltalk method

Greetz, Ben
benvandijk
 
Posts: 45
Joined: Sun Feb 25, 2007 7:14 am
Location: Arnhem, Netherlands

Re: WS document/literal wrapped schema

Postby fortiz » Thu Mar 17, 2011 9:48 am

Hi Ben,

sorry about the delayed response i was out of the office.

I tried your code snippet without luck. I'm still getting a DNU at stWSDocLiteralWrappedStyle>>#addNamespaceForElement:envelope:message: cause schema's namespaceMappings holds a reference to nil.

Which version of VAST are you using? I'm using an empty 8.0.3 image with ST: Server Smalltalk (SST) - Web Services loaded with its prerequisites.

Thanks,
Francisco
fortiz
 
Posts: 7
Joined: Tue Mar 01, 2011 11:28 am

Re: WS document/literal wrapped schema

Postby tc » Thu Mar 17, 2011 10:20 am

Hello,

Try this:
Code: Select all
SstWSContainer clearAll.
[
  | aContainer aServiceCollection contName parm soapMappedElement dictionary |

    contName := SciSocketManager default getHostName.
    aContainer := SstWSContainer containerNamed: contName
    ifNone: [ SstWSContainer createContainerNamed: contName ].
    aServiceCollection := aContainer deploy: 'http://www.holidaywebservice.com/Holidays/US/Dates/USHolidayDates.asmx?WSDL'.
    schemas := (aContainer serializationManager schemas at: 'http://www.27seconds.com/Holidays/US/Dates/') content.
    schema := schemas detect: [ :s | s name = 'GetCincoDeMayo' ].
      mappedElement := schema asMappedElement.
    mappedElement year: '2008'.
    soapMappedElement := ((aServiceCollection first) invoke: 'GetCincoDeMayo' withArguments: (Array with: mappedElement)).
   dictionary := soapMappedElement elements inject: Dictionary new into: [ :dict :elem |
      elem object isNil
         ifFalse: [ dict at: elem abtXmlName put: elem object]. 
      dict ].
   dictionary inspect
] fork

. . . also,

http://www.soapclient.com/soaptest.html

. . . shows the web service calls defined and the parameters required. Enter the address of the WSDL file in the text box.

Different WSDL files have different bindings, such as RPC or Doc/Literal. A different 'style' may require slightly different code above.

--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC

Re: WS document/literal wrapped schema

Postby fortiz » Tue Mar 22, 2011 11:08 am

Hello,

thanks for your help, i finally understood some of the inner workings of the WS implementation but I wrote two examples and unfortunately the one I do really need to have working is the other one :?

I've been trying this...
Code: Select all
SstWSContainer clearAll.
[
        | aContainer aServiceCollection containerName schemas datesSchema mappedElement soapMappedElement dictionary |

     containerName := SciSocketManager default getHostName.
   aContainer := SstWSContainer containerNamed: containerName ifNone: [ SstWSContainer createContainerUsingDocLiteralWrappedNamed: containerName ].

   aServiceCollection := aContainer deploy: 'http://demo.argentinaclearing.com.ar/webservice/businessservices.asmx?WSDL'.
 
   schemas := (aContainer serializationManager schemas at: 'https://www.argentinaclearing.com.ar/webservice/businessservices.asmx') content.
     datesSchema := schemas detect: [ :s | s name = 'Fechas' ].

   mappedElement := datesSchema asMappedElement.
     mappedElement TipoFecha: 1.
   mappedElement Parametro1: 1.
     mappedElement Parametro2: 1.

   soapMappedElement := ((aServiceCollection first) invoke: 'Fechas' withArguments: (Array with: mappedElement)).
   soapMappedElement inspect
] fork


I tried this code snipet with VAST 8.0.3 and isn't working then i made some changes because i've got and uninitilized namespaceMappings at element's schemas and also tried some other changes but i can't make it work.

The most annoying thing is that after sending #invoke: inspecting the SstWSMessageContext object i can see the message request (##wsTransportMessageRequest) and if i copy paste it in a soap client it works!

I also tried sending #createContainerNamed: to SstWSContainer wich i think is the default with no luck.

Kind regards,
Francisco
fortiz
 
Posts: 7
Joined: Tue Mar 01, 2011 11:28 am

Re: WS document/literal wrapped schema

Postby Diane Engles » Tue Mar 22, 2011 12:07 pm

Hello Franscisco,

I have been working on another case which turns out has exposed the same problem you are having as a side effect. The code you were getting the DNU in is attempting to be sure all namespaces are included in the SOAP request envelope and has a bug when a schema with no namespace mappings is referenced. Please file in the following updated method and see how far you get:
Code: Select all

!SstWSDocLiteralWrappedStyle publicMethods !

addNamespaceForElement: anElement envelope: anSstSoapEnvelope message: aMessage

   | assoc namespace prefixed prefixToAdd uniqueId envelopeMappings mapping notADuplicate |
   
   
   "Ensure namespaces are added for schema elements with no type, but a typename or ref"
   "Also include namespaces defined locally for a single element"
   
   notADuplicate := true.
   self prefixTable: LookupTable new.

   anElement isExtension
      ifTrue: [prefixed := anElement base]

      ifFalse: [
         anElement getReference notNil
            ifTrue: [prefixed := anElement ref]
            ifFalse: [anElement typeName notNil ifTrue: [prefixed := anElement typeName]]].

   (prefixed notNil and: [ anElement schema namespaceMappings notNil])
      ifTrue: [
         prefixToAdd := AbtXmlUtility prefixFor: prefixed.
         namespace := anElement schema namespaceMappings at: prefixToAdd ifAbsent:
                              [(anElement abtXmlNamespaceMappings) notNil ifTrue:
                                 [anElement abtXmlNamespaceMappings at: prefixToAdd ifAbsent: []]].
         namespace notNil ifTrue: [assoc := Association key: prefixToAdd value: namespace]].
         
   assoc isNil
      ifTrue: [ assoc := aMessage definedBy types allNamespaceMappings associationAt: prefixToAdd ifAbsent: []].
               
   
   "if a key already exsits with this prefix that refers to a DIFFERENT namespace, do not overwrite it. 
    Modify the prefix it so that namespaces declared with wsdl with duplicate prefixes
    will all be included in the SOAP envelope.  If a namespace is already in the lookuptable with another key,
    do not make an entry with a duplicate value"   
   assoc notNil ifTrue:
      [
           envelopeMappings := anSstSoapEnvelope abtXmlNamespaceMappings.
             (envelopeMappings includes: (assoc value))
          ifFalse: [
            
                  "namespace is not in the table.  is the key already in the table?"
                  (envelopeMappings includesKey: (assoc key)) ifTrue: [
                
                 "key is already in table.  Make it unique and add the namespace to the SOAP envelope"
                    uniqueId := (self prefixTable) at: prefixToAdd ifAbsent: [ (self prefixTable) at: prefixToAdd put: 1].
                     assoc key: assoc key, uniqueId printString.
                    prefixTable at: prefixToAdd put: (uniqueId + 1) ]]
   
           ifTrue: [ notADuplicate := false]].
          
               
   " add association with unique key to the envelope namespace mappings"
   (notADuplicate) ifTrue: [ ( prefixToAdd notNil and: [assoc notNil])
                        ifTrue: [anSstSoapEnvelope abtXmlNamespaceMappings add: assoc]                                              ]
      
! !


This is the SOAP request which was generated in my 8.0.3 image after making the above change and executing the code in your example above:

'<SOAP-ENV:Envelope
xmlns:tns="https://www.argentinaclearing.com.ar/webservice/businessservices.asmx"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<tns:Fechas>
<tns:TipoFecha>1</tns:TipoFecha>
<tns:Parametro1>1</tns:Parametro1>
<tns:Parametro2>1</tns:Parametro2>
</tns:Fechas>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>'


Is this the correct envelope?

Regards,

Diane
Instantiations Smalltalk Support
diane@instantiations.com
Diane Engles
Moderator
 
Posts: 66
Joined: Mon Oct 16, 2006 2:40 pm

Re: WS document/literal wrapped schema

Postby fortiz » Tue Mar 22, 2011 1:50 pm

Hi Diane,

I got as far as i was with my changes... instead of checking if namespaceMappings is nil i'd some lazy initialization to an empty LookupTable. (BTW Is it ok to have a namespace-mapping-less schema?)

Yes that's the correct envelope but again if i copy/paste it in a SOAP client like soapui it works! VAST isn't able to build the response, it's getting an error from the server.

Any other clue?

Thanks,
Francisco
fortiz
 
Posts: 7
Joined: Tue Mar 01, 2011 11:28 am

Re: WS document/literal wrapped schema

Postby tc » Thu Mar 24, 2011 2:26 am

Hello,

I'm a little concerned about the Argentine web service. I was able to call it from http://www.soapclient.com but when I tried it with java, I got the error shown in the attached picture.

argentina web service.JPG
argentina web service.JPG (23.74 KiB) Viewed 403 times


Part of the problem is the WSDL/schema standards are not standards, but proposals. This gives people a wide latitude when producing and consuming a web service.

The 'US Holiday' web service worked fine though.

--tc
tc
Moderator
 
Posts: 304
Joined: Tue Oct 17, 2006 7:40 am
Location: Raleigh, NC

Re: WS document/literal wrapped schema

Postby Diane Engles » Thu Mar 24, 2011 8:43 am

Hi Fransisco,

It is ok for a schema to have no namespace mappings.

What error response are you getting from the server?

Thanks,

Diane
Instantiations Smalltalk Support
diane@instantiations.com
Diane Engles
Moderator
 
Posts: 66
Joined: Mon Oct 16, 2006 2:40 pm

Re: WS document/literal wrapped schema

Postby fortiz » Mon Mar 28, 2011 6:09 am

Hi,

i'm getting the following error,

Code: Select all
Debugger Stack Trace Report:
Error String: 'System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Helper.Log.BusinessServices.Write(Accion Accion, String Detalle)
   at WebServiceWSE.BusinessServices.Fechas(Int32 TipoFecha, String Parametro1, String Parametro2)
   --- End of inner exception stack trace ---'
Resumable: true


Regards,
Francisco
fortiz
 
Posts: 7
Joined: Tue Mar 01, 2011 11:28 am

Re: WS document/literal wrapped schema

Postby Diane Engles » Thu Mar 31, 2011 10:14 am

I am are getting the same error in VA Smalltalk that you posted, so at least we are on the same page there.

If it is true that you can cut and paste the exact same envelope that is begin generated in VA Smalltalk into soapui and get a correct response, it could be something in the header that is the problem. Can you get the complete message that is being sent out of soapui including the Http header and the SOAP envelope? That would be very helpful.

Thanks.
Instantiations Smalltalk Support
diane@instantiations.com
Diane Engles
Moderator
 
Posts: 66
Joined: Mon Oct 16, 2006 2:40 pm

Re: WS document/literal wrapped schema

Postby fortiz » Thu Mar 31, 2011 12:01 pm

Hi, this is the raw HTTP log of soapui (request and response, separated with a new line).

Hope it helps,
Francisco
Attachments
output.txt
HTTP soapui log
(3.73 KiB) Downloaded 17 times
fortiz
 
Posts: 7
Joined: Tue Mar 01, 2011 11:28 am

Re: WS document/literal wrapped schema

Postby Diane Engles » Fri Apr 01, 2011 2:59 pm

Hi,
Thanks to your information from soapui, I have been able to get VA Smalltalk to successfully invoke the web service and recieve a valid response. It appears this service requires the User-Agent field to be present in the header. I tried setting all of the fields VA Smalltalk was not setting and then removing them one by one to find which were really necessary. (You can set a breakpoint in SstHttpClient>>post: typed: at: using: withHeaders: to see the SstByteMessages that are sent and received).

The Http 1.1 spec states that the User-Agent field SHOULD be set, but this service seems to require it. ( http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html )

Please try this version of SstHttpClient>>buildHttpPOSTFor:using: along with your previous mods to ignore schemas without namespace mappings.

Code: Select all
buildHttpPOSTFor: aUrl using: basicAuthCredential

   |req|

   req := self templateHttpPOSTMessage copy.

   basicAuthCredential isNil
      ifFalse: [req header authorization:  basicAuthCredential].

   req header
      url: (self requestUriForUrl: aUrl);
      host: aUrl hostport;
      userAgent: 'VA Smalltalk/8.0.3'.

   ^req


I hope you will get back a SOAP envelope that looks something like this:

'<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
<wsa:Action>https://www.argentinaclearing.com.ar/webservice/businessservices.asmx/FechasResponse</wsa:Action>
<wsa:MessageID>uuid:d6662817-2d93-4d55-93f4-c4af96301fce</wsa:MessageID>
<wsa:RelatesTo>uuid:8ff2b2c3-00e6-4f5e-97e8-326fb4a92b8a</wsa:RelatesTo>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:To>
<wsse:Security>
<wsu:Timestamp wsu:Id="Timestamp-f10071b7-1db0-47c1-8052-f3201cddb4db">
<wsu:Created>2011-04-01T20:36:36Z</wsu:Created>
<wsu:Expires>2011-04-01T21:36:36Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soap:Header>
<soap:Body>
<FechasResponse xmlns="https://www.argentinaclearing.com.ar/webservice/businessservices.asmx">
<FechasResult>03/12/2010</FechasResult>
</FechasResponse>
</soap:Body>
</soap:Envelope>'


The final result should be an inspector on an instance of a SOAP Mapped Element.

Let me know your results.
Instantiations Smalltalk Support
diane@instantiations.com
Diane Engles
Moderator
 
Posts: 66
Joined: Mon Oct 16, 2006 2:40 pm

Re: WS document/literal wrapped schema

Postby fortiz » Tue Apr 05, 2011 6:31 am

Diane, it worked! I'm testing it... making other requests.

Thanks to all for your help,
Francisco
fortiz
 
Posts: 7
Joined: Tue Mar 01, 2011 11:28 am


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: No registered users and 1 guest

cron