Hello I am very new to WCF Services kindly excuse me for wrong terminology. I need to display all the methods in a list and when the method is selected I need to show the parameters so the user can enter the parameter value like id and name so that we can invoke the service and compare the result with expected and actual result.
Note: the user will only provide the WSDL URL, and from there I can generate a dynamic proxy because our services usually change using (http://blogs.msdn.com/b/vipulmodi/archive/2006/11/16/dynamic-programming-with-wcf.aspx).
How do I get the operation and parameter types so that we can generate client and invoke service with the parameters. Just want to display methods get the values for parameters from user and invoke the service in a C# windows application.
Related
How to identify operation from xml content posted to WCF Service Url?
Suppose WCF Service Url is http://single.mat.nn.com and client dont want to include operation name in Url.
Problem is to identify operation on the basis of xml content posted .
I am not able to find any solution for this problem. Is it feasible to do configuration in WCF Service that can identify operation method on the basis of xml content posted to WCF Service URL.
One of the scenarios possible in Extending Dispatchers is:
Custom Operation Dispatching. Users can implement dispatching on something other than action – for example, on the body element, or on a custom message property. This can be done using the IDispatchOperationSelector interface.
Implmenting IDispatchOperationSelector will give you access to the incoming message to parse and decide which method you want to forward the request to.
The SOAP web service based on the corresponding method of the SOAPAction field request in the HTTP request. See the screenshot below.
The SOAPAction field and the method section in the request body can view the operation name of the specific request. If you want to recognize this value, we can intercept the SOAP message through the following two interfaces and get the value of the field.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/extending/how-to-inspect-or-modify-messages-on-the-client
https://learn.microsoft.com/en-us/dotnet/api/system.servicemodel.dispatcher.idispatchmessageinspector?view=netframework-4.8
these two interfaces could capture the SOAP message during the communication. We could retrieve the field value and modify it.
Feel free to let me know if there is anything I can help with.
I have a WCF Service with a method that has 3 parameters: 1 input and 2 outputs. Eg.
Foo(input, out1, out2)
I add the service reference fine in my client code, however, when I go to call the service, visual studio doesn't recognise the parameters properly. I have to call the service as
Foo(out1, out2, input)
Why is this? I can see that the order is reversed in the reference file of the service reference, but if I change the order then visual studio gives me errors saying that they are not in the right order. Is this normal behaviour? Do I just need to call the service using the reversed parameters?
...when I go to call the service, visual studio doesn't recognise the
parameters properly
The problem you are having is by design.
When the service exposes the WSDL metadata to consumers, there is nowhere in the service definition where the service operation signature is maintained in its original form.
Instead, the input and output parameters are declared in separate collections.
Now, it's the job of the Add Service Reference tooling to make an attempt at reconstructing the original operation signature for consumers from the metadata, but in this instance it cannot. The original operation signature has been lost at this point. So it just reconstructs the operation processing the output parameters collection first, and then the input parameters, hence your observed behaviour.
The only way to make this go away is to:
not use output parameters in your service operation definition. This is recommended anyway, as output parameters are a code quality flag and should be avoided if possible, or
not expose metadata from the service. Consumers can call the service directly by using the actual service definition types using a WCF channel instead of using a service reference. This is generally regarded as being a superior method for calling a service in WCF.
Or you could just do nothing. The consumer is still able to call the service operation right?
I am developing the SSRS report and wanted to consume the one method call of the WCF service. Suppose I have a service Url like http:\\localhost\2014\security.svc and wanted to consume string Encrypt(string data) method from that service.
Now I know how to use XML and Web service as the data source. I don't want that what I want is to call the web service to get the some values encrypted on the report so I can use the expression to set the encrypted values for the some fields. In case of confusion feel free to leave a comment. Any help would be great .
In my services all the methods except certain mandatory parameters and all the input parameters are encapsulated inside message contract.
Right now, we are validating the input in each and every service method, Its like duplicating validation logic in all the service methods. Is there any way I can move all these validation to common place and more over I don't want my service method to be executed as the input is not valid.
Appreciate your suggestions.
Yes, you can use FluentValidator for each MessageContract request.
You can write the commom validator for the request which have common validation rules.
Ex: If you want the validate employee profile in both CreateEmployeeRequest, UpdateEmployeeRequest then you can write the commom validator for Employee Profile (EmployeeProfileValidator) and make use of this validator in Create & Update Employee request validators..
Enterprise Library Validation Application Block has a module for Integration with WCF.
It implements input validation as a WCF parameter inspector. Your method will never be called if it the parameters fail validation.
I am following along in the .6 release of the WCF Web API chm file. I have built my service and everything works fine when I access it via IE. But when I create my console app, I don't understand how the client can know about the "contact" type. Sure I can add a reference, but how would some other client out there in the world know about the types?
List<Contact> contacts = resp.Content.ReadAs<List<Contact>>();
How would a client know about changes to the Contact class?Thanks.
Using the SOAP based WCF bindings, the client would normally generate a client off the WSDL, which would specify these custom types.
However as far as I know, in the REST based world of Web API, there is no facility for doing that. It is expected that the 3rd party customer / programmer making the client is given the data contract in some other form, and makes a compatible class.
In other words, there is not really an automatic way of doing that.
Every property on your client type that matches a property (Name/Type) in the response type is mapped by ReadAs<T>.
If you have a string property "Name" on your response type and your client type, its value is being parsed.
You don't need a reference.
Update: If you don't want to work with a contacts type on the client side you could try something like this:
var json = JsonValue.Parse(response.Content.ReadAsStringAsync().Result);
If your contact type on the server side had a property "Name" you should be able to do the following:
var name = json["Name"];
(Assuming your response was a single contact - in case of List<Contact> "json" would be of type JsonArray - you should get a clue... here is a sample showing usage of JsonValue and JsonArray).
Concerning "changes on contact type" please read this.