Consuming a webservice in Nav2009R2 - migration to .Net

Hello,

i have made a small solution for exporting address data to a webservice with soap.

The current technical approach is xmlhttp / XML (Automation Controller). Now i want to migrate this small solution to .Net.

I have knowlegde in vb.net to create a classes, functions, procedures and attach wsdl files as webreferences.

But i dont know, how to “upload” the (XML) data to this assembly, invoke the Service to send the request, handle with the Response XML and handle the faults.

Could you help me with some tips, code snippets, samples?

/Peter

Attached you will find my current solution (at the end there is the wsdl part)

OBJECT Codeunit 50009 XMLPort Export Test
{
OBJECT-PROPERTIES
{
Date=05.12.13;
Time=11:45:10;
Version List=;
}
PROPERTIES
{
OnRun=BEGIN
RunService(1);
END;

}
CODE
{

PROCEDURE RunService@1000000000(ServiceNo@1000000000 : Integer);
VAR
TempBLOB@1000000007 : Record 99008535;
Utility@1000000010 : Codeunit 50001;
MyXmlPort@1000000004 : XMLport 50009;
xmlHttp2@1000000003 : Automation “{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{F6D90F16-9C73-11D3-B32E-00C04F990BB4}:‘Microsoft XML, v6.0’.XMLHTTP”;
xmlDoc2@1000000002 : Automation “{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:‘Microsoft XML, v6.0’.DOMDocument”;
ServiceEndPoint@1000000008 : Text[1024];
TempInstream@1000000006 : InStream;
OutStream@1000000005 : OutStream;
Success@1000000001 : Boolean;
BEGIN
CREATE(xmlDoc2);
xmlDoc2.async := FALSE;

CLEAR(TempBLOB);
TempBLOB.Blob.CREATEOUTSTREAM(OutStream);
CASE ServiceNo OF
1 : BEGIN
MyXmlPort.SETDESTINATION(OutStream);
MyXmlPort.EXPORT;
ServiceEndPoint := 'webservice.mydomain.com/…/MyService’;
END;
END;

TempBLOB.CALCFIELDS(Blob);
TempBLOB.Blob.CREATEINSTREAM(TempInstream);

xmlDoc2.load(TempInstream);
xmlDoc2.save(Utility.GetFilename(‘Test0001.xml’));

CREATE(xmlHttp2);
xmlHttp2.open(‘POST’,ServiceEndPoint,0,GetUserID,GetPassword);
xmlHttp2.setRequestHeader(‘Content-type’,‘application/soap+xml; charset=utf-8’);
xmlHttp2.setRequestHeader(‘SOAPAction’,'webservice.mydomain.com/…/AddressService’);:wink:

xmlHttp2.send(xmlDoc2);

xmlDoc2.loadXML(xmlHttp2.responseText);
xmlDoc2.async := TRUE;

xmlDoc2.save(Utility.GetFilename(‘Test0001.xml’));

IF xmlHttp2.status = 200 THEN
MESSAGE(’%1’, xmlDoc2.documentElement.selectSingleNode(‘soap:Body/AdressStoreRequest/AddressStore/City’).text)
ELSE
MESSAGE(’%1’, xmlHttp2.status);
END;

PROCEDURE GetUserID@1000000001() Result : Text[30];
BEGIN
Result := ‘myuserid’;
END;

PROCEDURE GetPassword@1000000002() Result : Text[30];
BEGIN
Result := ‘mypassword’;
END;

BEGIN
END.
}
}

OBJECT XMLport 50009 KGV MyService Test
{
OBJECT-PROPERTIES
{
Date=05.12.13;
Time=11:45:40;
Version List=;
}
PROPERTIES
{
Encoding=UTF-8;
OnInitXMLport=BEGIN
xmlnssoapenv:='schemas.xmlsoap.org/…/’;
xmlnsmes:='software.com/…/messages’;
END;

}
ELEMENTS
{
{ [{280C3D79-6EE6-4E96-B1E0-6A1E2B9E1131}]; ;soapenv:Envelope ;Element ;Text }

{ [{C4D63017-26F6-4C5A-89A7-5C9EA7A314BC}];1 ;xmlns:soapenv ;Attribute;Text ;
VariableName=xmlnssoapenv }

{ [{38775F07-19F6-4669-A916-E0ADFB8A030A}];1 ;xmlns:mes ;Attribute;Text ;
VariableName=xmlnsmes }

{ [{40E58184-F47A-47A1-91CC-64B75182678A}];1 ;soapenv:Header ;Element ;Text }

{ [{356B76DB-6FFB-446E-83AF-4F7F85247336}];1 ;soapenv:Body ;Element ;Text }

{ [{FCB5DC8E-EFBD-4F5D-84BD-11FB40E69B75}];2 ;mes:AddressStoreRequest;Element;Text }

{ [{CC900C97-1E7A-45B6-975D-1A949683773C}];3 ;AddressStore ;Element ;Table ;
VariableName=Cust;
SourceTable=Table18;
Export::OnAfterGetRecord=BEGIN
State := Cust.Name;
street := Cust.Address;
housenumber := Cust.Address;
zip := Cust.“Post Code”;
city := Cust.City;
isoCode := Cust.“Country/Region Code”;
END;
}

{ [{FB92F0F8-E4BB-45E0-A9D5-40C3A3C8D357}];4 ;State ;Element ;Text }

{ [{05FF6850-3307-4320-9163-9BC8EBDDCDBD}];4 ;street ;Element ;Text }

{ [{0EF57347-1249-41CA-A79A-291358E87B40}];4 ;housenumber ;Element ;Text }

{ [{3454FB34-C43B-49BF-BA19-011C356F048D}];4 ;zip ;Element ;Text }

{ [{E12D6777-A110-4F66-B1E4-51A460DC9219}];4 ;city ;Element ;Text }

{ [{0318AF5F-9809-401D-901F-15EEAC4FA55E}];4 ;country_identifier ;Element ;Text }

{ [{D4A37785-1B76-4E08-B338-98A49A5014F5}];5 ;isoCode ;Element ;Text }

}
EVENTS
{
}
REQUESTPAGE
{
PROPERTIES
{
}
CONTROLS
{
}
}
CODE
{

BEGIN
END.
}
}

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<wsdl:definitions xmlns:soap=“http://schemas.xmlsoap.org/wsdl/soap/
xmlns:wsdl=“http://schemas.xmlsoap.org/wsdl/
xmlns:xsd=“http://www.w3.org/2001/XMLSchema
xmlns:tns=“http://software.com/soap/adv/messages
targetNamespace=“http://software.com/soap/adv/messages”>

wsdl:types

<xsd:schema targetNamespace=“http://software.com/soap/adv/types” xmlns:tns=“http://software.com/soap/adv/types”>

<xsd:complexType name=“StoreFault”>
<xsd:attribute name=“name” type=“xsd:string” />
<xsd:attribute name=“messageCode” type=“xsd:string” />
</xsd:complexType>

<xsd:complexType name=“CountryIdentifier”>
xsd:annotation
xsd:documentationThis identifier contains all attributes to clearly identfy the associated country.</xsd:documentation>
</xsd:annotation>
xsd:sequence
<xsd:element name=“isoCode” type=“xsd:string”/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name=“AddressStore”>
xsd:sequence
<xsd:element name=“state” type=“xsd:string” minOccurs=“0”/>
<xsd:element name=“street” type=“xsd:string” minOccurs=“0”/>
<xsd:element name=“housenumber” type=“xsd:string” minOccurs=“0”/>
<xsd:element name=“zip” type=“xsd:string” minOccurs=“0”/>
<xsd:element name=“city” type=“xsd:string” minOccurs=“0”/>

<xsd:element name=“countryIdentifier” type=“tns:CountryIdentifier” minOccurs=“0”/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name=“AddressStoreResult”>
xsd:sequence
<xsd:element name=“state” type=“xsd:string”></xsd:element>
<xsd:element name=“street” type=“xsd:string”></xsd:element>
<xsd:element name=“housenumber” type=“xsd:string”></xsd:element>
<xsd:element name=“zip” type=“xsd:string”></xsd:element>
<xsd:element name=“city” type=“xsd:string”></xsd:element>

<xsd:element name=“countryIdentifier” type=“tns:CountryIdentifier” minOccurs=“0”/>
</xsd:sequence>
</xsd:complexType>

</xsd:schema>

<xsd:schema targetNamespace=“http://software.com/soap/adv/messages” xmlns:tns=“http://software.com/soap/adv/messages” xmlns:t=“http://software.com/soap/adv/types”>
<xs:import xmlns:xs=“http://www.w3.org/2001/XMLSchema” namespace="http://software.com/soap/adv/types"/>

<xsd:element name=“AddressStoreRequest”>
xsd:complexType
xsd:sequence
<xsd:element name=“AddressStore” type=“t:AddressStore” />
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name=“AddressStoreResponse”>
xsd:complexType
xsd:sequence
<xsd:element name=“NodeId” type=“xsd:long”/>
<xsd:element name=“NodeVersionId” type=“xsd:long”/>
<xsd:element name=“id” type=“xsd:string”/>
<xsd:element name=“storeResult” type=“t:AddressStoreResult” minOccurs=“0”>
xsd:annotation
xsd:documentation
If configured a subset of the stored data will be added to the response.
This should be useful to get e.g. generated identfier values for using with Identifier elements.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:element name=“StoreFaults”>
xsd:complexType
xsd:sequence
<xsd:element name=“Error” type=“t:StoreFault” maxOccurs=“unbounded” />
</xsd:sequence>
</xsd:complexType>
</xsd:element>

</xsd:schema>
</wsdl:types>

<wsdl:message name=“AddressStoreRequest”>
<wsdl:part name=“AddressStoreRequest” element=“tns:AddressStoreRequest” />
</wsdl:message>
<wsdl:message name=“AddressStoreResponse”>
<wsdl:part name=“AddressStoreResponse” element=“tns:AddressStoreResponse” />
</wsdl:message>
<wsdl:message name=“AddressStoreFault”>
<wsdl:part name=“AddressStoreFault” element=“tns:StoreFaults” />
</wsdl:message>

<wsdl:portType name=“AddressPort”>
<wsdl:operation name=“store”>
<wsdl:input message=“tns:AddressStoreRequest” />
<wsdl:output message=“tns:AddressStoreResponse” />
<wsdl:fault name=“fault” message=“tns:AddressStoreFault” />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name=“AddressSOAP” type=“tns:AddressPort”>
<soap:binding style=“document” transport=“http://schemas.xmlsoap.org/soap/http” />
<wsdl:operation name=“store”>
<soap:operation soapAction="" />
wsdl:input
<soap:body use=“literal” />
</wsdl:input>
wsdl:output
<soap:body use=“literal” />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name=“Address”>
<wsdl:port binding=“tns:AddressSOAP” name=“AddressSOAP”>
<soap:address location=“https://webservice.mydomain.com/soap/AddressService” />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>