I am in the process of developing a WCF Service(WCFManager) which would send out request to other services and get response back. For this I developed a WCF service.
Trying to accomplish the following (Assuming that my service name is WCFManager)
What I did so far
Added a service reference of Service X to WCFManager which created a reference.cs and a WCF Client.
Using the WCF Client generated by adding service reference and sending the request to Service X by using the following code
WCFManagerClient client = new WCFManagerClient();
Response response = client.GetResponse(request);
What am I trying to accomplish
I want to add few config settings in a App.Config file of Service X, Service Y, Service Z which I did.
Reuse the same WCFManagerClient to send the request to Service Y or Service Z by reading the endpoint information from the config file. My assumption is that when I use the WCFManagerClient to send the request it uses the reference.cs created in the service reference of the WCFManager service.If my assumption is true can I change the reference.cs on the fly to include the Service Y binding information when I send the request to Service Y and same with the Service Z. This way I don't have to create a proxy for each Service.
Is it possible to reuse the same reference.cs file generated but include the binding information on the fly from config file.
3.I have no control over the Service Y or Service Z but all I know is services Endpoint information and the method names and the schema of each service would be the same.
I am not sure if this is possible in WCF if some one has gone through such design with WCF but any suggestions about my approach is apreciated.
Related
I need to consume a service endpoint which is WSDL.
I tried adding it as a webreference and service reference. In both occasions I couldn't find an effective method to fetch data.
Below is the service consumed in SoapUI -
When you added ServiceReference, it would have created a Client\Proxy Class as well. This client in actual serializes the data into soap format, sends it over the network and then deserializes the soap response into memory response objects which you can consume
when you do a "Add Service Reference", on the dialog that comes up, click on the [Advanced] button in the button left corner and on the next dialog that comes up, pick the [Add Web Reference] button at the bottom.
Notice that there is a namespace, have you included that namespace in the class that is calling the web service
That namespace should contain a client class that will allow you to invoke the web service
I could consume this service by creating the client object and calling the method from client.
I have added a Service Reference that points to WSDL of the service. I can consume the service by creating a proxy and theres no issue with that. My problem is that I need to send a specific soap message , and theres some parameters that need to be include into the header and the body of the soap message (credentials and IDs).
How I can manually edit or add this soap message? without touching the app.config file?, there's a way to add the same parameters inside the code? such as:
soap:Header
soap:Body
Hi I have a WCF service and within it I have this method
void SendData(int pumpNo, List<String> pumpInfo);
however when I try to pass an int and a list into it, I get an error saying
Error 1 No overload for method 'SendData' takes 2 arguments
This is how I passed data to it in the WCF client
sendpumpdata.SendData(pumpID, pumpData);
ok so at the top I create an instance of the WCF service by doing...
ServiceReference1.iCommClient sendpumpdata = new Pumps.ServiceReference1.iCommClient();
also in my service.cs I have created the method defined in the IService.cs
A WCF web service leverages client generated code (i.e. a proxy) to communicate with the server. In your situation, even though the server code has two parameters, your client generated code must be out of date.
If you're using a Web Reference or a Service Reference just right click and Update Reference. If you're using a static WSDL then navigate to the WSDL hosted locally for the WCF service and save it to disk and then overwrite the one in your project.
I am trying to add a SOAP web service in the VS.NET 2010 interface, but I get that the server refused the connection. The people in charge of the service tell me it is working. I asked if they had a wsdl file, but supposedly they have none.
Is the problem caused by their lack of wsdl, or can I assume there is a problem on my side?
If they are not willing to expose their service metadata on the service then see if they will give you access to the assemblies containing the service contract, operations, and data contracts. Then you can create a proxy to the service without needing any metadata.
// Create service proxy on the fly
var factory = new ChannelFactory<IMyServiceContract>("NameOfMyClientEndpointInConfigFile");
var proxy = factory.CreateChannel();
// Create data contract
var requestDataContract = new MyDataContract();
// Call service operation.
var responseDataContract = proxy.MyServiceOperation(requestDataContract);
It also helps if you have access to the service-side config file so you can copy the endpoint details out of there into your client config.
It looks like their service is not exposing metadata. Try and browse to the wsdl url and see if you get back anything. http://server/blah/blah?wsdl
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.