Constructor for QMSClient Object throwing exception (C#.net) (QMS API) - c#

I'm trying to create a QMSClient object using the constructor that accepts [string endpointConfigurationname, string remoteAddress]. When executing the code the following exception is thrown
An unhandled exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll
Additional information: Could not find endpoint element with name 'BasicHttpBinding_IQMS' and contract 'QMSAPIService.IQMS' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.
I have successfully connected to the server I entered in the remoteAddress parameter using the default constructor for the QMSClient, but for some reason when I use this constructor it throws the exception. I followed the instructions in the QMSAPI Documentation under the service key injection example. The reason I wish to use this constructor is so I can have a parameterized server address as I will need to change between the target QlikView server on different executions of my program.
As I said I have connected successfully with the default constructor, meaning my service reference and config file have been configured properly. Here is a snippet of my code:
IQMS apiClient = new QMSClient("BasicHttpBinding_IQMS", "http://qlikviewdev:4799/QMS/Service");
ServiceKeyClientMessageInspector.ServiceKey = apiClient.GetTimeLimitedServiceKey();
Any help is greatly appreciated.
EDIT: I have now successfully connected to the original server using the constructor mentioned, my new problem is that when trying to connect to a different server, an exception is thrown on the next line when attempting to generate a service key for the QMSClient object.
ServiceKeyClientMessageInspector.ServiceKey = apiClient.GetTimeLimitedServiceKey();
The exception is as follows
An unhandled exception of type 'System.ServiceModel.ActionNotSupportedException' occurred in mscorlib.dll
Additional information: The message with Action 'http://ws.qliktech.com/QMS/12/IQMS/GetTimeLimitedServiceKey' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).
I am following the QMSAPI Documentation instructions and am not seeing any directions to update the config file or ServiceSupport files when attempting to connect to a different server. I hope to make advances on this soon.

Related

MongoDB C# unable to connect to database: Unable to create an authenticator

While setting up my new environment with a freshly deployed MongoDB container with authentication enabled, I ran into this exception: "An unhandled exception has occurred while executing the request. MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. ---> System.NotSupportedException: Unable to create an authenticator."
In my case I'm using a connection string like this example: mongodb://USER:PASSWORD#HOST:27017/?authMechanism=DEFAULT. This string works perfectly fine in MongoDB Compass but not inside my .NET 6.0 application.
If you take a look at the source code of C# MongoDB driver in MongoCredential.cs#L469, you see this exception gets thrown while checking the auth mechanism.
After specifying the exact auth mechanism in the connection string, all exceptions are gone!
example: mongodb://USER:PASSWORD#HOST:27017/?authMechanism=SCRAM-SHA-256
Hope anyone else googeling around will find my answer helpful!
happy coding.
For me this just changed the exception to unable to authenticate using sasl protocol mechanism scram-sha-256
After some trial and error I got it working by changing the connection string to:
mongodb://USER:PASSWORD#HOST:27017/?authSource=admin
I have no idea why this was needed as the default and SCRAM-SHA-256 connectionstrings works fine in other contexts...
Remove the authMechanism=DEFAULT parameter from the connection string

WPF deserialize issue, communication exception

There is an asp.net based backend, where I use wcf services to communicate with client, which is a WPF application. When the data comes back from server, and during deserialization, it throws a communication exception. Here is the exception:
Exception thrown: 'System.ServiceModel.CommunicationException' in mscorlib.dll
Additional information: Error in deserializing body of reply message for operation 'AutoImportGetProtokolls'. The input source is not correctly formatted.
Source: http://pastebin.com/ZtUxYNUm
Here is a photo about the exception: https://www.dropbox.com/s/5araq9oajhrhrty/communicationexception.png?dl=0
I have another application based on silverlight, and when I call the same service, the exception does not come. After I start the WPF application the exception comes every time for first service call, after that it comes "randomly" (I could not find any logic when)
What I have tried so far but did not help:
-I used a DTO (data transfare object) class instead of generated one by entity framework. (sp_AutoImport_GetProtokolls_Result)
-Deleted the "out ErrorCustomModel res" parameter from service.
-Many source in google said that I should take a look for webconfing, and increase the property value of readerquotas. Here is the relevant part of webconfig: pastebin.com/e4ZpQsMK
Thank you guys, every hint are welcome.
Best Regards,
Norbert

Error in Calling some service in WCF Client

When I call this service method:
StaffServiceClient _Service = new StaffServiceClient();
Table_StaffInfo item = _Service.GetStaffById(10);
I get an error:
An error occurred while receiving the HTTP response to http://localhost:8008/StaffService. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
but when i call another service method:
StaffServiceClient _Service = new StaffServiceClient();
List<spStaffList_Result> list = _Service.GetStaffList().ToList();
the program works.
Your method GetStaffById failed internally. Maybe it has problems with receiving data (unlikely if just an int) maybe it has problems sending data (does your type Table_StaffInfo feature DataContract / DataMember attributes?) or it simply threw an exception.
You will need to debug your service. Put a breakpoint in the method and see where it takes you.
For starters, ignore the int parameter and just put a return null; in the method. If that works, it has nothing to do with your connection or server setup and you need to debug your code.

Unable to add a Service Reference to a WCF service that is hosted locally

I have successfully created my service, I have modified it ever so slightly so that it does a little more than the bog standard "Hello World".
The service compiles and runs and give me the following address to add into my client application:
127.0.0.1:81/Appointments.svc
When I follow the next tutorial in the series: https://azure.microsoft.com/en-us/documentation/articles/cloud-services-configure-ssl-certificate/
During step 5, when I add the reference to the service, it gives me the following error message:
An error (Details below) occurred while attempting to find services at '127.0.0.1:81/Appointments.svc'
Metadata contains a reference that cannot be resolved: '127.0.0.1:81/Appointments.svc?wsdl'.
The WSDL document contains links that could not be resolved.
There was an error downloading '127.0.0.1:81/Appointments.svc?xsd=xsd0'.
The underlying connection was closed: The connection was closed unexpectedly.
Metadata contains a reference that cannot be resolved: '127.0.0.1:81/Appointments.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service 127.0.0.1:81/Appointments.svc. The client and service bindings may be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
If the service is defined in the current solution, try building the solution and adding the service reference again.
I guess it might be some permission issues. Can you try to grant permissions on C:\Windows\Temp and see if that resolves your problem. The account that is associated with your apppool under which the service is running needs to have permissions on this folder.

WCF REST Client Exception

I have the following WCF client code:
string add = String.Format("http://localhost:{0}/ServiceRequestRest",accessPort);
var cf = new ChannelFactory<IServiceRequestRest>(new WebHttpBinding(), add);
cf.Endpoint.Behaviors.Add(new WebHttpBehavior());
busService = cf.CreateChannel();
busService.DoMyStuff("hello",null);
When I have "first chance exception break" activated, that last line of code throws a series of exceptions. The first exception is this:
System.InvalidOperationException occurred
Message="Envelope Version 'EnvelopeNone (http://schemas.microsoft.com/ws/2005/05/envelope/none)' does not support adding Message Headers."
Source="System.ServiceModel"
StackTrace:
at System.ServiceModel.Channels.MessageHeaders.ValidateHeaderKind(HeaderKind headerKind)
I am not aware that I am trying to "add Message Headers", but I choose to continue execution and immediately get the next exception:
System.Net.WebException occurred
Message="The underlying connection was closed: The connection was closed unexpectedly."
Source="System"
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
With all that said, I'm having difficulty understanding what the problem is. Any clues?
Update: The return type of my REST call could not be serialized, as I learned from another site. That alone could cause this problem, but after I fixed it I still had the same problem. When I use a regular catch block for the exception, all I get is "the connection was closed unexpectedly." What else could I be missing?
Update2: I think I found the final problem. I was getting interference from Skype. The code is working now. :)
The main problem that I see is that you are trying to use a WCF Channel to communicate using WebHttpBinding.
IMHO the entire purpose of WebHttpBinding was so that the client did not have to use the WCF stack to communicate with it. You simply use any HTTP stack to make the requests.

Categories