• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling SOAP web service  RSS feed

 
Wendy Batista
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to web services and need to call a web service that has already been written. Below is the wsdl for the web service.
I need to call the web service from my java program. Could someone please provide the code to call the webservice? Let me know if you need any additional info. Thanks in advance.


<definitions targetNamespace="urnefaultNamespace">
<message name="CREATECONTACTUSResponse"></message>
<message name="CREATECONTACTUSRequest">
<part name="REQUESTTYPE" type="xsd:string"/>
<part name="SALESORG" type="xsd:string"/>
<part name="FIRSTNAME" type="xsd:string"/>
<part name="LASTNAME" type="xsd:string"/>
<part name="EMAILADDRESS" type="xsd:string"/>
<part name="TELEPHONENUMBER" type="xsd:string"/>
<part name="EXTENSION" type="xsd:string"/>
<part name="PREFEREDCONTACTMETHOD" type="xsd:string"/>
<part name="CUSTOMERCOMMENTS" type="xsd:string"/>
<part name="CONTACTID" type="xsd:string"/>
<part name="WEBID" type="xsd:string"/>
<part name="ZIPCODE" type="xsd:string"/>
<part name="STREETADDRESS" type="xsd:string"/>
<part name="SALESPRODUCT" type="xsd:string"/>
<part name="SERIALNUMBER" type="xsd:string"/>
<part name="SERVICEPRODUCTFAMILY" type="xsd:string"/>
<part name="SERVICEPRODUCT" type="xsd:string"/>
</message>
<portType name="ContactUs">
<operation name="CREATECONTACTUS" parameterOrder="REQUESTTYPE SALESORG FIRSTNAME LASTNAME EMAILADDRESS TELEPHONENUMBER EXTENSION PREFEREDCONTACTMETHOD CUSTOMERCOMMENTS CONTACTID WEBID ZIPCODE STREETADDRESS SALESPRODUCT SERIALNUMBER SERVICEPRODUCTFAMILY SERVICEPRODUCT">
<input message="impl:CREATECONTACTUSRequest" name="CREATECONTACTUSRequest"/>
<output message="impl:CREATECONTACTUSResponse" name="CREATECONTACTUSResponse"/>
</operation>
</portType>
<binding name="DominoSoapBinding" type="impl:ContactUs">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="CREATECONTACTUS">
<wsdlsoapperation soapAction="CREATECONTACTUS"/>
<input name="CREATECONTACTUSRequest">
<wsdlsoap:body namespace="urnefaultNamespace" use="literal"/>
</input>
<output name="CREATECONTACTUSResponse">
<wsdlsoap:body namespace="urnefaultNamespace" use="literal"/>
</output>
</operation>
</binding>
<service name="ContactUsService">
<port binding="implominoSoapBinding" name="Domino">
<wsdlsoap:address location="http://notesdev.test.com:80/WebsiteA.nsf/ContactUs?OpenWebService"/>
</port>
</service>
</definitions>
 
Wendy Batista
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it working using the following code. However, I am getting an error on the call "unexpected encoding style: expected=http://schemas.xmlsoap.org/soap/encoding/, actual="

Does anybody have any ideas on how to fix this? Does something need to change on the web service side or can I change something in my call to get it to work?

QName serviceName = new QName("http://notesdev.test.com/WebsiteA.nsf/ContactUs?WSDL ","ContactUsService");
ServiceFactory factory = ServiceFactory.newInstance();
Service service = factory.createService(serviceName);

Call call = service.createCall();

QName operationName = new QName("CREATECONTACTUS");
call.setOperationName(operationName);

// The input parameter
call.addParameter("REQUESTTYPE", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("SALESORG", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("FIRSTNAME", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("LASTNAME", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("EMAILADDRESS", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("TELEPHONENUMBER", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("EXTENSION", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("PREFEREDCONTACTMETHOD", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("CUSTOMERCOMMENTS", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("CONTACTID", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("WEBID", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("ZIPCODE", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("STREETADDRESS", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("SALESPRODUCT", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("SERIALNUMBER ", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("SERVICEPRODUCTFAMILY ", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("SERVICEPRODUCT ", XMLType.XSD_STRING, ParameterMode.IN);


// The return
call.setReturnType(XMLType.XSD_STRING);

call.setProperty( Call.OPERATION_STYLE_PROPERTY, "rpc" );
call.setProperty(Call.ENCODINGSTYLE_URI_PROPERTY, "http://schemas.xmlsoap.org/soap/encoding/");

call.setTargetEndpointAddress("http://notesdev.test.com:80/WebsiteA.nsf/ContactUs?OpenWebService");
// Invoke the operation

String[] actArgs = {(String)"SA", (String)"US01", (String)"Test", (String)"User", (String)"test_user@yahoo.com", (String)"", (String)"",(String)"",(String)"",(String)"",(String)"",(String)"",(String)"",(String)"",(String)"",(String)"",
(String)"" };

String responseObj = (String)call.invoke(actArgs);

Thanks.
 
Wendy Batista
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got this working by changing the style on the lotus notes side to document wrapped.


SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();

// Send SOAP Message to SOAP Server
java.net.URL endpoint = new URL("http://notesdev.test.com:80/WebsiteA.nsf/ContactUs?OpenWebService");

MessageFactory messageFactory = MessageFactory.newInstance();

SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();

envelope.removeNamespaceDeclaration("SOAP-ENV");
envelope.setPrefix("soapenv");
envelope.addNamespaceDeclaration("urn", "urnefaultNamespace");

SOAPHeader header = envelope.getHeader();
header.removeNamespaceDeclaration("SOAP-ENV");
header.setPrefix("soapenv");

SOAPBody body = envelope.getBody();
body.removeNamespaceDeclaration("SOAP-ENV");
body.setPrefix("soapenv");

SOAPElement createContactUs = body.addChildElement("CREATECONTACTUS","urn");

SOAPElement requestType = createContactUs.addChildElement("REQUESTTYPE");
requestType.addTextNode("SA");

SOAPElement salesOrg = createContactUs.addChildElement("SALESORG");
salesOrg.addTextNode("US01");

SOAPElement firstName = createContactUs.addChildElement("FIRSTNAME");
firstName.addTextNode("Minnie");

SOAPElement lastName = createContactUs.addChildElement("LASTNAME");
lastName.addTextNode("Mouse2");

SOAPElement email = createContactUs.addChildElement("EMAILADDRESS");
email.addTextNode("mickey_mouse@test.com");

SOAPElement phone = createContactUs.addChildElement("TELEPHONENUMBER");
phone.addTextNode("555-555-1212");

SOAPElement ext = createContactUs.addChildElement("EXTENSION");
ext.addTextNode("123");

SOAPElement contactMethod = createContactUs.addChildElement("PREFEREDCONTACTMETHOD");
contactMethod.addTextNode("p");

SOAPElement customerComments = createContactUs.addChildElement("CUSTOMERCOMMENTS");
customerComments.addTextNode("p");

SOAPElement contactId = createContactUs.addChildElement("CONTACTID");
contactId.addTextNode("123");

SOAPElement webId = createContactUs.addChildElement("WEBID");
webId.addTextNode("p");

SOAPElement zip = createContactUs.addChildElement("ZIPCODE");
webId.addTextNode("01757");

SOAPElement street = createContactUs.addChildElement("STREETADDRESS");
street.addTextNode("1 Main St");

SOAPElement product = createContactUs.addChildElement("SALESPRODUCT");
product.addTextNode("product");

SOAPElement serial = createContactUs.addChildElement("SERIALNUMBER");
serial.addTextNode("serial");

SOAPElement productFamily = createContactUs.addChildElement("SERVICEPRODUCTFAMILY");
productFamily.addTextNode("Family");

SOAPElement serviceProduct = createContactUs.addChildElement("SERVICEPRODUCT");
serviceProduct.addTextNode("Service Product");

soapMessage.saveChanges();

/* Print the request message */
System.out.print("Request SOAP Message = ");
soapMessage.writeTo(System.out);
System.out.println();

SOAPMessage soapResponse = soapConnection.call(soapMessage, endpoint);
soapResponse.writeTo(System.out);

SOAPBody returnSoapBody = soapResponse.getSOAPBody();
//returnSoapBody.get

soapConnection.close();


Here is what the new wsdl looked like after changing the style on lotus notes web service.....

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urnefaultNamespace" xmlns:intf="urnefaultNamespace" 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="urnefaultNamespace">
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urnefaultNamespace">
<element name="CREATECONTACTUS">
<complexType>
<sequence>
<element name="REQUESTTYPE" type="xsd:string"/>
<element name="SALESORG" type="xsd:string"/>
<element name="FIRSTNAME" type="xsd:string"/>
<element name="LASTNAME" type="xsd:string"/>
<element name="EMAILADDRESS" type="xsd:string"/>
<element name="TELEPHONENUMBER" type="xsd:string"/>
<element name="EXTENSION" type="xsd:string"/>
<element name="PREFEREDCONTACTMETHOD" type="xsd:string"/>
<element name="CUSTOMERCOMMENTS" type="xsd:string"/>
<element name="CONTACTID" type="xsd:string"/>
<element name="WEBID" type="xsd:string"/>
<element name="ZIPCODE" type="xsd:string"/>
<element name="STREETADDRESS" type="xsd:string"/>
<element name="SALESPRODUCT" type="xsd:string"/>
<element name="SERIALNUMBER" type="xsd:string"/>
<element name="SERVICEPRODUCTFAMILY" type="xsd:string"/>
<element name="SERVICEPRODUCT" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="CREATECONTACTUSResponse">
<complexType>
<sequence>
<element name="CREATECONTACTUSReturn" type="xsd:string"/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<message name="CREATECONTACTUSResponse">
<part element="impl:CREATECONTACTUSResponse" name="parameters"/>
</message>
<message name="CREATECONTACTUSRequest">
<part element="impl:CREATECONTACTUS" name="parameters"/>
</message>
<portType name="ContactUs">
<operation name="CREATECONTACTUS">
<input message="impl:CREATECONTACTUSRequest" name="CREATECONTACTUSRequest"/>
<output message="impl:CREATECONTACTUSResponse" name="CREATECONTACTUSResponse"/>
</operation>
</portType>
<binding name="DominoSoapBinding" type="impl:ContactUs">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="CREATECONTACTUS">
<wsdlsoapperation soapAction="CREATECONTACTUS"/>
<input name="CREATECONTACTUSRequest">
<wsdlsoap:body use="literal"/>
</input>
<output name="CREATECONTACTUSResponse">
<wsdlsoap:body use="literal"/>
</output>
</operation>
</binding>
<service name="ContactUsService">
<port binding="implominoSoapBinding" name="Domino">
<wsdlsoap:address location="http://notesdev.test.com:80/WebsiteA.nsf/ContactUs?OpenWebService"/>
</port>
</service>
</definitions>
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!