Is return supposed to return a boolean (0/1) or the non empty value of check1?

I'm asking because you write "will return false even for non-empty strings (due to conversion to integers for string prefixes)".

In general to check for not empty string (check1'="") is used.

If you need to return a boolean depending of empty/not empty, then you can use:

return (check1'="") 

If/when you set KeepIntegrity to True, then ALL messages and message headers belonging to a session containing ANY message with status Created or Queued or Delivered or Suspended or Deferred are NOT deleted/purged, same goes for the headers (Ens.MessageHeader).

Since your is a test environment, it's (very?) likely having "messed" sessions that are not purged using KeepIntegrity  = True.
Sometimes even production systems do have sessions that are not purged using KeepIntegrity  = True.

While setting using KeepIntegrity  = True is "best practice" and prevent purging "uncompleted sessions", I suggest to run a purge with KeepIntegrity  = False with a (much?) longer DaysToKeep parameter, unless you do need/want to keep uncompleted sessions and messages for.....ever and ever.

For example, if you purge with KeepIntegrity  = True and DaysToKeep=30, you may run a second purge with KeepIntegrity  = false and DaysToKeep=90 (or longer) to purge really old messages belonging to "uncompleted" sessions.

Code adapted with your details:

Set objHttpRequest = ##class(%Net.HttpRequest).%New()
Set objHttpRequest.ContentType = "application/fhir+json"
Set objHttpRequest.Server = "localhost"
Set objHttpRequest.Port = "52773"
Set pRequest = {"asd":"asd"}
Do objHttpRequest.EntityBody.Write(pRequest.%ToJSON())
If objHttpRequest.Send("POST", "/aktest/test") {
    Set objHttpResponse = objHttpRequest.HttpResponse
    If $IsObject(objHttpResponse.Data) {
        Set objStream = objHttpResponse.Data
        Set json = ""
        While ('objStream.AtEnd) {
            Set json = json _ objStream.ReadLine()
        }
    } Else {
        Set json = objHttpResponse.Data
    }
    Set httpStatus = objHttpResponse.StatusCode
    Write "Status: ", httpStatus, !
    Write "Response: ", json, !
}

I do not understand your question, can you please explain what you need to achieve?

%Net.HttpRequest class is used to create an HTTP request that is sent to the counterpart/endpoint and a response message is then received from the counterpart. How can you possibly generate a response that, by definition, has to be received from a remote system?

Clearly I'm missing something.

You may try with:

set tQuery="{ CALL dbo.SavePatientDetails (?) }"

Set tParams=1
Set tParams(1)=xmlContent
Set tParams(1,"SqlType")=$$$SqlVarchar ; or 12 if macro does not resolve
Set tSC = ..Adapter.ExecuteProcedureParmArray(.tResultSnapshots, .tOutputParms, tQuery,,.tParams)

For details see the SQL adapters documentation on Using Parameters.
 

To debug your issue I suggest to enable SOAP logging setting this two global node:

Set ^ISCSOAP("LogFile")="/path/to/yourlog/filename.log"
Set ^ISCSOAP("Log")="ios"

Values for ^ISCSOAP("Log") are:
"i" — Log inbound messages
"o" — Log outbound messages
"s" — Log security information.

Then call your SOAP service and check the log file for hints on the actual issue.

When finished debugging remember to turn it off with Set ^ISCSOAP("Log")="" or Kill ^ISCSOAP("Log")

In error handling code, when using SOAP and a <ZSOAP> error in triggered, the actual error status is contained in %objlasterror variable, so:

Set displayString = ex.DisplayString()
If displayString [ "<ZSOAP>" {
    Set displayString=$system.Status.GetErrorText(%objlasterror)
}

It's all documented, I cannot post documentation links because the documentation site it's not working for me at the moment.

According to the documentation, it's not possible exporting an object.

Edit: however, as pointed out by @Herman Slagman in the next post, it's indeed possible, I'm going to provide feedback to documentation team.

You can manually create the XML document using %XML.Writer, like:

	set writer=##class(%XML.Writer).%New()
	set writer.Indent=1
	set writer.NoXMLDeclaration=1
	set status=writer.OutputToDevice()
	set status=writer.StartDocument()
	set status=writer.RootElement("XMLTest")
	set status=writer.Element("Id")	
	set status=writer.WriteAttribute("Attribute","D1949EE1-7D03-4666-9548-D1A949E10327")
	set status=writer.EndElement()
	set status=writer.EndRootElement()
	set status=writer.EndDocument()

The output of the above code is:

<XMLTest>
  <Id Attribute="D1949EE1-7D03-4666-9548-D1A949E10327"/>
</XMLTest>

Having said that, what's your issue with the closing tag? Semantically there is no difference, any system should be able to handle both cases (with or without closing tag).