Monday, 6 August 2012

Read response from invoking Siebel CRM “EAI HTTP Transport” business service

 

I wrote a post some time ago about how to call URL from Siebel CRM. This post will deal with processing the response from remote page.

So here you go, follow the instructions from my previous post and submit data to remote page. Many times you expect not only to send data, but also receive a response back.

To remind you , in order to send data you have to invoke

oService.InvokeMethod("SendReceive", oInputs, oOutputs);

Common sense tells you that response is probably located in object.


But if you try to run


oOutputs.GetValue();

You will get the following error message


PropertySet GetValue call failed. PropertySet Value is marked as binary data, starting with….

And this is because Siebel can process data only in UTF-16 encoding. If it is not, Siebel “thinks” that it is a binary data.

Bellow is very simple code to convert the HTTP output to a proper format


var oTransService = TheApplication().GetService("Transcode Service");
var oTransOutputs = TheApplication().NewPropertySet();
oOutputs.SetProperty(
"ConversionMode", "EncodingToString");
oOutputs.SetProperty(
"SourceEncoding", "CP1252");
oTransService.InvokeMethod(
"Convert", oOutputs, oTransOutputs);
var sResponse = oTransOutputs.GetValue();

After you execute it. You will fine HTTP response string in sResponse variable.

P.S. You can find more information in 536101.1 metalink note

Tuesday, 31 July 2012

Invoking web service from Siebel with EAI HTTP Transport Business Service

 

Some recent task I did was to invoke a web-service from Siebel to send SMS message.

I have to admit that I never did such a thing before. So I started to read Siebel “bookshelf”  documentation (you can throw this crap to the garbage . It is worthless), search Google. Found plenty bad written tutorials about invoking workflow process that can invoke web service or call http URL.

      Half of the staff I didn’t understand, the  other half didn’t like, but I understood one thing: at the end Siebel works with a Business Service (BC) called “EAI HTTP Transport “.

As I mentioned I am not to good with clicking on buttons in Siebel Tools, but pretty good with writing code. So if I know that Siebel uses a BC, why not to use it directly?

  The result is this simple function that defines XML message and uses POST method to submit data to remote web-service


function SendSms(Inputs, Outputs)
{
//get Business Service
var bs = TheApplication().GetService("EAI HTTP Transport");
var inp = TheApplication().NewPropertySet();
var outputs1 = TheApplication().NewPropertySet();
// it is web-service, so use POST method
inp.SetProperty("HTTPRequestMethod","POST");
//Content type as in all HTTP request
inp.SetProperty("HTTPContentType", "text/xml; charset=UTF-8");
//web-service end point
inp.SetProperty("HTTPRequestURLTemplate","https://**********/imsc/interfaces/largeaccount/la3.sms");
//define the data to be send
var reqVal = '<?xml version="1.0" encoding="utf-8" ?> '+
'<request> '+
' <head> '+
' <auth> '+
' <account>CompanyName</account> '+
' <user>userName</user> '+
' <pass>Pass</pass> '+
'</auth> '+
' <action>sendsms</action> '+
' </head> '+
' <body> '+
' <addr> '+
' <from>039535640</from> '+
' <to> '+
' <cli>97254545450</cli> '+
' </to> '+
'</addr> '+
'<data> '+
' <msgtype>text</msgtype> '+
' <text>This is SMS message text</text> '+
' </data> '+
' <billing> '+
' <port>0</port> '+
' </billing> '+
' </body> '+
'</request>';
//set the data
inp.SetProperty("HTTPRequestBodyTemplate",reqVal);
//invoke. The result can be found in "Outputs"
bs.InvokeMethod("SendReceive",inp,Outputs);
}