Comments (15)

  1. Anonymous says:

    Really interesting post.Thank you!

  2. Anonymous says:

    Great post, I've been struggling with this.  I'm onboard with it not working.  However, can you direct me to what I should be doing?  I've seen snippets of it in many of your posts, but nothing that is complete.  Is there a good guide on what to do instead?

    Thanks!

  3. Brian, if you want to use WCF as a client for a REST service, the simplest way is to literally copy the contracts (the service contract, and any data contracts it may use) to the client application, then use the WebChannelFactory<T> to create a client to talk to the service:

    WebChannelFactory<IService> factory = new WebChannelFactory<IService>(new Uri(endpointAddress));

    IService proxy = factory.CreateChannel();

    int result = proxy.Operation(1, 2, 3);

  4. Anonymous says:

    Useful post. Thank you!

  5. Anonymous says:

    Hi,

    I have a .svc URL and can access the WSDL portion.

    I want to use the service in my Android and iOS application. Generally for WSDL I use SOAP UI, but in SOAP UI it is not able to generate the operations/methods. For one of the login operation, I am getting a JSON response. But for other methods I am not sure how to access the operations.

    Is there a tool/way to know what will be the sample request and corresponding response for a particular .svc service.

    Regards,

    Nirav

  6. If you get a JSON response, then the WSDL you get is probably not complete. As I mentioned in this post, if you have a WCF service which only exposes JSON endpoints, you cannot trust the WSDL to consume it, it doesn't have enough information.

  7. Anonymous says:

    Thanks for helping.

    I too was struggling with this.

  8. Anonymous says:

    Then how do you consume WCF services from an ASP.net application?

    In other words, what is necessary in the Web.Config file to make the connection?

  9. Mike, to consume REST endpoints you'd normally use regular HTTP clients such as HttpClient, HttpWebRequest or some other HTTP library. You can use the WCF client as well – copy the data and service contracts to your client project (in your case, the ASP.NET app), create a WebChannelFactory<YourServiceContractInterfaceType> passing the endpoint URL for the REST endpoint, and call CreateChannel() on your interface to give you a typed client.

  10. Anonymous says:

    This is an older entry, but still helped me figure out why I wasn't able to consume my REST WCF service via Visual Studio.  What I found that worked pretty well was to:

    1) Do the Add Service Reference like usual, to get the service Request/Response model classes.

    2) Use JSON.NET to serialize and deserialize those objects to JSON, passing them to

    3) RestSharp which makes the actual REST calls.

    However, knowing now that Visual Studio's support when doing WCF REST is pretty limited, we'll probably start creating REST endpoints in addition to the normal WCF bindings, rather than replacing them.

    Thanks!

  11. Anonymous says:

    Thanks for your post.

    I too was struggling with this issue.

    Can you tell me instead of webHttpBinding which one I should use…I want to call the wcf service in my asp.net  application …

  12. @Sugendar, you can still call a webHttpBinding endpoint via ASP.NET – in fact, if you use the HttpClient classes it's fairly simple to do. What you won't have is a typed proxy that you can use in the client, but for REST endpoints this is usually not a big drawback.

  13. Anonymous says:

    Sir Very Interesting Explanation….Even i also facing this issue since very long time..and i m not  able to fine solution…thanks for such a very good and exact explanation that why its not possible….

  14. Anonymous says:

    Nice post, but due to my limited knowledge of WCF I'm experiencing problem in working properly with it.

    I created A VB.NET project where a web service (server side) is implemented and correctly working. Then I want to consume this web service into another project, so what I did is to

    ' Enable metadata publishing.

               Dim smb As New ServiceMetadataBehavior()

               smb.HttpGetEnabled = True

               smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15

               host.Description.Behaviors.Add(smb)

     'Add MEX endpoint

              host.AddServiceEndpoint( _

                    ServiceMetadataBehavior.MexContractName, _

                    MetadataExchangeBindings.CreateMexHttpBinding(), _

                    "mex")

    so into my client project I added the service by Visual Studio with rigth click on Service References and indeed I found my interfaces (take care that the Interface Service Description, and the data definition classes I put them into a class library into the server project and I imported it into the client project)

    Into the client project I wrote as suggested into this post the following lines in order to consume the webservice:

    Dim myBinding As New ServiceModel.WebHttpBinding

    Dim factory As System.ServiceModel.Web.WebChannelFactory(Of IFCDMapMatchedResultsWebService) = New System.ServiceModel.Web.WebChannelFactory(Of IFCDMapMatchedResultsWebService)(myBinding, New Uri("http://localhost:8082/fcdmapmatchedresults/mex&quot;))

    'Create a channel.

           Dim wcfClient As IFCDMapMatchedResultsWebService = factory.CreateChannel()

           Dim parameters As New FCDMapMatchedResults.inputParam

           parameters.id = 1

           parameters.treq = "info"

           parameters.VehicleTrajID = "1"

    Dim trj As FCDMapMatchedResults_response = wcfClient.PostXML(parameters)  '("match", 11, "3-846758

    BUT i get the following error:

    "no endpoint listening on "http://localhost:8082/fcdmapmatchedresults/PostXML&quot;

    SO

    I added the following URI "http://localhost:8082/fcdmapmatchedresults/PostXML/mex&quot; ad it seems working except that I get the following error now:

    content type application/xml; charset utf-8 not supported by the service "http://localhost:8082/fcdmapmatchedresults/mex/PostXML&quot;

    WHAT IS IT?

  15. Anonymous says:

    What if we add the WebGet/WebInvoke attribute above the method in the client proxy (generated by Add Service Reference) for the REST service? I saw this solution in some post.