grpc on angular error

38 views
Skip to first unread message

XCompiler

unread,
May 29, 2020, 2:19:04 PM5/29/20
to grpc.io
I am trying to call a grpc service (the service in created using c#) in angular. i did not used docker on this. i just run the grpc service on my local machine. see code below.

const AbcRequest = new DomainMessage();

    nexusRequest.setMesssage("QueryTest");

 

    grpc.unary(AbcService.Fields, {

      request: AbcRequest,

      host: "https://localhost:5001/",

      onEnd: res =>{

        const { statusstatusMessageheadersmessagetrailers } = res;

        if (status === grpc.Code.OK && message) {

          var result = message.toObject() as AbcResponse.AsObject;

          

          this.response = result.jsonresponsedata;

        }

      }

  });


the message.toObject() is always null and the error below

"Error: Response closed without headers

    at Object.onEnd (http://localhost:4200/main.js:1257:21)

    at http://localhost:4200/vendor.js:62504:24946

    at Array.<anonymous> (http://localhost:4200/vendor.js:62504:5685)

    at e (http://localhost:4200/vendor.js:62504:1567)

    at http://localhost:4200/vendor.js:62504:1681

    at ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:412:35)

    at Object.onInvokeTask (http://localhost:4200/vendor.js:44161:33)

    at ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:411:40)

    at Zone.runTask (http://localhost:4200/polyfills.js:180:51)

    at invokeTask (http://localhost:4200/polyfills.js:493:38)"



i tried another approach. see code below.

const service = new AbcServiceClient('https://localhost:5001'null);

    const request = new DomainMessage();

    request.setMesssage('QueryTest');

 

    service.fields(requestnull, (errresponseAbcField=> {

        console.log(response.toObject());

        if (err) {

          console.log(err);

        }

    });




and this one give me CORS error. see error below.

Access to fetch at 'https://localhost:5001//AbcApi.AbcService/Fields' from origin 'http://localhost:4200' has been blocked by CORS policy:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.



Is it possible to run angular accessing grpc with out using docker?


thanks.

Stanley Cheung

unread,
May 29, 2020, 3:33:45 PM5/29/20
to XCompiler, grpc.io
On your first code snippet, what is "grpc.unary"?

On your second approach, are you using grpc-web? If so, you need to set up Envoy to handle the CORS request (and handle the grpc-web requests in general) like this.

In general grpc-web browser clients cannot directly talk to a grpc backend server. You need Envoy and grpc-web to do the translation. See https://github.com/grpc/grpc-web/tree/master/net/grpc/gateway/examples/helloworld for an example.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/0949924e-ee23-44e3-acc2-c52dab1065e6%40googlegroups.com.

XCompiler

unread,
Jun 1, 2020, 12:47:04 PM6/1/20
to grpc.io
Hi,

Yes i am using grpc-web.

Is there any other way to implement other than using Envoy?

thanks.


On Friday, May 29, 2020 at 2:33:45 PM UTC-5, Stanley Cheung wrote:
On your first code snippet, what is "grpc.unary"?

On your second approach, are you using grpc-web? If so, you need to set up Envoy to handle the CORS request (and handle the grpc-web requests in general) like this.

In general grpc-web browser clients cannot directly talk to a grpc backend server. You need Envoy and grpc-web to do the translation. See https://github.com/grpc/grpc-web/tree/master/net/grpc/gateway/examples/helloworld for an example.

To unsubscribe from this group and stop receiving emails from it, send an email to grp...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages