Using C# WCF REST Service with JSP Servlet - wcf

I've created a simple WCF REST Service. It only has one method that returns a JSON string of an employee object.
I'm fairly new to designing web services... What do I need to do in order for a JSP Servlet to invoke that method, retrieve the data, and display the data?
Do I need to generate WSDL or can I simply call http://localhost:8080/TestService/Employee and deserial the JSON string?
Thanks in advance for your help.

With a REST service there is no WSDL, that is a WS-* and SOAP artifact. So you just call the service URL with something like the WebClient, HttpClient or HttpWebRequest and process the response.

Related

Is there any way to hide the operation contract tag in the wsdl for WCF soap web service?

For example, if I have a operation contract as GetData() I dont want it to be in wsdl but the method should be accessible by client using Action Attribute and would be able to be consumed.
So the client should just "know" that the service method is there and how to call it?
Anyway no, you can't do that. Save the generated WSDL and XSDs, modify them to remove the information you want to remove and then supply these WSDL and XSD to the client.

Using basicHttpbinding and get the response in raw data

I've looked all day and I couldn't able to find a correct answer on how get the response of my Web Service using basicHttpBinding without the SOAP formatting.
Can anyone know how to do that ? or another way for getting the raw data ? (like a string)
You have to use webhttpBinding. Look at the following articles, it might help you:
Creating WCF Service with SOAP/REST Endpoints
How to enable REST and SOAP both on the same WCF Service
An Introduction To RESTful Services With WCF

WCF BasicHttpBinding Http Post

Is it possible to post to a WCF service hosted in IIS? I know that that this is possible using REST but I really need the WSDL generation and SOAP headers. I need to transition an existing ASMX web services to WCF but I need to also allow my clients to continue to utilize the service via http posts (xml http request via javascript). Is REST my only option?
No, with a SOAP service, you need to use the SOAP methods and actions - you cannot use HTTP POST to "dump" some data on a SOAP service.
If you need HTTP POST, then REST is the way to go.
You can also use REST style WCF
http://msdn.microsoft.com/en-us/netframework/cc950529.aspx

How to perform GET web requests to WCF Service Without WCF Client?

I want to send a GET web Request to a WCF service:
for example to:
http://TheirServerIP:PortNumber/TheirService/TheirServiceName.svc?op=theirWCFmethod
i want to write a C# code in my page (web aplication) that send HTTP GET request to their service (without WCF Client)
can i do that ?
To create a WCF service that responds to HTTP GET or HTTP POST requests
http://msdn.microsoft.com/en-us/library/bb628610.aspx
Well, in that case, you need to create a WCF REST service, one that can be called from any language using any HTTP stack and no need for any WCF specifics.
Check out the WCF REST developer center for lots of great info on WCF REST services.
Basically, what it boils down to is
using the WebHttpBinding on your server side
defining a URL pattern to handle requests and their parameters
For the client part of this, use the answer Ladislav provided - just new up a HttpRequest object and make a HTTP GET request to a valid URL - that's all there is, really.
The basic approach to call HTTP resource is:
var request = HttpWebRequest.Create("YourURL");
request.Method = "GET";
var response = request.GetResponse();
...

WCF Service invoking - without any reference added

I want to invoke a wcf service for testing on the http layer. I do not want to add a service reference and create a proxy and invoke. I want to create a new web test(VSTS) which sends a http request to the service and posts(Http post) the request in http body as an xml.
I have service metadata, with which I can see the datacontracts, but the wsdl:operation has only the operation name, wsdl:input is just blank.
On the Contary, an asmx service will have the soap request in the metadata which can be copied as the http request body, with the parameters replaced.
How to build a wcf service xml body from scratch just by looking at the service metadata (no access to the service logs as well), have got just the end point.
It is something like
<root>
<element1>element1</element1>
<element2>element2</element2>
</root>
But, how to find out this, root has to be some thing like
<FunctionRequest xmlns=""http://schemas...."" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"">
(tested for a local service and worked)
Now, without having access to service logs(svctraceviewer logs), not able to add a service reference, not able to use svcutil.exe(certificate based service), just only with metadata - wsdl, is there a way to find out the request that is to be sent to service?
Well, you will have to create proxy - either statically by adding a service reference or running svcutil on your service metadata, or you can construct it dynamically totally in code, if you wish.
In that case, you'd have to have your service contract (ISomethingService) at hand, and check out the ChannelFactory < ISomethingService > () concept - that should get you started.
Marc
Yes you can, but you have to do a little work first.
Build the service client by running svcutil.exe on the wsdl/xsd metadata. This will generate a c# with your service and data contract objects. Compile that to an assembly using csc.exe.
See the soap envelope body you can create a request object and manually serialize it with data contract serializer. Or you can host the assembly in WcfSvcHost.exe and add wcf logging to the config file. In either case you will only have the correct xml for the body, and even that might be wrong if the real service uses xml serializer instead of data contract serializer.
The next part is the hard part because you need to know the security model for the real service. If it only uses certificates for SSL and server identification, you should be able to send the xml using WebClient. But if it uses mutual certs and/or security tokens, you pretty much have to create a channelfactory by hand with the right bindings.