Access webservice using ASP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gihan
    New Member
    • Aug 2008
    • 2

    #1

    Access webservice using ASP

    Hi,
    I have a problem accessing remote webservice from my asp code. Instead of returning results, it returns list of web methods it has.
    Wonder where i'm doing wrong. Also note that, this is a ristricted webservice, which need username password to access and I can't use third party tools (llike xmlspy, webservice studio) to access it and debug. I only got is WSDL.

    Here is the WSDL
    Code:
    <wsdl:definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:DefaultNamespace" xmlns:intf="urn:DefaultNamespace" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:DefaultNamespace">
    	<wsdl:types>
    		<schema targetNamespace="urn:DefaultNamespace" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    			<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
    			<complexType name="Person">
    				<sequence>
    					<element name="branch" nillable="true" type="xsd:string"/>
    					<element name="branchAcronym" nillable="true" type="xsd:string"/>
    					<element name="division" nillable="true" type="xsd:string"/>
    					<element name="divisionAcronym" nillable="true" type="xsd:string"/>
    					<element name="extNo" nillable="true" type="xsd:string"/>
    					<element name="notesCommonName" nillable="true" type="xsd:string"/>
    					<element name="notesName" nillable="true" type="xsd:string"/>
    					<element name="portfolio" nillable="true" type="xsd:string"/>
    					<element name="positionAcronym" nillable="true" type="xsd:string"/>
    					<element name="positionLevel" type="xsd:int"/>
    					<element name="positionType" nillable="true" type="xsd:string"/>
    					<element name="section" nillable="true" type="xsd:string"/>
    					<element name="sectionAcronym" nillable="true" type="xsd:string"/>
    					<element name="signatureLevel" type="xsd:int"/>
    					<element name="siteCode" nillable="true" type="xsd:string"/>
    					<element name="postNominal" nillable="true" type="xsd:string"/>
    					<element name="familyName" nillable="true" type="xsd:string"/>
    					<element name="personId" nillable="true" type="xsd:string"/>
    					<element name="positionTitle" nillable="true" type="xsd:string"/>
    					<element name="department" nillable="true" type="xsd:string"/>
    					<element name="salutation" nillable="true" type="xsd:string"/>
    					<element name="formalSalutation" nillable="true" type="xsd:string"/>
    					<element name="middleName" nillable="true" type="xsd:string"/>
    					<element name="givenName" nillable="true" type="xsd:string"/>
    				</sequence>
    			</complexType>
    			<complexType name="ArrayOfPerson">
    				<complexContent>
    					<restriction base="soapenc:Array">
    						<attribute ref="soapenc:arrayType" wsdl:arrayType="impl:Person[]"/>
    					</restriction>
    				</complexContent>
    			</complexType>
    			<complexType name="Exception">
    				<sequence>
    					<element name="errorType" nillable="true" type="xsd:string"/>
    					<element name="message" nillable="true" type="xsd:string"/>
    				</sequence>
    			</complexType>
    		</schema>
    	</wsdl:types>
    	<wsdl:message name="GetHeadsRequest">
    		<wsdl:part name="MS" type="xsd:boolean"/>
    		<wsdl:part name="PS" type="xsd:boolean"/>
    		<wsdl:part name="GG" type="xsd:boolean"/>
    	</wsdl:message>
    	<wsdl:message name="GetHeadsResponse">
    		<wsdl:part name="GetHeadsReturn" type="impl:ArrayOfPerson"/>
    	</wsdl:message>
    	<wsdl:message name="GetPersonByCommonNameRequest">
    		<wsdl:part name="notesName" type="xsd:string"/>
    	</wsdl:message>
    	<wsdl:message name="GetIPPLRequest"/>
    	<wsdl:message name="GetIPPLResponse1">
    		<wsdl:part name="GetIPPLReturn" type="impl:ArrayOfPerson"/>
    	</wsdl:message>
    	<wsdl:message name="GetMyRecordsResponse">
    		<wsdl:part name="GetMyRecordsReturn" type="impl:ArrayOfPerson"/>
    	</wsdl:message>
    	<wsdl:message name="GetPersonByCommonNameResponse">
    		<wsdl:part name="GetPersonByCommonNameReturn" type="impl:ArrayOfPerson"/>
    	</wsdl:message>
    	<wsdl:message name="GetPeopleBySearchRequest">
    		<wsdl:part name="allWords" type="xsd:string"/>
    		<wsdl:part name="PeopleOnly" type="xsd:boolean"/>
    		<wsdl:part name="SiteOnly" type="xsd:boolean"/>
    		<wsdl:part name="currentOnly" type="xsd:boolean"/>
    	</wsdl:message>
    	<wsdl:message name="Exception">
    		<wsdl:part name="Exception" type="impl:Exception"/>
    	</wsdl:message>
    	<wsdl:message name="GetIPPLRequest1">
    		<wsdl:part name="positionLevel" type="xsd:int"/>
    	</wsdl:message>
    	<wsdl:message name="GetPeopleBySearchRequest1">
    		<wsdl:part name="givenNames" type="xsd:string"/>
    		<wsdl:part name="lastName" type="xsd:string"/>
    		<wsdl:part name="location" type="xsd:string"/>
    		<wsdl:part name="PeopleOnly" type="xsd:boolean"/>
    		<wsdl:part name="SiteOnly" type="xsd:boolean"/>
    		<wsdl:part name="currentOnly" type="xsd:boolean"/>
    	</wsdl:message>
    	<wsdl:message name="GetMyRecordsRequest"/>
    	<wsdl:message name="GetPeopleBySearchResponse">
    		<wsdl:part name="GetPeopleBySearchReturn" type="impl:ArrayOfPerson"/>
    	</wsdl:message>
    	<wsdl:message name="GetIPPLResponse">
    		<wsdl:part name="GetIPPLReturn" type="impl:ArrayOfPerson"/>
    	</wsdl:message>
    	<wsdl:message name="GetPeopleBySearchResponse1">
    		<wsdl:part name="GetPeopleBySearchReturn" type="impl:ArrayOfPerson"/>
    	</wsdl:message>
    	<wsdl:portType name="Directories">
    		<wsdl:operation name="GetIPPL">
    			<wsdl:input name="GetIPPLRequest" message="impl:GetIPPLRequest"/>
    			<wsdl:output name="GetIPPLResponse" message="impl:GetIPPLResponse"/>
    			<wsdl:fault name="Exception" message="impl:Exception"/>
    		</wsdl:operation>
    		<wsdl:operation name="GetIPPL" parameterOrder="positionLevel">
    			<wsdl:input name="GetIPPLRequest1" message="impl:GetIPPLRequest1"/>
    			<wsdl:output name="GetIPPLResponse1" message="impl:GetIPPLResponse1"/>
    			<wsdl:fault name="Exception" message="impl:Exception"/>
    		</wsdl:operation>
    		<wsdl:operation name="GetHeads" parameterOrder="MS PS GG">
    			<wsdl:input name="GetHeadsRequest" message="impl:GetHeadsRequest"/>
    			<wsdl:output name="GetHeadsResponse" message="impl:GetHeadsResponse"/>
    			<wsdl:fault name="Exception" message="impl:Exception"/>
    		</wsdl:operation>
    		<wsdl:operation name="GetMyRecords">
    			<wsdl:input name="GetMyRecordsRequest" message="impl:GetMyRecordsRequest"/>
    			<wsdl:output name="GetMyRecordsResponse" message="impl:GetMyRecordsResponse"/>
    			<wsdl:fault name="Exception" message="impl:Exception"/>
    		</wsdl:operation>
    		<wsdl:operation name="GetPersonByCommonName" parameterOrder="notesName">
    			<wsdl:input name="GetPersonByCommonNameRequest" message="impl:GetPersonByCommonNameRequest"/>
    			<wsdl:output name="GetPersonByCommonNameResponse" message="impl:GetPersonByCommonNameResponse"/>
    			<wsdl:fault name="Exception" message="impl:Exception"/>
    		</wsdl:operation>
    		<wsdl:operation name="GetPeopleBySearch" parameterOrder="allWords PeopleOnly SiteOnly currentOnly">
    			<wsdl:input name="GetPeopleBySearchRequest" message="impl:GetPeopleBySearchRequest"/>
    			<wsdl:output name="GetPeopleBySearchResponse" message="impl:GetPeopleBySearchResponse"/>
    			<wsdl:fault name="Exception" message="impl:Exception"/>
    		</wsdl:operation>
    		<wsdl:operation name="GetPeopleBySearch" parameterOrder="givenNames lastName location PeopleOnly SiteOnly currentOnly">
    			<wsdl:input name="GetPeopleBySearchRequest1" message="impl:GetPeopleBySearchRequest1"/>
    			<wsdl:output name="GetPeopleBySearchResponse1" message="impl:GetPeopleBySearchResponse1"/>
    			<wsdl:fault name="Exception" message="impl:Exception"/>
    		</wsdl:operation>
    	</wsdl:portType>
    	<wsdl:binding name="BlaSoapBinding" type="impl:Directories">
    		<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    		<wsdl:operation name="GetIPPL">
    			<wsdlsoap:operation/>
    			<wsdl:input>
    				<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:input>
    			<wsdl:output>
    				<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:output>
    			<wsdl:fault name="Exception">
    				<wsdlsoap:fault name="Exception" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:fault>
    		</wsdl:operation>
    		<wsdl:operation name="GetIPPL">
    			<wsdlsoap:operation/>
    			<wsdl:input>
    				<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:input>
    			<wsdl:output>
    				<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:output>
    			<wsdl:fault name="Exception">
    				<wsdlsoap:fault name="Exception" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:fault>
    		</wsdl:operation>
    		<wsdl:operation name="GetHeads">
    			<wsdlsoap:operation/>
    			<wsdl:input>
    				<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:input>
    			<wsdl:output>
    				<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:output>
    			<wsdl:fault name="Exception">
    				<wsdlsoap:fault name="Exception" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:fault>
    		</wsdl:operation>
    		<wsdl:operation name="GetMyRecords">
    			<wsdlsoap:operation/>
    			<wsdl:input>
    				<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:input>
    			<wsdl:output>
    				<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:output>
    			<wsdl:fault name="Exception">
    				<wsdlsoap:fault name="Exception" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:fault>
    		</wsdl:operation>
    		<wsdl:operation name="GetPersonByCommonName">
    			<wsdlsoap:operation/>
    			<wsdl:input>
    				<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:input>
    			<wsdl:output>
    				<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:output>
    			<wsdl:fault name="Exception">
    				<wsdlsoap:fault name="Exception" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:fault>
    		</wsdl:operation>
    		<wsdl:operation name="GetPeopleBySearch">
    			<wsdlsoap:operation/>
    			<wsdl:input>
    				<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:input>
    			<wsdl:output>
    				<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:output>
    			<wsdl:fault name="Exception">
    				<wsdlsoap:fault name="Exception" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:fault>
    		</wsdl:operation>
    		<wsdl:operation name="GetPeopleBySearch">
    			<wsdlsoap:operation/>
    			<wsdl:input>
    				<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:input>
    			<wsdl:output>
    				<wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:output>
    			<wsdl:fault name="Exception">
    				<wsdlsoap:fault name="Exception" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:DefaultNamespace"/>
    			</wsdl:fault>
    		</wsdl:operation>
    	</wsdl:binding>
    	<wsdl:service name="DirectoriesService">
    		<wsdl:port name="Bla" binding="impl:BlaSoapBinding">
    			<wsdlsoap:address location="http://somewebsite:80/system/webservices.nsf/directoriesservices?OpenWebService"/>
    		</wsdl:port>
    	</wsdl:service>
    </wsdl:definitions>

    Here is my simple asp page to access the page

    Code:
    <html> 
    <head> 
    	<META name=VI60_defaultClientScript content=VBScript> 
    </head> 
    <body> 
    <form> 
    <input type="button" value="Hello!" name="HelloButton"> 
    <script language="VBScript"> 
    '<!-- 
    sub HelloButton_OnClick() 
     GetXMLSearchResults() 
    End Sub 
    
    Function GetXMLSearchResults() 
                Dim xmlhttp, strSoapRequest, strSOAPResponse 
                strSOAPResponse = "" 
                Const SoapServer = "somewebsite" 
                Const SoapPath = "/directoriesservices?OpenWebService" 
                Dim  SoapURL 
                SoapURL  = "http://" & SoapServer & SoapPath 
                set xmlhttp = CreateObject("Msxml2.ServerXMLHTTP") 
                'Create SOAP request 
                strSoapRequest = MakeSOAPMessage() 
                ' Set the Headers 
                xmlhttp.Open "GET", SoapURL, False, "Username" ,"password"           ' False = Do not respond immediately 
    
                xmlhttp.setRequestHeader "Content-Type", "text/xml; charset=utf-8" 
                xmlhttp.setRequestHeader "SOAPAction", "GetPeopleBySearch" 
                'Send SOAP Request 
                xmlhttp.send(strSoapRequest) 
                Response.Write xmlhttp.responseText 
    
                'Response.End 
                strSOAPResponse = "" 
                If Cint(xmlhttp.Status) = 200 Then                                   ' Response from server was success 
                            strSOAPResponse = xmlhttp.responseText 
                Else                                                                  ' Response from server failed 
                            Response.Write "<div class='feedback_error'> Error in accessing search results from the directory web service.<br/>" 
                            Response.Write "ERROR :- " & xmlhttp.status & " - " & xmlhttp.statusText & "</div>" 
                End If 
                set xmlhttp = nothing 
                GetXMLSearchResults = strSOAPResponse 
    End Function 
    
      
    
    '------------------------------------------------------------------------------------------------------------------------------------------------ 
    
    ' Create a SOAP reqest to the web service 
    
    '------------------------------------------------------------------------------------------------------------------------------------------------ 
    
    Function MakeSOAPMessage() 
                Dim strSOAPMessage 
                ' XML tag 
                strSOAPMessage = "<?xml version=""1.0"" encoding=""utf-8""?>" & VBCRLF 
                ' Envelop tag with name spaces 
                strSOAPMessage =  strSOAPMessage & "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:soapenc=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:tns=""http://somewebsite/services/Directories"" xmlns:types=""http://somewebsite/services/Directories/encodedTypes"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">" & VBCRLF 
                ' ' SOAP body tag 
                strSOAPMessage  = strSOAPMessage  & "<soap:Body soap:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"">" & VBCRLF 
                strSOAPMessage  = strSOAPMessage  & "<q1:GetPeopleBySearch xmlns:q1=""http://somewebsite"">" & VBCRLF 
                strSOAPMessage  = strSOAPMessage  & "<allWords xsi:type=""xsd:string"">" & "smith" & "</allWords>" & VBCRLF 
                strSOAPMessage  = strSOAPMessage  & "<PeopleOnly xsi:type=""xsd:boolean"">" & "false" & "</PeopleOnly>" & VBCRLF 
                strSOAPMessage  = strSOAPMessage  & "<SiteOnly xsi:type=""xsd:boolean"">" & "false" & "</SiteOnly>" & VBCRLF 
                strSOAPMessage  = strSOAPMessage  & "<currentOnly xsi:type=""xsd:boolean"">" & "true" & "</currentOnly>" & VBCRLF 
                strSOAPMessage  = strSOAPMessage  & "</q1:GetPeopleBySearch>"  & VBCRLF 
                strSOAPMessage  = strSOAPMessage  & "</soap:Body>" & VBCRLF 
                strSOAPMessage  = strSOAPMessage  & "</soap:Envelope>" & VBCRLF 
                MakeSOAPMessage = strSOAPMessage 
    End Function 
    ' --> 
    
    </script> 
    </form> 
    </body> 
    </html>
    and response.write returns this
    Code:
    Bla(wsdl) 
    GetIPPL 
    GetIPPL 
    GetHeads 
    GetMyRecords 
    GetPersonByCommonName 
    GetPeopleBySearch 
    GetPeopleBySearch
    in Bla(wsdl), wsdl have a link to wsdl. so that loads up above wsdl when i click on the link.

    Could some one please help me on this.
    Thanks in advance.
    Gihan.
    Last edited by jhardman; Aug 21 '08, 03:24 PM. Reason: put code in code tags. please note button marked #
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:tns="http://somewebsite/services/Directories" 
    xmlns:types="http://somewebsite/services/Directories/encodedTypes" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       <soap:Body soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <q1:GetPeopleBySearch xmlns:q1="http://somewebsite">
            <allWords xsi:type="xsd:string">smith</allWords>
            <PeopleOnly xsi:type="xsd:boolean">false</PeopleOnly>
            <SiteOnly xsi:type="xsd:boolean">false</SiteOnly>
            <currentOnly xsi:type="xsd:boolean">true</currentOnly>
          </q1:GetPeopleBySearch>
       </soap:Body>
    </soap:Envelope>
    I've never opened a webservice in classic ASP, but I would assume the problem is in the SOAP. Looking over your code I don't see a problem though, and I assume you checked it already?

    Jared

    Comment

    Working...