pranvera hoti
pranvera hoti

Reputation: 117

How to call a soap webservice using google apps script

I am using google apps script to work with an open source platform OpenClinica and I am trying to consume their soap web service using the following code below:

  var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
  +"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:v1=\"http://openclinica.org/ws/studySubject/v1\" xmlns:bean=\"http://openclinica.org/ws/beans\">"
  +"<soapenv:Header>"
  +"<wsse:Security soapenv:mustUnderstand=\"1\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">"
  +"<wsse:UsernameToken wsu:Id=\"UsernameToken-27777511\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">"
  +"<wsse:Username>xxx</wsse:Username>"
  +"<wsse:Password>yyy</wsse:Password>"
  +"</wsse:UsernameToken>"
  +"</wsse:Security>"
  +"</soapenv:Header>"
  +"<soapenv:Body>"
  +"<v1:importRequest>"
  +"<ODM>"
  +"<ClinicalData StudyOID=\"S_PROSPER2\" MetaDataVersionOID=\"v1.0.0\">"
  +"<SubjectData SubjectKey=\"SS_UU001\">"
  +"<StudyEventData StudyEventOID=\"SE_QUESW4\" StudyEventRepeatKey=\"0\">"
  +"<FormData FormOID=\"F_RANDANDQUEST_11\">"
  +"<ItemGroupData ItemGroupOID=\"IG_RANDA_UNGROUPED\" ItemGroupRepeatKey=\"1\" TransactionType=\"Insert\">"
  +"<ItemData ItemOID=\"I_RANDA_RAND01\" Value=\"1\"/>"
  +"<ItemData ItemOID=\"I_RANDA_RAND02\" Value=\"1\"/>"
  +"<ItemData ItemOID=\"I_RANDA_RAND03\" Value=\"1\"/>"
  +"<ItemData ItemOID=\"I_RANDA_RAND04\" Value=\"1\"/>"
  +"</ItemGroupData>"
  +"</FormData>"
  +"</StudyEventData>"
  +"</SubjectData>"
  +"</ClinicalData>"
  +"</ODM>"
  +"</v1:importRequest>"
  +"</soapenv:Body>"
  +"</soapenv:Envelope>";


  var options =
      {
        "method" : "post",
        "contentType" : "text/xml",
        "payload" : xml
      };

  var result = UrlFetchApp.fetch("http://89.221.253.174:8080/OpenClinica-ws/ws/data/v1/dataWsdl.wsdl", options);

For some reason I am getting this error message:

Request failed for http://89.221.253.174:8080/OpenClinica-ws/ws/data/v1/dataWsdl.wsdl returned code 404 (line 147, file "Code")

So the error is actually on this line:

var result = UrlFetchApp.fetch("http://89.221.253.174:8080/OpenClinica-ws/ws/data/v1/dataWsdl.wsdl", options);

If I am trying the same code from soapUI tool it works all fine:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://openclinica.org/ws/data/v1">
   <soapenv:Header>
    <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <wsse:UsernameToken wsu:Id="UsernameToken-27777511" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <wsse:Username>xxx</wsse:Username>
    <wsse:Password>yyy</wsse:Password>
    </wsse:UsernameToken>
    </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
     <v1:importRequest>
          <ODM>
                <ClinicalData StudyOID="S_PROSPER2" MetaDataVersionOID="v1.0.0">
                    <SubjectData SubjectKey="SS_UU001">
                        <StudyEventData StudyEventOID="SE_QUESW4" StudyEventRepeatKey="0">
                            <FormData FormOID="F_RANDANDQUEST_11">
                                <ItemGroupData ItemGroupOID="IG_RANDA_UNGROUPED" ItemGroupRepeatKey="1" TransactionType="Insert">
                                    <ItemData ItemOID="I_RANDA_RAND01" Value="1"/>
                                    <ItemData ItemOID="I_RANDA_RAND02" Value="1"/>
                                    <ItemData ItemOID="I_RANDA_RAND03" Value="1"/>
                                    <ItemData ItemOID="I_RANDA_RAND04" Value="1"/>
                                </ItemGroupData>
                            </FormData>
                        </StudyEventData>
                    </SubjectData>
                </ClinicalData>
            </ODM>      
     </v1:importRequest>
   </soapenv:Body>
</soapenv:Envelope>

Upvotes: 1

Views: 2749

Answers (1)

Nitin Dhomse
Nitin Dhomse

Reputation: 2612

Just add one extra parameter in your option as follows, muteHttpExceptions : true

var options =
      {
        "method" : "post",
        "contentType" : "text/xml",
        "payload" : xml,
        muteHttpExceptions:true
      };

Upvotes: 1

Related Questions