Problem With IHttpResponse Entity Property

Posted by David O'Regan on 25-Oct-2016 09:29

Hi,

I am having trouble interpreting the response data from an OpenEdge.Net.HTTP.IHttpRequest. The request itself executes as expected and performs it's function.

The problem is that the response object (OpenEdge.Net.HTTP.IHttpResponse) has the correct ContentLength/StatusCode/StatusReason but the Entity and ContentType fields are ? and blank respectively.

Code:

cURL = "http://SomeURL/SomeService":U
oXML = NEW STRING(lcXML)
oURI = URI:Parse(cURL).

ASSIGN
oLib = ClientLibraryBuilder:Build():sslVerifyHost(NO):Library
oRequest = RequestBuilder:Post(oURi,oXML):AcceptAll():ContentType('application/x-www-form-urlencoded'):Request
oResponse = ClientBuilder:Build():UsingLibrary(oLib):Client:Execute(oRequest)
oEntity = oResponse:Entity. 

oResponse:Entity is ? and i'm unable to do anything with it. I have run my routine with:

log-manager:logfile-name = "MyLog.log".
log-manager:logging-level = 6.

And I can see that the response-data-chunk contains the data i am looking for from the httpresonse. I am expecting XML as the response data, for what it's worth.

Any ideas where I am going wrong? 

Thanks.

Posted by Peter Judge on 01-Nov-2016 11:32

They’re not sending a Content-Type header back, so the HttpClient cannot know what to transform to. Given that we say
        /* populate the entity if there's content (signalled by content-type) */
        if poResponse:ContentType ne '':u then
            ExtractEntity(poResponse, oMessageBody).
 
This explains why you’re not seeing a body. I’ve logged PSC00351636 (ABLSocketLibrary should check for ContentType hdr then extant body) for this. If you’d like to be associated with it, please contact Tech Support.
 
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 01 Nov 2016 16:03:11 GMT
Content-Length: 254
 
<?xml version='1.0' encoding='utf-8'?>
<createOrderResult>
   <Status>OK</Status>
   <Action>Edit</Action>
   <WebOrder>4598</WebOrder>
   <URL>testshop.dacapo.com/punchoutorder.aspx
</createOrderResult>
 
 
 
 
 

All Replies

Posted by David O'Regan on 01-Nov-2016 06:13

Hi All,

I have spent some more time working on this and come up with a solution, of sorts, but am failing to understand why it works and my above solution does not. If anyone could shed some light I'd appreciate so i understand better going forward (or anyone else has this issue).

First a little more information, in case it's relevant. I am running version 11.6 SP 3 and the service I am trying to call is a third-party SOAP web service that requires an XML document passed to it and responds in kind with an XML document.

Running the same request as my original post through POSTMAN or SOAPUI is successful.

In the end i managed to get it working in my program by opting to use the System.Net.WebClient instead of OpenEdge.Net.HTTP.

Here is the code I am using (successful), it is my understanding that this should not be functionally different from the above?

/**** Code ****/

/* lcXML is a longchar generated by write-xml and webResponse is a longchar */

ASSIGN  

 cURL = "http://Site/Service".  

FIX-CODEPAGE(webResponse) = "UTF-8".

HttpClient = NEW System.Net.WebClient().

httpClient:headers:add("content-type":U,"application/x-www-form-urlencoded":U).

webResponse = HttpClient:UploadString(curl,"xmlRequest=":U + lcXML).

HttpClient:Dispose().

DELETE OBJECT HttpClient.

MESSAGE WebResponse VIEW-AS ALERT-BOX. /* Success! */

Hope this helps if anyone is having the same problem. Hopefully someone can explain where I am going wrong.

Thanks,

David

Posted by Brian K. Maher on 01-Nov-2016 06:18

David,
 
I may be missing something but if this is a normal Web Service, why aren’t you using the bprowsdldoc utility to generate the documentation for it then using the built-in ABL Web Service support?  The output from bprowsdldoc will even generate the ABL code you need to connect and to call any specific function.
 
Brian Maher

Posted by David O'Regan on 01-Nov-2016 06:31

Hi Brian,

Originally I had wanted to use the http options afforded by version 11.6 since it was just a simple post operation.

I did actually run the bprowsdldoc utility and attempt to get it work using the stubs provided but was still unable to get the response correctly. The request function seemed to resolve correctly but I would get an error saying:

"Error receiving Web Service Response: Version Mismatch. 'createResult:(null)' is not supported SOAP Envelope".

The wsdl doc itself contains namespaces for both SOAP 1.1 and 1.2 so I am unsure what exactly needs to be done about this error. The stubs provided by the bprowsdldoc utility don't specify how to get the response (can only be run as a procedure and has no output param).

Is there any reason not to use http methods as opposed to this?

Thanks.

Posted by Brian K. Maher on 01-Nov-2016 06:42

David,
 
You can use the HTTP methods if you want, its just that the Web Service support is normally easier.  Have you tried running bprowsdldoc with the -show100style parameter?  That may get you something different.
 
One common mistake people make when using the Web Services support is to use the XML format specified by the vendor instead of what bprowsdldoc shows.  For example, vendor documentation may show sample XML with specific namespaces whereas bprowsdldoc will show the same with with the ns0 namespace.  If you use the vendor formatting things will fail but if you pass what we tell you to pass it will work.  I work in support and have seen this mistake numerous times.
 
Brian

Posted by David O'Regan on 01-Nov-2016 08:57

Brian,

I have just tried running it with the parameter you suggested and, indeed, it does show quite different results. Using this method I can see that it specifies an output parameter to get the response data (not sure why I don't get this without -show100style) and using the ns0 namespace as you suggest seems to help.

I am still getting an error but I think that's because I haven't yet got to figuring out how to set the content-type to the required value using this method. I'll play with this a bit more when I get time and see if it works with the correct content-type.

I will probably just use the system.net.webclient method for the time being since it's working correctly and is simpler to implement. I just don't understand why this works but my first example doesn't...

Thanks for your assistance.

David

Posted by Peter Judge on 01-Nov-2016 10:54

Couple of things

- are you catching errors? if so, are there any?

- if you look at the response-data-received.txt does it contain what you expect? note that there may be a bunch of (expected) null characters

- are there any errors /oddities in the MyLog.log file?

Posted by David O'Regan on 01-Nov-2016 11:10

Hi Peter,

I am catching errors but not getting any.

The response-data-received.txt does have the correct data I believe (the XML is in there and i get status 200 OK), there is no content-type header but i am unsure if that is an issue.

The MyLog final few lines contains the following:

[16/11/01@16:00:28.320+0000] P-001140 T-004340 1 4GL SOCKET         READ: COMPLETE= yes

[16/11/01@16:00:28.320+0000] P-001140 T-004340 1 4GL SOCKET         READ: ERROR= ?

[16/11/01@16:00:28.320+0000] P-001140 T-004340 1 4GL SOCKET         READ: TOTAL TIME(ms)=252

[16/11/01@16:00:28.320+0000] P-001140 T-004340 1 4GL SOCKET         READ: TOTAL SIZE(b)=445

I don't know the significance of READ:ERROR= ?, does this mean no error was encountered or that the error returned evaluated to ?

Posted by Peter Judge on 01-Nov-2016 11:16

That means there was no error raised during the socket’s reading of the response.
 
Can you send me or attach the response-data-received file ? So far it looks like it should be working …
 

Posted by David O'Regan on 01-Nov-2016 11:23

[View:/cfs-file/__key/communityserver-discussions-components-files/19/3364.response_2D00_data_2D00_received.txt:320:240]

Please see attached.

Thanks for your help on this.

(edited to remove unique code from response).

Posted by Peter Judge on 01-Nov-2016 11:32

They’re not sending a Content-Type header back, so the HttpClient cannot know what to transform to. Given that we say
        /* populate the entity if there's content (signalled by content-type) */
        if poResponse:ContentType ne '':u then
            ExtractEntity(poResponse, oMessageBody).
 
This explains why you’re not seeing a body. I’ve logged PSC00351636 (ABLSocketLibrary should check for ContentType hdr then extant body) for this. If you’d like to be associated with it, please contact Tech Support.
 
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Tue, 01 Nov 2016 16:03:11 GMT
Content-Length: 254
 
<?xml version='1.0' encoding='utf-8'?>
<createOrderResult>
   <Status>OK</Status>
   <Action>Edit</Action>
   <WebOrder>4598</WebOrder>
</createOrderResult>
 
 
 
 
 

Posted by David O'Regan on 01-Nov-2016 11:42

Ok, that makes sense.

Thanks for your help!

This thread is closed