DataContract create in WCF - c#

At client side, I have this class without [DataContract]:
public class UserEntity
{
public string login;
public string password;
}
when I put [DataContract] and refresh the reference of this class at WCF side, then I can't initiate the web service. It says an error:
cannot create metadata...
What's wrong?

Are you sure that you actually know, why you can't refresh the reference? I mean you add [DataMember] - and it fails, you remove it - it works? Or it works several days ago and now you add [DataMember] (and many other stuff) and it not works now?
But anyway, the easiest way to solve "refresh reference" issues - to refresh reference manually with SvcUtil.exe. In this case error message would be much more descriptive the simple "oops! error!".

What is client and server side in your case? What is refreshing reference on the WCF side? Your description is very uncommon. Here is description how to create service with complex data type and WCF Class library:
Create WCF class library
Add data contract to the class library
Add service to class library
Implement service contract and service in the class library
Add host project
Reference WCF class library from host project
Host service from class library in host project
Add Metadata endpoint to your hosted service
Create client project
Run the host project outside the visual studio
Use Add service reference to create proxy on WCF service hosted in your host project
Implment code to call your service through created proxy
As you see there is no modification of data contract on the client side and no refreshing WCF service.

Related

add wss security header via proxy class

I consuming web service by proxy class generated from wsdl file. Main class is inherits from SoapHttpClientProtocol. In description of this web service I have an annotation
"Service invocation context. Implemented in the form ws-security
custom token"
I belive is it means that I need add wss security header and actually, I don't know how to go about it. Can I find aleary method or properties inherited from SoapHttpClientProtocol class to do it? Maybe I should consume this web service without the proxy class?

Where is the instance of a WCF object stored?

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.

Exposing WCF class reference method client side

I have a WCF Service. I add reference of a DLL in the WCF service.Now ddl has a class, i'm able to get access of the class at WCF client side by using the serviceknowntypeattribute but not the functions inside the class.Any solution?
I'm guessing that You are using autogenerated code (by Add Service Reference in Visual Studio).
This creates a stub for your class (only a container) but it is not actually your class.
To use your actual class in client code you must reference it in client project and in service reference advanced options make sure you have 'use types from referenced assemblies' checked.

Can't add service reference

I have started learning WCF. I wrote a simple service to query a SQL relation through LINQ.
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = aspNetCompatibilityRequirementsMode.Allowed)]
public class Order_WCFService
{
[OperationContract]
public List<Order> getOrders()
{
List<Order> orderList= null;
try
{
orderList= DAL.GetList<Order>();
return orderList;
}
catch (Exception)
{
throw;
}
}
}
This is located in ASP.NET-MVC project.
I have a simple silverlight application. It's in the same solution, but in a different project.
I would like to consume my service by a silverlight application.
I attempt to "Add Service Reference..." and in the left hand column I have a list of all available ASMX and WCF services. When I click on any of the services, it attempts to download service information, but fails after 10-20 seconds: "An error occured (details) while attempting to find services at..."
What am I doing wrong here?
Thank you
I'm 100% certain that services are functional because I can invoke them through AJAX.
Maybe a stupid question but was the service running when you attempted to add the service reference (if you are using the Visual Studio's built-in web server, was it started and the ASP.NET MVC project containing the service running)? Also you may try giving the full address of the WSDL in the Add Service Reference dialog instead of selecting it from a list after verifying that this WSDL is accessible in your browser.

What is the Proxy Class

Is a web service reference the proxy class itself? Or is it the classes created inside that you see in object explorer when you look at your web service reference?
example, I created this web service reference
http://www.elbalazo.net/post/TestWebProject%5FObjectExplorer%5FWebReference.jpg
I assume ServiceAuthResponse is one proxy class inside my web service reference?
When you add the WebService reference a proxy class is generated for you.
In your example it looks like LitleWebService will be your service proxy, ServiceAuthResponse sounds more like a data contract that will be used by the service. If you read about the Proxy Design Pattern it may be of some interest
Normally you proxy will inherit from ClientBase, this is where you can specify the service contract.
public class MyProxy : ClientBase<IServiceContract>, IServiceContract

Categories

Resources