Topic
  • 6 replies
  • Latest Post - ‏2012-11-15T20:06:45Z by SystemAdmin
SystemAdmin
SystemAdmin
2327 Posts

Pinned topic Web services unable to consume through HTTP Adapter

‏2012-11-14T10:09:35Z |
Hi All,

I am working on a Worklite application that uses a HTTP adapter to invoke my REST web services written using Microsoft WCF framework. I am getting the following error when I invoke the function through the worklite http adapter invoker

{
"errors": [
"Runtime: Failed to parse JSON string\n\"\""
],
"info": [
],
"isSuccessful": false,
"warnings": [
]
}

whereas in the Worklite console I see the following information


2012-11-14 15:07:16 Procedure invocation finished
2012-11-14 15:07:16 An error occurred while invoking procedure WebServiceAdapter/HttpRequest parameters: {
"arr": [
{
"method": "get",
"path": "Service1\/GetEmployeeDetail",
"returnedContentType": "json"
}
]
}
Failed to parse JSON string
""
Caused by: java.io.IOException: Expecting '{' on line 1, column 32 instead, obtained token: 'Token: String - '''
A snap shot of my REST method as follows


[WebInvoke(Method = "GET", UriTemplate = "/GetEmployeeDetail", RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
OperationContract
public string GetEmployeeDetail()
{
List<EmployeeDetail> employeeDetail = new List<EmployeeDetail>();
EmployeeDetail empDetail1 = new EmployeeDetail();
empDetail1.EmployeeName = "Test1";
employeeDetail.Add(empDetail1);
System.Web.Script.Serialization.JavaScriptSerializer jSearializer =
new System.Web.Script.Serialization.JavaScriptSerializer();
UTF8Encoding encoder = new UTF8Encoding();
byte[] bytes = Encoding.UTF8.GetBytes(jSearializer.Serialize(employeeDetail));
string utf8ReturnString = encoder.GetString(bytes);
return utf8ReturnString;
}

Adapter.js file has few set of codes given below:

function getWCFWebService1()
{

var input =
{
method : 'get',
returnedContentType : 'json',
path : 'Service1/GetEmployeeDetail',

};
}

I am unable to solve this issue, any help to resolve this issue is appreciated.

TIA,
Anu
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Web services unable to consume through HTTP Adapter

    ‏2012-11-14T16:30:28Z  
    Can you provide example output for: return utf8ReturnString; ?
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Web services unable to consume through HTTP Adapter

    ‏2012-11-15T06:25:15Z  
    Can you provide example output for: return utf8ReturnString; ?
    Thanks for the attempt to help.
    output for: return utf8ReturnString is:
    Thanks,
    Anu
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Web services unable to consume through HTTP Adapter

    ‏2012-11-15T08:33:48Z  
    Thanks for the attempt to help.
    output for: return utf8ReturnString is:
    Thanks,
    Anu
    Thanks for the attempt to help.
    output for: return utf8ReturnString is:

    Thanks,
    Anu
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Web services unable to consume through HTTP Adapter

    ‏2012-11-15T08:37:10Z  
    Can you provide example output for: return utf8ReturnString; ?
    Thanks for the attempt to help.
    output for: return utf8ReturnString is attached, since the output was not displayed as expected.
    "EmployeeName":"Test1"

    Thanks,
    Anu
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Web services unable to consume through HTTP Adapter

    ‏2012-11-15T19:13:30Z  
    Thanks for the attempt to help.
    output for: return utf8ReturnString is attached, since the output was not displayed as expected.
    "EmployeeName":"Test1"

    Thanks,
    Anu
    I am unable to reproduce, compare your code with mine:

    node server.js

    
    var restify = require(
    'restify'); var server = restify.createServer();   server.get(
    '/json', function (req, res) 
    { res.writeHead(200, 
    { 
    'Content-Type': 
    'application/json'
    }); res.end(JSON.stringify([
    {EmployeeName : 
    "Test1"
    }])); 
    });   server.listen(9081, function() 
    { console.log(
    '%s listening at %s', server.name, server.url); 
    });
    


    test.xml (parts have been removed for brevity)

    
    <connectivity> <connectionPolicy xsi:type=
    "http:HTTPConnectionPolicyType"> <protocol>http</protocol> <domain>localhost</domain> <port>9081</port> </connectionPolicy> <loadConstraints maxConcurrentConnectionsPerNode=
    "2" /> </connectivity>   <procedure name=
    "json"/>
    


    test-impl.js

    
    function json () 
    { var input = 
    { method : 
    'get', returnedContentType : 
    'json', path : 
    '/json' 
    }; 
    
    return WL.Server.invokeHttp(input); 
    }
    


    app-name.js

    
    var invocationData = 
    { adapter : 
    'test', procedure : 
    'json', parameters : [] 
    };   var adapterWin = function (data) 
    { alert(JSON.stringify(data.invocationResult.array); 
    //[{"EmployeeName: "Test1"}] 
    };   WL.Client.invokeProcedure(invocationData, 
    {onFailure: fail, onSuccess: adapterWin
    });
    
  • SystemAdmin
    SystemAdmin
    2327 Posts

    Re: Web services unable to consume through HTTP Adapter

    ‏2012-11-15T20:06:45Z  
    I am unable to reproduce, compare your code with mine:

    node server.js

    <pre class="jive-pre"> var restify = require( 'restify'); var server = restify.createServer(); server.get( '/json', function (req, res) { res.writeHead(200, { 'Content-Type': 'application/json' }); res.end(JSON.stringify([ {EmployeeName : "Test1" }])); }); server.listen(9081, function() { console.log( '%s listening at %s', server.name, server.url); }); </pre>

    test.xml (parts have been removed for brevity)

    <pre class="jive-pre"> <connectivity> <connectionPolicy xsi:type= "http:HTTPConnectionPolicyType"> <protocol>http</protocol> <domain>localhost</domain> <port>9081</port> </connectionPolicy> <loadConstraints maxConcurrentConnectionsPerNode= "2" /> </connectivity> <procedure name= "json"/> </pre>

    test-impl.js

    <pre class="jive-pre"> function json () { var input = { method : 'get', returnedContentType : 'json', path : '/json' }; return WL.Server.invokeHttp(input); } </pre>

    app-name.js

    <pre class="jive-pre"> var invocationData = { adapter : 'test', procedure : 'json', parameters : [] }; var adapterWin = function (data) { alert(JSON.stringify(data.invocationResult.array); //[{"EmployeeName: "Test1"}] }; WL.Client.invokeProcedure(invocationData, {onFailure: fail, onSuccess: adapterWin }); </pre>
    One more thing, you should check that your REST service is working as expected via a browser and/or command line tool like curl or wget:
    http://f.cl.ly/items/0O190U2e1E2V1C3N0w3C/Screen%20Shot%202012-11-15%20at%202.08.41%20PM.png