Options

Calling webservice, but confused about the syntax

livingdolllivingdoll Member Posts: 45
edited 2011-04-11 in NAV Three Tier
Hi everybody,

I have to send an xml message to a webservice called 'SendMessage', that is defined by the following wsdl:
<?xml version="1.0" encoding="utf-8" ?> 
- <wsdl:definitions name="Service" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata">
- <wsdl:types>
- <xsd:schema targetNamespace="http://tempuri.org/Imports">
  <xsd:import schemaLocation="http://server.company.nl/NavService/Service.svc?xsd=xsd0" namespace="http://tempuri.org/" /> 
  <xsd:import schemaLocation="http://server.company.nl/NavService/Service.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" /> 
  </xsd:schema>
  </wsdl:types>
- <wsdl:message name="IService_SendMessage_InputMessage">
  <wsdl:part name="parameters" element="tns:SendMessage" /> 
  </wsdl:message>
- <wsdl:message name="IService_SendMessageToQueue_OutputMessage">
  <wsdl:part name="parameters" element="tns:SendMessageResponse" /> 
  </wsdl:message>
- <wsdl:portType name="IService">
- <wsdl:operation name="SendMessage">
  <wsdl:input wsaw:Action="http://tempuri.org/IService/SendMessage" message="tns:IService_SendMessage_InputMessage" /> 
  <wsdl:output wsaw:Action="http://tempuri.org/IService/SendMessageResponse" message="tns:IService_SendMessage_OutputMessage" /> 
  </wsdl:operation>
  </wsdl:portType>
- <wsdl:binding name="BasicHttpBinding_IService" type="tns:IService">
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
- <wsdl:operation name="SendMessage">
  <soap:operation soapAction="http://tempuri.org/IService/SendMessage" style="document" /> 
- <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:service name="Service">
- <wsdl:port name="BasicHttpBinding_IService" binding="tns:BasicHttpBinding_IService">
  <soap:address location="http://server.company.nl/NavService/Service.svc" /> 
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>

I'm using XMLDom that's filled from a XMLPort to produce the xml. That's working fine. The only thing I'm puzzled about is the SetRequestHeader-lines in the code below. I don't know - based upon the wsdl above - what to put in there... Anyone have an idea? I have difficulties reading the wsdl, that's new for me..
IF ISCLEAR(XMLDoc) THEN
  CREATE(XMLDoc);

XMLDoc.load(Instr);

IF ISCLEAR(XMLHttpConn) THEN
  CREATE(XMLHttpConn);

XMLHttpConn.setRequestHeader('Host','?????');
XMLHttpConn.setRequestHeader('SOAPAction','?????');
XMLHttpConn.setRequestHeader('Content-Type','text/xml'); 

XMLHttpConn.send(XMLDoc); 
XMLHttpConn.waitForResponse(1000);

TxtResponse := FORMAT(XMLHttpConn.status);

Best regards,
Jesz

Comments

  • Options
    ara3nara3n Member Posts: 9,255
    Hello Jes
    What You need to paste the xml file and not copy and paste what IE is rendering. To do that. Save WSDL as xml file and then open it in Notepad and paste the code.

    We can then help you with the code on how to communicate with web service.


    Could you also post the address for WSDL?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    livingdolllivingdoll Member Posts: 45
    Hi Ara3n,

    Thanks for your reply. The WSDL is only addressable on our intranet, so posting the url to it won't be of any use I'm afraid.

    I'm pretty new to webservices, so I hope I followed your directions correctly:
    <?xml version="1.0" encoding="utf-8"?><wsdl:definitions name="Service" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"><wsdl:types><xsd:schema targetNamespace="http://tempuri.org/Imports"><xsd:import schemaLocation="http://server1.domain.nl/NavService/Service.svc?xsd=xsd0" namespace="http://tempuri.org/"/><xsd:import schemaLocation="http://server1.domain.nl/NavService/Service.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/></xsd:schema></wsdl:types><wsdl:message name="IService_SendMessageToQueue_InputMessage"><wsdl:part name="parameters" element="tns:SendMessageToQueue"/></wsdl:message><wsdl:message name="IService_SendMessageToQueue_OutputMessage"><wsdl:part name="parameters" element="tns:SendMessageToQueueResponse"/></wsdl:message><wsdl:portType name="IService"><wsdl:operation name="SendMessageToQueue"><wsdl:input wsaw:Action="http://tempuri.org/IService/SendMessageToQueue" message="tns:IService_SendMessageToQueue_InputMessage"/><wsdl:output wsaw:Action="http://tempuri.org/IService/SendMessageToQueueResponse" message="tns:IService_SendMessageToQueue_OutputMessage"/></wsdl:operation></wsdl:portType><wsdl:binding name="BasicHttpBinding_IService" type="tns:IService"><soap:binding transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="SendMessageToQueue"><soap:operation soapAction="http://tempuri.org/IService/SendMessageToQueue" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="Service"><wsdl:port name="BasicHttpBinding_IService" binding="tns:BasicHttpBinding_IService"><soap:address location="http://server1.domain.nl/NavService/Service.svc"/></wsdl:port></wsdl:service></wsdl:definitions>
    

    The function (or method) I have to call is SendMessageToQueue, and I have to pass 3 parameters to it (two ID's and the output of the xmlport).

    Thanks in advance for your effort!
  • Options
    ara3nara3n Member Posts: 9,255
    What kind of webservice is this? I usually use SOAPUI and load the WSDL. It generates the xml file needed to access the webservice. In your case it's erroring out.
    One suggestion is to start visual studio and try and consume the webservice and see that it works.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    livingdolllivingdoll Member Posts: 45
    Hi Rashed,

    I managed to call the server (the webservice has been changed to a classic one) and sent some xml (and get something back). It works fine, as long as the xml that I send does match the xml that the service is expecting.

    But now the problem: we intend to use this service for exchanging changes on some 15 different master data tables. For example: when a field in de customer table changes, I want to send the modified data over to the webservice. So the xml that I want to send to the service varies per master table. For the currency table, the layout of the xml will be different.

    So I have 15 different xmlports that produce 15 different xmlfiles for 15 different master tables. I want to be able to sent these files to the same classic webservice. How can I achieve that? A collegue that handles the .net side of the service brought up 'streaming of the xml files', but I have no clue on that matter. Do you have an idea? The service that has to be called is an internal one, so we can make modifications to that if that's necessary.

    Best regards,

    Jes
Sign In or Register to comment.