Someone else created a WSDL service for me in Java. There is so far only one simple method to call. We tested this method in a C# console app by adding a service reference with the service's url. If I make a call to the generated method that has 'Async' at the end, I get an error. However, since the synchronous method is available, making calls to that work perfectly.
The trouble is, when I add a service reference to the same service from within a Silverlight project, the synchronous method is not available. A call to the async method also errors out.
Is there a different way I can do this so I can call the synchronous method from Silverlight?
Related
In an Angular service (provider.service) that uses $http, is there a way to periodically turn on and off what certain calls using $http will return?
Here's my scenario: we are using $http to consume web services built by another development team. When those services are not yet ready (or break) we don't want development efforts to halt on our end. We simply need to temporarily turn off that specific call and have it return mocked data.
I've seen $httpBackend being used to mock out HTTP calls, but I'm not sure that will work for me, and if it would, I'm not sure how this would look or be configured.
If you are making your $http calls from a data service, you can set toggles in your service. Don't even make the http call if you know it will fail. Alternatively you could probably even make a whole mock data service to use at dev time, and replace it with the actual service when your backend is ready, avoiding issues of dev code being there in production. This is one of the reasons people say you should never reference $http in controllers.
See the AngularJS Style Guide - Data Services for a better explanation than I could ever write.
I need to calculate distances for some logic within a web service and assume google.maps API is appropriate. Everything I've seen is Jscript and requires a reference to the script in html tags <script>, which does not apply here. A .dll would make things obvious to me, but that does not seem to be available...
How do you access google.maps within a c# .asmx??
You will have to do the same thing that would be done by the JavaScript code you're seeing as examples. You'll want to use the WebClient class or maybe the WebRequest class to do the network I/O, but you've got to send and receive HTTP messages.
"Add Service Reference" won't work, of course.
Note that this problem is not specific to ASMX web services. You would have the exact same issue in a console program or Winforms application.
I am using WCF DataService I have a method:
[OperationContract]
public List<string> GetAges()
{
return _registrationData.GetAges();
}
on my client side, I instantiate it this way:
_registrationDataServices = new RegistrationDataServiceClient();
it now exposes a delegate
_registrationDataServices.GetAgesCompleted += GetAgesCompleted;
and a function call:
_registrationDataServices.GetAgesAsync()
the problem with this is that the call to the service will be asynchronous and the results comes in the delegate function, I want to be able to call the service and wait (block) until the results come back, how can this be done using WCF ?
I have to use a wcf, because I have a silverlight application that needs data from a database, the WCF is being called from a .NET assembly as my data access layer.
It is a very bad practice to call web service from a Silverlight/WPF application synchronously. The sync call would hang your UI until the web service call has ended, which will cause bad user experience.
However, if you're still up for it, here is a very helpful link.
Don't call it synchronously -- you will block the UI thread. Users usually think their software has crashed if the UI is frozen.
Ideally you would make a modal busy indicator that animates and shows 'progress' while you wait for the call to come back, and it goes away when you receive the Completed event.
Even if you were still convinced that blocking the UI thread was OK in your case, you can't actually call it synchronously! It was designed this way for a reason - go with the flow.
I have WPF application that needs to access WCF service at start ( login window ). Each time application runs on Windows 7 it freezes on login until gets a responce from WCF. Is there any way to design this process differently?
It sounds like you need to make your calls asynchronously. Either start the call on a new thread (preferably using a Task), or call the WCF service using an asynchronous design pattern.
Put the WCF call in a background thread
There are two causes for something perceived as "freezing" when carrying out WCF Service Calls:
Calling the service in a synchronous fashion will block your UI thread until the call has completed. This bad and the reason why Silverlight forbids synchronous calls and forces you to follow the Begin/End Async pattern for any kind of RPC - be it WebRequest or WCF Layer. By default the async methods are not generated when adding a service reference to your WPF project but you can turn it on using Configure Service Reference.
The second cause is less obvious. The initial service client instantiation can take almost 3 seconds - even on fast machines. That's why you are well advised to QueueWorkUserItem the proxy instantiation and the BeginXXX call even when using the async pattern.
If you need the response from this service call to start the application, you can use a background thread to call this service and handle the return value. While this thread is consuming the service you can display your window or a splash screen.
If you don't need the retrun value from this service method you can use [OperationContract(IsOneWay=true)] on your service. So that you don't need to worry about threading and stuff.
You're calling a WCF call on the main thread, Therefore it will appear to crash.
You can either, put it in a thread and call it at the start of your app.
Put it in a background process ( if you're in visual studio you can drag this off the tool bar)
You can do threads quite easily by defining a Thread, then defining a threadstart, passing in your login WCF call, and the call thread.start(); and pass in your threadstart you defined.
A background worker is pretty similar, you can put your code in the backgroundWorker1_DoWork() method
Or make your WCF call Async, so it will send off the login response, and your login code will call on the "OnTaskCompleted" method( you could also put it on a new thread as well, but don't really have to)
Try this thread for Async WCF calls
How to make a call to my WCF service asynchronous?
I'm not sure if I'm on the right lines but this is what I'm trying to do, I have a Silverlight application and a WCF service, the Silverlight app "subscribes" to the WCF service using PollingDuplex and the service can send data to any connected clients which works.
The service is marked with [ServiceContract(CallbackContract = typeof(IServiceCallback))] and it is single instanced
The problem is there is another service which should be able to call a standard method on this service to pass it data that will get distributed to the connected Silverlight clients, but because of the above settings it requires it to use callbacks (I can't change the other service).
Is there a way to have both types of operations, callback and standard in the same service if that makes sense?
Thanks for your time
Yes. It is possible. I guess CallbackContract parameter will not stop you from using your service as a regular request/response service (though I have not tried it).
But for the same contract, you may have to define two end points with different bindings, one with PollingDuplexHttpBinding and another one with basicHttpBinding (with silverlight this is the only other option).
You have to make sure that you are calling the right operation from the clients using duplex and basic http bindings.