Hi Im using silverlight ria services and trying to called a domain service method
the domain service class signature goes like this public class UserDomainService : DomainService
and I have a simple operation to return data
public IQueryable GetUsers()
{
return userService.GetAll()
).AsQueryable();
}
this compiles fine an a silverlight proxy is generated on the silverlight client side
how ever when makeing calls from silverlight eg
LoadOperation op = UserDomainContext.Load(UserDomainContext.GetUsers(),UserLoadedCallback,null);
int i = op.Entities.Count();
i is always 0, the domain servcice method is never hit when i put a breakpoint, please help!!!
You may not have enough detailed code to see the exact problem.
Have you put [EnableClientAccess()] on the service class?
The proxy must be generated because it must be compiling to run.
Hope it helps
Related
I have inherited a web service built to receive calls from a third party system, "System A". It was a POC that may not have any active functions calling it and I suspect it was only tested from SoapUI or the like and never from the application it was designed for.
When System A is configured to call it, the service is called but the payload, one complex-type parameter, is null.
I have two other web services written years ago that accept calls of the same type from the same function of System A. Pointing System A to either of these services results in the parameter being supplied. Contracts and WSDLs look very similar and the only variations I see (like differing namespaces) seem to vary between the two services that do work.
What would cause a web service to not receive the payload in the call?
Related, where should I look to find it? The parameter is getting dropped between System A calling and the web service code itself getting hit. I've checked the trace logs but see nothing that I recognize as useful.
namespace MyNamespace.StandardNoteReceiverService
{
public class StandardNoteReceiverService : IReceiveNoteService
{
public StandardNoteReceiverResponse ReceiveNote(ReceiveNoteData standardNoteReceiverRequest)
{
string x = standardNoteReceiverRequest == null ? "NULL" : "ok";
LoggingLib.Log($"Service called. Paramter status: {x}");
return NoteReceiverServiceLayer.ReceiveNote(standardNoteReceiverRequest);
}
}
}
which implements
namespace MyNamespace.StandardNoteReceiverService
{
[ServiceContract]
public interface IReceiveNoteService
{
[OperationContract]
StandardNoteReceiverResponse ReceiveNote(ReceiveNoteData standardNoteReceiverRequest);
}
}
It turned out to be the parameter naming. Once I changed the name of the parameter to be the same as the name used by the services that are working, it began receiving the data.
public class StandardNoteReceiverService : IReceiveNoteService
{
public StandardNoteReceiverResponse ReceiveNote(ReceiveNoteData NoteData)
{ ...
How did you build “System A”? Is it a WCF Web HTTP service or an ancient soap web service? How does the client call the service and send the parameter? I think it may be that the format of the parameters sent by the client is incorrect. In the Rest-style service created by WCF, using complex objects as parameters to pass data may not always receive the value of the parameter on the server because of the format of the parameter.
Get the object is null using JSON in WCF Service
While in the WCF SOAP web service, the invocation is completed with a client proxy, the parameters are strong-typed. If the server always gets null, it might be caused by other issues.
I suggest you create a minimal, producible example so that I can try to offer a workaround instead of offering speculation of this issue here.
Feel free to let me know if the problem still exists.
I'm going to be creating a service that needs to make a call to a hosted WCF service halfway around the world. This isn't that big of a deal since the number of transactions that will be made is relatively low. However, I need to pass in an instance of a class that will possibly be defined in the WCF to the necessary WCF function.
So my question is, will that instance of the class exist on my server? Or will I be contacting the host server every time I attempt to set a variable in the object?
EXAMPLE:`
public class Dog
{
public string noise;
public int numLegs;
}
public class doSomething
{
public string makeNoise(Dog x)
{
return x.noise;
}
}
`
All of those are defined in the WCF. So when I create an instance of class Dog locally, will that instance exist on my side or the server hosting the WCF service? If I'm setting 1000 instances of Dog, the latency will definitely build up. Whereas if I DON'T have to contact the server every time I make a change to my instance of Dog, then the only time I have to worry about latency is when I pass it into doSomething.makeNoise.
The host creates a new instance of the service class for each request, if you're using the default per-call instantiation method (which is the recommended way).
So either this is the IIS server which hosting your WCF service that creates an instance of your service class, or it is the ServiceHost instance that you've created inside your own self-hosting setup (a console app, a Windows service etc.).
The service class instance is used to handle your request - execute the appropriate method on the service class, send back any results - and then it's disposed again.
There's also the per-session mode in which case (assuming the binding you've chosen support sessions) your first call will create a service-class instance, and then your subsequent calls will go to the same, already created instance (until timeouts come into play etc.).
And there's also the singleton mode, where you have a single instance of the service class that handles all requests - this is however rather tricky to get right in terms of programming, and "challenged" in terms of scalability and performance
You will need to host your WCF service on a public available server (for example IIS). Successful hosting will provide you with a link for the svc file. Clicking on that will give you a link ending in singleWsdl. You need to copy that link. On your client side, the one that requires a reference to the WCF, you will need to Add Service Reference and pass that link. This will generate proxy code with Client objects that you can use to access your WCF ServiceOperation methods.
At a minimum you should have three projects. A website project to host the actual site. A WCF project to host your services. And finally a shared project, which should contain the classes you are concerned with (the models).
Both the website and wcf projects should reference the shared project, this way they both know how the models look.
The wcf project should return serialzed models as json objects, which I usually do by referencing Newtonsoft.Json.
Your website project should expect this json, and deserialize them, also using Newtonsoft.Json. This is why your class (model) should exist in the shared project, so you can use the same class on both sides of your service call.
I'm developing an .NET application (WinForms, .NET Framework 4.0) and i need to call a method from a web service.
The problem is that the client's web service is only accessible from inside its network. So at development time, i can't access it, so I can add it as a refference.
How should I proceed?
Should I create some kind of replica of that web service in my network?
Which would be the best option?
I'd get the WSDL and write a mock of it that i can call from my side.
I'd then make it return data that i was expecting and then later on have it return data that i wasn't expecting.
Then when you deploy it (should) be ok but you would need to run some integration tests.
The alternative it to tell them to open a port for you to use so that you can write the s/ware.
You could replicate the web service which returns dummy data.
I would wrap the call to the service in a separate abstraction layer, this would allow you to provide a different implementation if you wish during testing.
Eg. Something along the lines of..
public interface IXYZServiceInvoker
{
SomeData SomeServiceCall();
}
public class SomeServiceInvoker : IXYZServiceInvoker
{
public void SomeServiceCall()
{
//Calls a real service
}
}
public class FakeServiceInvoker : IXYZServiceInvoker
{
public SomeData SomeServiceCall()
{
//returns some dummy/test data
}
}
Im slowly delving into Silverlight and after a good while trying I am finally able to return my own Custom Object from my web to my silverlight client, use a Siverlight enabled WCF service.
Now, im a little at a loss between the differences of a Domain Service, and a WCF Service.
Ive worked through the tutorials where a Domain Service is tied to a data context then bound to siliverlight controls. Great :) However, where i hit a rock was trying to return anything bar IQuerryable; as String, my own simple type etc.
I found a few tutorials such as this showing to mark a function with the [ServiceContract] annotation and to have a [Key] within your simple class. This didnt work, [ServiceContract] was not resolvable, and i later found a guide saying to use [Invoke]. I then hit issues of not been able to load the function and get a result, i basically go to here
[Invoke]
public string HelloWorld(string name)
{
return string.Format("Hello {0}.", name);
}
var helloWorld = new HelloWorldDomainContext();
//helloWorld.HelloWorldCompleted += new EventHandler<InvokeEventArgs<string>>(HelloWorldHelloWorldCompleted);
//helloWorld.HelloWorld("Mark Monster");
Anyway, so I then discovered silverlight enabled WCF services, and am able to return my own custom objects and call this fine.
tl;dr - Are Domain Services only for use when binding to Silverlight controls? Ie its kind of a direct one way binding and is called as and when is needed, and i do all Linq related sorting / filtering / selecting on the server?
And lets say I want to return an xmlString, then i use a WCF service? Am i right to be using a mix of WCF services and Domain Services in my application?
Sorry if the above is a bit confusing! Just trying to get to grips with this all coming from ASP.NET / Flex
Thanks muchly.
This should clear things up:
WCF RIA Services: Returning a Simple POCO from RIA
Here is what I've found after searching:
http://42spikes.com/post/-Using-WCF-RIA-Services-with-your-POCO-Part-4-Returning-a-Simple-POCO-from-RIA
Scenario:
I am using Silverlight 3.0 as client for a web service.
Design:
The server has a class named DeviceInfoService which has the basic functionality of getting the list of devices, getting the properties of devices etc.
When I open an ASP.NET project and try to add a web reference, I can find an option to add a "Web Reference". After I add the web reference this way, I am able to access the DeviceInfoService class by creating it's object and then accessing it's methods.
Web Reference v/s Service Reference:
Coming to Silverlight: when I try to add a service reference, there is no option to add a web reference. Going with Service Reference, everything works fine till WSDL file is downloaded. People say that I can get this option by going back to .NET 2.0, but probably Silverlight won't work in .NET 2.0
The Problem
Now when I try to access the class DeviceInfoService , I am not able to find it. All I get is Interfaces -- DeviceInfoServiceSoap and DeviceInfoServiceSoapChannel. Classes named DeviceInfoServiceSoapClient.
The methods GetHostedDevices and GetDeviceInfo are no longer available. All I get is GetDeviceInfoRequest, GetDeviceInfoRequestBody, GetDeviceInfoResponse and GetDeviceInfoResponseBody.
I googled a lot how to use these four classes, only to find nothing. I want to get those 2 classes directly like in ASP.NET and not using those Request Response type.
You sound awfully confuse about some concepts.
How about you watch the following Silverlight.Net video and see if that helps?
How to Consume WCF and ASP.NET Web Services in Silverlight
What is web reference in ASP.NET is equivalent to service reference in Silverlight.
Here's an example of how to use a web service in Silverlight, e.g. the CDYNE Profanity Filter.
Add a new Service Reference to your project, URL is: http://ws.cdyne.com/ProfanityWS/Profanity.asmx?wsdl, leave the name as ServiceReference1.
Use this code behind to call the service (which was implemented to be asynchronous):
public MainPage()
{
InitializeComponent();
string badText = "I wonder if the filter will filter this out: shit bad luck";
ServiceReference1.ProfanitySoapClient client = new ServiceReference1.ProfanitySoapClient();
client.ProfanityFilterCompleted += new EventHandler<ServiceReference1.ProfanityFilterCompletedEventArgs>(client_ProfanityFilterCompleted);
client.ProfanityFilterAsync(badText, 0, false);
}
void client_ProfanityFilterCompleted(object sender, ServiceReference1.ProfanityFilterCompletedEventArgs e)
{
string cleanText = e.Result.CleanText; // Web service callback is here
}
And you've got a web service up and running in Silverlight!