i am new in wcf. Dynamic Endpoint is a standard endpoint which performs discovery and automatically selects a matching service that i know. here is a code sample for DynamicEndpoint.
DynamicEndpoint dynamicEndpoint = new DynamicEndpoint(ContractDescription.GetContract(typeof(ICalculatorService)), new WSHttpBinding());
CalculatorServiceClient client = new CalculatorServiceClient(dynamicEndpoint);
Console.WriteLine("Invoking CalculatorService");
Console.WriteLine();
double value1 = 100.00D;
double value2 = 15.99D;
double result = client.Add(value1, value2);
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
i do not understand from the code that it is assumed that we added service reference and then we work with dynamic endpoint. when we add wcf service reference at client side then endpoint related setting automatically added in config file at client end.
could anyone please tell how dynamic endpoint discover my service address at run time just if we pass the contract. suppose if we have no config file at client end then how dynamic endpoint can discover my service?
could anyone please tell me in what kind of situation dynamic endpoint is used and only option ?
please discuss all my points in details. thanks
There are multiple ways of discovering services. There is UDDI and WS-Discovery.
It seems those classes use WS-Discovery. For a better overview, I'd suggest a good book, this is way to broad for a single SO question.
Related
Can anyone concisely describe or point me to a resource which explains how to call a service reference and pass in credentials? I have created the service reference from a wsdl, but I am stuck on how to call it with credentials?
I am an idiot - I was using the wrong class, need to use the one with Client in the name, eg
MyServiceClient c as new MyServiceClient();
not
MyService c = new MyService();
This allows setting of the ClientCredentials, eg
c.ClientCredentials.UserName.UserName = "joeblow";
I need to create the RESTful WCF service for the schema I have in the application. The schema which has three elements
My requirement is to create the WCF service so I can pass these three values through the service. Can anybody give me clear idea how can I approach this. I have been trying to create a schema, and promoted the one of the element for example the user name and created the property schema like
I deployed this and tried creating the WCf service through the publishing wizard selecting WCF WebHTTp adapter(which didnt ask we to select the schema) created the service and configured the application in Biztalk console. But the service is not working. If I call the service with the parameters , still it shows the
Can anybody please help me how can I approach this. I am really stuck with this for long time. Please any help is greatly appreciated. Thanks
This error means that Server is not able to find out the action it needs to do based upon the URL and request. Based on your configuration on receive location, your url should be localhost/demp/service1.svc/specimen=value, if that does not work then, change the Operation Name="Op1" Method = "GET" Url ="specimen/{specimen} and then your url should be localhost/demp/service1.svc/specimen/value
I'm using a really simple WCF project which is being hosted by a WPF application. It basically operates as a REST server for dishing up data on my PC. No IIS, and it runs as SingleInstance. I want to see what IP's are accessing MyService, and what WebMethod they're attempting to invoke.
Ok so I can have an event as part of my Service, declared in the service class itself. Here's some code that gets it going, it all works exactly as expected (no flames about m_ please ;)):
MyService ds = new MyService(); // It's not really called this :)
ds.Request += new EventHandler(ds_Request); // I want to avoid this
ds.SomePropertySetFromMyRehostingClient = "something"; // SingleInstance now required
m_Service = new ServiceHost(ds, new Uri(GetServerHostUri()));
m_Service.Description.Behaviors.Find<ServiceBehaviorAttribute>().InstanceContextMode = InstanceContextMode.Single;
m_Service.BeginOpen(new TimeSpan(0, 0, 5), new AsyncCallback(EndStartService), null);
Then in each service method, I can raise this event so my app knows that someone has tried to use it. Brilliant, but let's face it, this is awful.
I have to write something along the lines of:
var who = OperationContext.Current.IncomingMessageProperties.Via;
var what = OperationContext.Current.IncomingMessageProperties["UriTemplateMatchResults"];
for each service call.
Is there a more generic catch-all-event that can detect a call to my service? There's probably one fired by one of the many Behaviour/ChannelDispatcher types which I admittedly don't fully understand.
Thanks for your help, Tom
Using IParameterInspector you can hook to any method calls and inspect the method and/or parameters.
There is no other way to get the extra information (IP address, etc) of the incoming message other than the one you have used. This is just a bad design by Microsoft IMHO (see my rant here).
You can find an example here.
I am just getting started with WCF and am using an older article posted by Miguel A. Castro called WCF the Manual Way. In the article he mentions using the ChannelFactory to create a service proxy. In the article, he shows this code to create the proxy :
IProductAdmin productAdminChannel = new ChannelFactory<IProductAdmin>().CreateChannel();
When I try using that code with the endpoints configured in the web.config, I keep getting errors about this endpoint being null. Obvioulsy it works if I specify the name of the endpoint on the ChannelFactory constructor, but that doesn't seem to be the best option for re-usability. But it also seems to work if I do this :
IProductAdmin productAdminChannel = new ChannelFactory<IProductAdmin>("*").CreateChannel();
Is this just a change in how the ChannelFactory class works (since the article is almost 2 years old)? What is the "best practice" for creating WCF Service Proxies and re-usability?
I can't speak for the original article, but maybe it's just an oversight by the author? As far as I know, the 2nd listing in your post has always been the way to create the channel using the config file. Passing a * will use the default/first configuration for the channel type in the file. You can also pass a specific name instead of a * in the case that you have multiple named configs for the same type.
I have been using the ("*") route for several years now, and it's a good way to go if you are only going to have one endpoint per type.
I have a client app and a server app.
The client calls a wcf service and passes machine information
to server , based on the machine name the server calls back a wcf service on client side.
So to achieve this , I am just changing the EndPointAddress but then it's throwing
NoEndPointFoundException , how can i fix it , below is the code :
public void RegisterTasks(MachineConfig machineInfo)
{
string add = exeProxy.Endpoint.Address.Uri.Scheme + "://" + machineInfo.MachineName.Trim()+"/"
+ exeProxy.Endpoint.Address.Uri.Segments[1];
Uri uri = new Uri(add);
EndpointAddress eadd = new EndpointAddress(add);
WSHttpBinding whttpBinding = new WSHttpBinding(SecurityMode.None);
//ServiceReference1.ExecuteTaskClient newProxy = new ExecuteTaskClient(whttpBinding , eadd);
//EndpointAddress endPointAddress = ;
exeProxy.Endpoint.Address = eadd;
//exeProxy.Endpoint.Binding = new System.ServiceModel.BasicHttpBinding("httpBinding");
// we just execute the task by
// calling the wcf service on client side
foreach (Task task in machineInfo.Tasks)
{
exeProxy.ExecuteTask(task.TaskID);
// newProxy.ExecuteTask(task.TaskID);
}
}
I am assuming that you are getting EndpointNotFoundException not NoEndPointFoundException. I could not find a reference to NoEndPointFoundException.
http://msdn.microsoft.com/en-us/library/system.servicemodel.endpointnotfoundexception.aspx
What this is saying is that the client cannot find the server. In your case the server is trying to call back to the client, so the roles are reversed.
There are two things that could be wrong:
the url that you have in the variable "add" is incorrect (try logging the value)
the wcf service on the client side is not listening on the correct url (try putting the url in a browser)
Hope this helps
Shiraz
My first impression is that your design should be reconsidered. Any time I see an ingenious (read: bizarre) solution I see a whole heap of head banging in the making.
So firstly, write out what it is that you are trying to acheive in baby speak: "I want client to be contacted when server has new data." and then think about how it can be acheived using more conventional techniques.
Check out the duplex bindings - and polling a stateful singleton is not always a bad idea if you're not scaling into thousands of clients -- in fact, I bet it'd scale better than your current design.
But, to solve your current design issue, I'd setup the client (which will become the server) with the MEX endpoint (mexHttpBinding) and then set it off so its listening, then use VS (an empty project or from the server project) to try and connect to the client(server) by way of Add Service Reference and supplying the local machine name etc. This alone might turn up your problem. Then once added, you can use the autogen app.config to know what settings you need.
Also, have you considered how the server will be able to call the client if the server doesn't have the proxy classes setup?
It does sound like you're making a rod for your own back.