How to get an IP address from an HttpResponseMessage? - dotnet-httpclient

Can one get an IP address from an HttpResponseMessage when using HttpClient (in System.Net.Http)?

There is no way to get an IP Address (presumably of the remote server) from only a HttpResponseMessage.
The HttpResponseMessage type does not expose such a property and it does not contain any types which have this information. This means that the request can't be answered, even with the use of reflection.
See the reference source code for HttpResponseMessage.cs.

Related

How to get line items from Business Central Web Service (Odata)?

From Microsoft Documentation, to get salesOrderLines, the following http request is needed:
GET businesscentralPrefix/companies({id})/salesOrders({id})/salesOrderLines({salesOrderLineId})
However, it assumes each json object has a unique GUID. But when I try to get Odata, the only thing close to a unique id I get back is "#odata.etag", and this does not allow me to access the salesOrderLines.
Use /salesOrders?$expand=SalesOrderSalesLines

Spring AMQP custom message correlation using an identifier generated by the app

Spring AMQP custom message correlation using an identifier generated by the app for the outbound gateway using spring integration.
We have a requirement where we need to correlate messages for outbound gateway with an id generated by app, in which actual processing of the messages would happen in external system and the response for the request will come as post from the external system, so we cannot rely on amqp_correlation data.
If you provide the steps for this that will be great.
Solution Tried
Set the correlation key in the rabbit template
Create Message of type AMQP, set the header name with the correleation key set in the template with some generated value
Provide header-mapper in the AMQP outbound gateway for the custom header name
Result
Rabbit template was able to map with the custom header, However it generates its own value, Not using the value that was set in the request/reply messages
Please open a new feature JIRA Issue for this.
Bear in mind it will be your responsibility to ensure the correlationId is unique.
You might be able to work around it by subclassing the template and overriding sendToRabbit; and set up the correlationId there; you would have to save off the template's correlationId (ideally in the message in a different header, but perhaps in a Map) and have the server return that header too.
protected void sendToRabbit(Channel channel, String exchange, String routingKey, boolean mandatory,
Message message) throws IOException {
// fix up properties
super.doSend(...);
}
You would also have to override onMessage() to restore the proper correlationId for the inbound request.

SqlEntityConnection configured with a local schema file

I want to use the SqlEntityConnection type provider in f# to query and update a db.
It works well when I use it with the connection string pointing to a live SQL Server DataBase.
type EntityConnection = SqlEntityConnection<"Data Source=myServer;Initial Catalog=myDb;...", Pluralize=true>
Now I want to get rid of the dependency with the live DB and, instead, use a local schema file. Given what I read on msdn, I gave a try to the following line:
type private EntityConnection = SqlEntityConnection<LocalSchemaFile="mySchemaFile.ssdl", Pluralize=true>
Unfortunately, it doesn't compile and the compiler's message is:
Error 46 The type provider 'Microsoft.FSharp.Data.TypeProviders.DesignTime.DataProviders' reported an error: When using this provider you must specify either a connection string or a connection string name. To specify a connection string, use SqlEntityConnection<"...connection string...">.
So what should I do? If I leave the connection string, I have the feeling that I don't really turn off the dependency to the DB. For instance, if I try to switch the Data Source with a non-existing server, it doesn't compile.
You can provide a connection string name, along with a connection string in the configuration file.
You can still provide a localschemafile that will be used to cache locally the schema.
If you put the schema file under source control, the connection string will only be used as a default when calling GetDataContext() without parameter, but not when building or editing code.
You also need to set the parameter ForceUpdate to False.

MKNetworkKit - Host Name and apiPath parameters

I was thinking of using MKNetworkKit as base for Network operations for an iOS App. I'm a bit confused about using the initWithHostName:customerHeaders: and initWithHostName: apiPath:customerHeaders: methods.
In the App, I need to communicate to a number of hosts and they have different ways of specifying the Host Name and URL. For example:
HostNameX.com - The Domain Name for HostX,
The first host has the service prepended to the Hostname as so:
serviceA.HostNameX.com?someparam=value The Path for ServiceA (returns info)
serviceB.HostNameX.com?someparam=value The Path for ServiceB (returns info)
HostNameY.com - The Domain Name for HostY
The second host has the service or command appended to the Hostname as so:
HostNameY.com/serviceA?someparam =value The Path for ServiceA (returns info)
HostNameY.com/serviceB?someparam =value The Path for ServiceB (returns info)
For the HostNameY.com case, I was thinking of creating one MKEngine Instance and then passing in the "serviceA?someparam=value" or "serviceB?someparam=value" string as the Path parameter to the operationWithPath:params:httpMethod:ssl: method.
This would work well for what I want to do, however for HostNameX.com I'm not sure how to prepend "serviceA." or "serviceB." to the host name? The only way I can see of doing it is to create two separate MKEngine Instances one for "serviceA" and one for "serviceB". Is this the case?
Am I missing something or is there a way to be able to prepend the service to the domain name after calling initWithHostName:apiPath:customerHeaders: ?
Thanks in advance for any suggestions.
All the Best
Dave
For HostNameY.com, you are right. The service name can be part of the path.
And as you mentioned, you should use multiple instances of MKEngine to manage HostNameX.com.
Why you should use multiple instances :
Hostname is a private property of MKNetworkEngine and the only way to change the hostname is to create a new instance of MKNetworkEngine (without modifying MKNetworkEngine). Hostname property is used by MKNetworkEngine to observe Reachability changes and freeze/restore operations. If you change the hostname at runtime for a single instance of MKNetworkEngine (by making hostname property public for example), this feature won't work well on all situations. Just take a look at freezeOperations (called when you loose network) method in MKNetworkEngine.m. It checks if and operation url contains the current hostname. If you have changed the hostname and the operation was created for another host, the operation will not be archived to restore it later when the network is back.
I solved this problem by using the operationWithURLString and building my own URL String. To me anyway, this seems a much better solution than allocating a number of MKEngine Instances just to handle something that can be passed as a parameter. This way I can also append path components as well as parameters to the URL String, for example:
http://serviceA.hostname.com/fred/simmons?isvip=true&hasBooked=false
Interestingly, the parameter dictionary that is passed to operationWithURLString:params:httpMethod: works in two ways:
if the httpMethod is GET, then the dictionary is used to pass parameters in the URL, if the httpMethod is POST or PUT (or DELETE?) then the Dictionary is formatted and sent as the Request Body.
Question - is it valid to have a POST Command with parameters?
For example:
http://bookingservice.hostname.com/bookings?isvip=true&lastname=simmons
Is this a valid URL as a POST not a GET?

A way to exclude self from Bonjour search results

When the same app acts as a Bonjour-enabled service and client at the same time, browsing for self-like services while listening on a socket, what's a good way to exclude self from service search results?
In your NSNetServiceBrowserDelegate you can just ask the incoming service if it is the same as the one you have published:
-(void)netServiceBrowser:(NSNetServiceBrowser *)netServiceBrowser didFindService:(NSNetService *)netService moreComing:(BOOL)moreComing
{
if ([netService isEqual:self.publishedNetService])
return;
…
}
In the server part, when I register my service with Bonjour, I generate a 10 character random alphanumeric string - a cookie. I make it a part of the advertised service name, as provided in call to [NSNetService initWithDomain:type:name:port:]. The resulting name is something like "MyApp on Joe's iPhone\txYbG56HjaE". The part before the tab character is for display, the part after is the cookie. I then store the cookie is a globally visible variable. Since server initialization takes place on app startup, the cookie value is available early on.
In the service discovery part, when I find a service, I check its name; if the cookie is the same as the stored global one, I skip this service. The idea is that other running instances of the program would have different cookie values, because randomness.
Naturally, when displaying discovered service names in the UI, I skip the part after the tab character.

Resources