Domain Service vs WCF Service? - c#

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

Related

I am trying to consume a PHP SOAP service from C# and create a class wrapper in VS 2010

I've been tasked with creating a class wrapper for a SOAP service, the idea is that you'll be able to treat it as a regular class. The main reason for this is that the WDSL for the SOAP service contains only one method and it's got 5 parameters and it's only kind of OO so you'd have to know all the method calls really well and it's a bit hard to remember them all.
OK, so I've tried adding a web reference, now web references can now be added as service references in VS 2010. You click add service reference advanced etc and it puts in a service reference. Great. Unfortunately if I try and access this from a class I can't.
I can build a console app and put code in the main procedure and access the method of the SOAP service fine but when I add a reference to a class library the intellisense won't allow me to select anything. I'd instantiate an instance like so:
SOAPService.webServiceService ws = new SOAPService.webserviceService();
ws.
and then the intellisense refuses to kick in. If I do the same in a web project or a console app then I can access it fine. I've added the namespace I've done all kinds of things. Also, I can add a web reference and get a DISCO file whenever I create a web project.
OK, also while I'm on the subject I also need to pass credentials to the web service in PHP.
The problem is that in the past I'd create some .net system credentials and add these and it would usually pass through if I was connecting to another .net service.
How should I be sending them to a PHP web service? I always get either invalid username/password combo errors or envelope malformatted error types
Thanks
Mr. B
So the intellisense is not working, but if you add the method in and try to use it does it work, or produce an error?
With regard to diagnosing authentication issues try using fiddler to view the SOAP messages that are being sent, and to view the reply. Do you have some other software that connects and authenticates to that service? Use fiddler to look at the SOAP messages and compare them to see if the header is different etc.
I'd normally do it like this,
using (Service service = new Service())
{
service.ClientCredentials.Windows.ClientCredential.Domain = "domain";
service.ClientCredentials.Windows.ClientCredential.Password = "password";
service.ClientCredentials.Windows.ClientCredential.UserName = "username";
}
Also with regard to the service working or not in general use fiddler if you have any problems, you can see the SOAP messages and it often gives you a clearer message.
I know in IIS you can turn on failed request handling that also gives you an insight from what is going on at the server end, perhaps you have some form of logging too for your php service?

Passing a Complex Type as a Parameter to an ASMX Service

I am trying to write a simple ASMX web service in C#. For the life of me, I can't understand or find out how to accept more complex parameters than primitives.
Is it possible to do something like:
[WebMethod]
public string MyMethod(SomeStruct parameter)
{
}
For anyone else having the same question. The answer was to use Soap.
As to why use ASMX service instead of WCF, there are a couple reasons:
Easier to configure and deploy for a small web service
Other developers are using and expect ASMX services
While the first reason is arguable, there really is nothing that can be done in the short term about the second reason, especially in the context of working with developers outside your own company.
try this :
[WebMethod]
public string MyMethod( )
{
var parameter = new JavaScriptSerializer().Deserialize<SomeStruct>(HttpContext.Current.Request["parameter"]);
}

Silverlight ria domain service not being called

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

How to return Domain objects from a WebService to my SilverLight Application

Im my DDD Aplication
I have a lot of Domain Objects like date:
class User()
{
public String Name{get;set;}
}
The persistence of then already done!
Now im going to Client Side (SilverLight).
My problem is: how i work with a User object on Client Side.
Example:
// only a example
User user = Service.Login("crazyjoe","1234");
The User object do not exist on Client Side.
Question:
Have a clean and fast way to pass my User object to SilverLight??
Obs: clean = dont put anything on my User class.
-
This website should give you the information you need:
Silverlight 2 - Webservices Part II - User defined type
I would use WCF to push the data to the silverlight client.
This isn't a problem. The User object you use on the client side will not be the same as the one on the server, but it will have all the same properties, of the same or similar types. It will be a proxy class. Note that it will be in a different namespace. If your Service Reference is named "UserService", then it will be in that namespace.

Using Webservice classes in Silverlight when adding service reference instead of web reference

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!

Categories

Resources