how to Create object of the proxy class of wcf? - wcf

i want detail procedure to Create object of the proxy class of a WCF service whose i have only URL and parameter along with method() name.i have only limited resource as i have service URL ,parameter and name of the method.

Related

WCF service how to create

I have been assigned a task to create a WCF service which able to insert or fetch record. I was provided with one DLL, with the help of that I have to create. I am unable to see any method name not it's content. I downloaded one application which decompiled the assembly. Now I am able to see content of it. There are 2 class, one class contain properties (which accesses through get and set method) another class contain method which add record and fetch record.
How to create WCF service from that? I have already created lot of WCF service before that. In that case I have created cs file that in that created class who have properties(get,set) given name to class as datacontract and member as datamember. In service one class which implement interface. In interface just declare method and in interface define that method where I do inert/serach code and consumer application creating instance of service class and calling that method. But how to do in this situation?
You should be able to create a WCF service that wraps the provided DLL.
Create the ServiceContract (interface) with the methods you want.
Create the service that implements the contract, and add a reference to the provided DLL. In the service implementation, you can then call the methods from the provided DLL that you need.
You can also create DataContracts as needed for returning the data (or passing data in).
Essentially, it's exactly the same as the previous WCF services you've created, except that the actual functionality is in a separate assembly (DLL) that you reference, rather than being in the service implementation itself.

WCF Data Service: How to return custom class object

Hi i want to return a custom class object from wcf data service.
my req is that i have a class A which contains some property along with a list property of other class B.
i want to return the object of class b.
plz help
If you have the data on the server as in-memory classes, you can use reflection provider to expose them as WCF Data Service: http://msdn.microsoft.com/en-us/library/dd723653.aspx

Making an interface visible across WCF web services

I would like to declare an interface in my Web Service layer and then have the caller create objects of this interface type via proxy and use them to call the service methods.
However, when I decorate the interface with DataContract attribute, I get an error saying this attribute can only be applied to class, struct and enum. I don't think that ServiceContract attribute makes sense, as the interface I am trying to expose is used only for data transfer purposes. I also noticed that when the interface was decorated with ServiceContract, it wasn't displayed in the proxy class created.
What is the best practice to go about this?
You cannot do that. "DataContract" interface cannot be exposed as part of metadata. Also even if you share the interface (in assembly) your clients will not be able to send their implementation back to your service because receiving side needs real type for deserialized instance.
The service contract is used on the interface, that is the name of the services. The data contract is used on the class, the data that you are sending over.
ServiceContract on the interface
OperationContract on the methods
DataContract on Class
DataMember on properties
See: http://msdn.microsoft.com/en-us/magazine/cc163647.aspx

WCF service method

I am creating a wcf service in .net. In the service I have added function named XYZ as:
public int XYZ(int a){
return a+a;
}
When i added the web reference of web service in my web application and accessed the function XYZ, here it requires two parameters one is of int type and second is of bool type.
But originally i had added single parameter in XYZ function in wcf service.
If someone has idea then please let me know that how to handle this. Because my wcf service will be called from flash code.
If you are adding a Web Reference to your project instead of Service Reference then you'll get "extra" parameters as described here. You should be adding a Service Reference to create a proxy for your service that matches the WCF ServiceContract description of your service. Also, the "extra" parameters only show up for ASMX-based clients. They won't be required for the Flash client to call the WCF Service.

How do I initialize a Service Object when Self-Hosting in WCF

I am hosting a service within a Windows Service.
The following snippet instantiates the ServiceHost object:
Host = new ServiceHost(typeof(Services.DocumentInfoService));
The DocumentInfoService class implements a contract interface that has methods that invoke business objects requiring initialization (actually a connection string). Ideally, I'd like the hosting process to get the connection string from the config file and pass it to a constructor for my service object, DocumentInfoService, which would hold onto it and use it to pass to business objects as needed.
However, the ServiceHost constructor takes a System.Type object -- so instances of DocumentInfoService are created via the default constructor. I did note that there is another constructor method for ServiceHost that takes an object instance -- but the docs indicate that is for use with singletons.
Is there a way for me to get to my object after it is constructed so that I can pass it some initialization data?
ServiceHost will create the service instances based on the binding and behaviors configured for the endpoint. There's no particular point in time, where you can rely there is a service instance. Hence, ServiceHost does not expose the service instances.
What you could do is add code to your service object constructor to read the relevant configuration values itself through the ConfigurationManager class.
Of course, if you don't keep your configuration in the app.config, that won't work for you. Alternative approach would be to have a well-known singleton object that the service instances access when created to get the necessary configuration.
And there's also the option of creating your own ServiceHost or your own ServiceHostFactory to control the service instantiation explicitly. This would give you acess to the new service instances at the moment of creation. I would stay away from that option though. It's not worth the effort for your scenario.
Implement your own ServiceHost. See also http://hyperthink.net/blog/servicehostfactory-vs-servicehostfactorybase/