0

Is there any way that I can write javascript that runs in the browser to create client code and connect to a net.tcp service endpoint and port?

For example, I know that a service contract is exposed at the endpoint https://www.demoexamplething.com:8001/service/mex (example), and is running on .NET server-side code (WCF or something else). How can I use javascript to connect to this endpoint and use its web services?

I know that in a .NET project that I would simply create a "Connected Service" reference and auto-generate client code to work with requests and responses. How can this be done in Javascript?

Fuzzy Analysis
  • 3,168
  • 2
  • 42
  • 66
  • 1
    When you say client code, do you mean you're running this JavaScript in the browser? Or a TCP client that runs server-side? You can't make arbitrary TCP connections from within a browser, but there's also no reason to do so in this case... you can use the Fetch API for a web service. – Brad Jan 30 '20 at 04:07

1 Answers1

2

Is there any way that I can write javascript that runs in the browser to create client code and connect to a net.tcp service endpoint and port?

No, you can't make arbitrary TCP connections from the browser, short of making a browser extension.

For example, I know that a service contract is exposed at the endpoint...

For HTTP requests, you don't need to make a TCP connection. You can use the Fetch API to make an HTTP request. For example:

const res = await fetch('https://example.com');
const data = await res.text();

See also: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API

I know that in a .NET project that I would simply create a "Connected Service" reference and auto-generate client code to work with requests and responses.

It's been a long time since I've messed with that... but wasn't there a WSDL or something that helped define the request/response data? I bet someone has made a JavaScript module that wraps Fetch or XHR. I wouldn't know specifically what to search for, but check over on NPM.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • @gforce301 Thanks. There's a WiFi antenna on the back. Was going to mod an access point, with a directional antenna in the front for relaying a distant access point. :-) – Brad Jan 30 '20 at 05:28