I am developing Application for Windows Phone using .Net Compact Framework 3.5
I am trying to connect Web Services from this application.
It is not connecting it in First Attempt, but it is connecting successfully in second and further attempts.
In First Attempt, It is giving "Web Exception" Error.
I am using following code for connecting:
SalesService.SalesService obj = new SalesService.SalesService();
string s = obj.CheckForValidService();
It is giving error in CheckForValidService method from Reference.cs file.
Ah, the old Expect-100 header issue. You will need to surpress the use of that header.
System.Net.ServicePointManager.Expect100Continue = false;
MSDN details:
http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.expect100continue(v=vs.90).aspx
Stackoverflow details:
The request failed with HTTP status 417: Expectation Failed - Using Web Services
Related
I'm trying to connect to a remote Dynamics CRM instance and getting this exception on the ServiceClient constructor:
Failed to connect to Dataverse
Inner Exception 1: One or more errors occurred.
Inner exception 2: Need a non-empty authority
Parameter name: Authority
Key here is that it works fine from my dev machine--the error only occurs when I move the code to another server.
Here's the code:
string crmConnectionString =
$"AuthType=OAuth;Username=user#contoso.com;Password=whatever;Url=my-app.crm.dynamics.com;LoginPrompt=Never";
using (ServiceClient service = new ServiceClient(crmConnectionString)) // throws here
I used Wireshark to sniff the data and noticed the working server is sending the client hello using TLS v1.2, whereas the failing server is sending a slightly shorter (fewer bytes) hello using TLS v1. Could the issue be related to this and, if so, how do I fix it?
I have confirmed that TLS 1.2 is indeed required when communicating with online Dynamics 365. The solution in my case was to add this line directly above the constructor:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
This forces the protocol to TLS 1.2 and allows the code to work on both servers.
Note that there are probably better ways to solve this, such as upgrading your OS to get the newer TLS. That way your code won't be stuck on TLS 1.2 when newer versions become available. But the code addition is a potentially quick way forward for those who need it.
More info here and here.
I am attempting to transition away from WCF to move our codebase across to .NET Core. Our services are all hosted as Windows services at present so am trying to self-host the gRPC service as well (rather than building AspNetCore applications). I have successfully built a server using Grpc.Core.Server, and the client side as well with Grpc.Net.Client.GrpcChannel, see the code snippets below for reference.
Server:
var builder = ServerServiceDefinition.CreateBuilder();
// Binder is a small class ripped from the CodeFirst example
var binder = new Binder();
binder.Bind(builder, serviceType, service: serv);
var serverServiceDefinition = builder.Build();
var server = new Grpc.Core.Server
{
Services = { serverServiceDefinition },
Ports = { new ServerPort(host, port, ServerCredentials.Insecure) }
};
server.Start();
Client:
var channel = GrpcChannel.ForAddress(Uri, new GrpcChannelOptions()
{
//HttpHandler = new GrpcWebHandler(new System.Net.Http.HttpClientHandler())
});
var service = channel.CreateGrpcService<TService>();
However because our applications are still running in .Net Framework 4.8 I get the runtime exception when testing out this code:
System.PlatformNotSupportedException : gRPC requires extra configuration on .NET implementations that don't support gRPC over HTTP/2. An HTTP provider must be specified using GrpcChannelOptions.HttpHandler.The configured HTTP provider must either support HTTP/2 or be configured to use gRPC-Web. See https://aka.ms/aspnet/grpc/netstandard for details.
That leads me to add in the Grpc.Net.Client.Web.GrpcWebHandler on the client side to switch over to Grpc-web as per the link in the error.
However, I am now struggling to do the equivalent for the server to support Grpc-web. The guide here suggests to either (1) use Grpc.AspNetCore.Web or (2) use "Envoy proxy" to get the server supporting it. The problem with (1) is that I'm not using AspNetCore so I don't think this solution is appropriate, and I can't find any lightweight/easy way to do (2) in a simple C# solution.
Without the server-side support added, I get this exception:
Grpc.Core.RpcException : Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: An error occurred while sending the request. WebException: The server committed a protocol violation. Section=ResponseStatusLine", DebugException="System.Net.Http.HttpRequestException: An error occurred while sending the request.
Which I assume is obviously related to the fact the server isn't supporting the Grpc-web requests. So I am at a bit of a dead end with regards to this now. I feel I need to work out how to self-host AspNetCore servers and move to that instead of Grpc.Core.Server, which will open up option (1), but I am finding little to no evidence that is actually possible.
So I guess my main question is: Is there any way to support Grpc-web clients in a server hosted via Grpc.Core.Server?
And if the answer is no --> How can I self-host a GRPC server that will support Grpc-web clients?
As per this getting started guide I have discovered protobuf-net.Grpc.Native which appears to solve the problem I have at the moment. I also discovered I was missing a default constructor for my [DataContract], which I think was unrelated to the errors I was receiving but may have been contributing.
I'm creating a shopify app using ASP.NET MVC, I made some code changes.
When I tried to run the application, I got the following error message
Error: The remote server returned an error: (502) Bad Gateway.
I always make backups for my application, because I got the error message, I decided to replace it with my backup file. But the same error still occurs.
I am a beginner both in the shopify app as well as C#. Can anyone explain why this happened and how to solve it?
You are trying to access an invalid connectionString shopUrl. Check this
İt is a proxy problem. Change current proxy to default proxy :
httpRequest.Proxy = GlobalProxySelection.GetEmptyWebProxy();
I am trying to make a call from my WPF project to an API that I created in ASP.NET Core. When the call is made to the Web API end point, it is returning an error: Unable to connect to the remote server with the inner error being SocketException: No connection could be made because the target machine actively refused it.
This is all being done on the localhost.
The code that is creating this call is(the second line throws the exception):
string RequestUri = "api/Class/GetEverythingDue";
HttpResponseMessage response = await myClient.GetAsync(RequestUri);
With myClient being an HttpClient that I configured like so:
this.myClient = new HttpClient();
myClient.BaseAddress = new Uri("http://localhost:56030/");
myClient.DefaultRequestHeaders.Accept.Clear();
myClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
I realize there are several questions with similar problems, I just haven't seen any yet that have to do with .NET Core. I just wanted to make sure that the problem wasn't due to using WPF and .NET Core together and it was due to them being incompatible.
Any help is appreciated.
Thanks
The exception usually means either the firewall is stopping you or the remote server is not listening to the port. An error with your code wouldn't throw such an exception unless you closed the connection and then tried to access it.
I want to get notifications when a new feed has landed on a designated page (by page id). After what I understand, the Realtime-update og Graph API should be able to do this trick according to https://developers.facebook.com/docs/graph-api/real-time-updates/v2.4.
So I want to add a new subscription, which I try to do with the following code:
dynamic result = client.Post(urlPath, new
{
#object = "page",
callback_url = callbackUrl,
fields = "feed",
verify_token = "654321",
access_token = accessToken
});
return result;
But when I try to run this, I'm getting the following error code:
(OAuthException - #2200) (#2200) callback verification failed: Received HTTP code 502 from proxy after CONNECT"
What do I miss?
The callback url is https://127.0.0.1:8989/ and I have a TcpListener running on the port, which does not seem to get any response/request incoming...
The application is a C# console application, so no fancy asp.net stuff or something. I'm using the Facebook .net SDK.
Should I FacebookClient.VerifyPostSubscription() or anything else that I missed out?? Maybe the SDK wraps a handle?
So the answer I'm looking for is:
- How do I create/add a subscription for feeds of a facebook page, using the .net SDK on a windows console project??
UPDATE:
I changed the loopback with a domain name, that I the NAT to my target machine, and now I actually get some encrypted data on my TcpListener!
So, the question now is, how do I respond correctly to this received respons, only by using a Tcp Client??
How you have to respond is exactly outlined in the docs you linked:
https://developers.facebook.com/docs/graph-api/real-time-updates/v2.4#setupget
It's not really clear what you mean with "TCP listener". You need to have some logic why can send HTTP responses to the Facebook servers, otherwise your service will be disregarded after some time, meaning no updates will be send.
Typically, this is implemented as a script/application in a web/application server.
Please note: The "C# SDK" is a third-party SDK and not officially supported by FB.