CALL EXTERNAL WEB SERVICE USING CU 1290 – Part 2

I wrote a blog post about calling external web services from Nav, which you can find here. I was asked, how in detail variable reqText works. reqText is the xml value, which is given to the web service as parameter value. For that i developed a simple web service in c#.

 namespace WebServiceNS  
 {  
   [WebService(Namespace = "http://tempuri.org/")]  
   [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]  
   [System.ComponentModel.ToolboxItem(false)]  
   public class WebService1 : System.Web.Services.WebService  
   {  
     [WebMethod]  
     public string GetUpperCase(string lowerCaseText)  
     {  
       if (!string.IsNullOrEmpty(lowerCaseText))  
         return lowerCaseText.ToUpper();  
       return string.Empty;  
     }  
   }  
 }  

Then i ran the new webservice from Visual Studio with http://localhost:63427/WebService1.asmx?op=GetUpperCase. The port is, as you may know, dynamically set by Visual Studio.

In the browser window you can then see then the wsdl code:
POST /WebService1.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: “http://tempuri.org/GetUpperCase”

 <?xml version="1.0" encoding="utf-8"?>  
 <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">  
  <soap:Body>  
   <GetUpperCase xmlns="http://tempuri.org/">  
    <lowerCaseText>string</lowerCaseText>  
   </GetUpperCase>  
  </soap:Body>  
 </soap:Envelope>  

To call the web service with c/al and set the correct value for reqText, simply copy the lines between the soap:Body tag and paste it to your c/al.
So the value for reqText in that case is:

 reqText := '<GetUpperCase xmlns="http://tempuri.org/"><lowerCaseText>hello</lowerCaseText></GetUpperCase>';  

GetUpperCase is the webmethod name , tag property xmlns is set with the namespace defined as attribute in the c# webmethod. lowercasetext is the name of the parameter. So it’s quite simple to use.

The result, when calling that web service:

 <GetUpperCaseResponse xmlns="http://tempuri.org/"><GetUpperCaseResult>HELLO</GetUpperCaseResult></GetUpperCaseResponse>  

You can see: hello is converted to HELLO..😉

cheers

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s