Call wcf service GET methods from client application

I have a Wcf service RESTful and now I'm making a client ASP.NET MVC application.

I added service reference.

I want to call GET method from my wcf service. Here is what I tried:

EndpointAddress endPointAddress = new EndpointAddress("http://localhost:1234/MyService/MyEndPoint"); var channelFactory = new ChannelFactory<MyService>("WebHttpBinding_IMyService", endPointAddress); MyServiceClient client = new MyService.MyServiceClient("WebHttpBinding_IMyService"); MyService.IMyService myClient = channelFactory.CreateChannel(); MyService.SomeClass theClass = myClient.MyMethod(model.UserName, model.Password);

Here is the important part from my web.config file from my client application:

<system.serviceModel> <bindings> <customBinding> <binding name="WebHttpBinding_IMyService"> <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap12" writeEncoding="utf-8"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> </textMessageEncoding> <httpTransport /> </binding> </customBinding> </bindings> <client> <endpoint binding="customBinding" bindingConfiguration="WebHttpBinding_IMyService" address="http://localhost:1234/MyService/MyEndPoint" contract="MyService.IMyService" name="WebHttpBinding_IMyService" /> </client>

Here is the important part of my wcf service web.config file:

<system.serviceModel> <services> <service behaviorConfiguration="MyServices.MyDataServiceBehavior" name="MyServices.MyDataService"> <endpoint address="MyEndPoint" behaviorConfiguration="poxBehavior" binding="webHttpBinding" contract="MyServices.IMyDataService" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <endpointBehaviors> <behavior name="msAjaxBehavior"> <enableWebScript /> </behavior> <behavior name="poxBehavior"> <webHttp /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="MyServices.MyDataServiceBehavior"> <serviceMetadata httpGetEnabled="true" httpGetUrl="" /> <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors>

I also tried this:

MyService.MyServiceClient client = new MyService.MyServiceClient("WebHttpBinding_IMyService"); client.Endpoint.Address = new EndpointAddress("http://localhost:1234/MyService/MyEndPoint"); BasicHttpBinding binding = new BasicHttpBinding(); using (ChannelFactory<MyService.IMyService> cf = new ChannelFactory<MyService.IMyService>(binding)) { MyService.IMyService proxy = cf.CreateChannel(); using ((IDisposable)proxy) using (new OperationContextScope((IContextChannel)proxy)) { client.MyMethod(model.UserName, model.Password); } }

But it says error - The Address property on ChannelFactory.Endpoint was null. The ChannelFactory's Endpoint must have a valid Address specified.

I also tried:

MyService.MyServiceClient client = new MyService.MyServiceClient(); client.MyMethod(model.UserName, model.Password);

But it says ProtocolException: The remote server returned an unexpected response: (405) Method Not Allowed.

Category:client Views:0 Time:2012-01-10
Tags: wcf client

Related post

  • how do i use WCF service instead of socket client-server application? 2012-02-18

    im wondering about how to use WCF service instead of sockets .. to send commands .. someone told me its more powerful than creating a client-server application my application about send/receive Commands chat file transfer in my application i have to

  • WCF Service with mvc application 2009-06-03

    I have started using MVC and as traditional way I want to keep my data access layer in WCF service. How can I achieve that using MVC ? Scenario I started a test application in MVC which Displays, Inserts and Edit data. I succe

  • Sharing types between WCF services and their .net clients 2011-06-24

    Sharing types between WCF services and their .net clients While I know that this can be done, I somehow feel there is something fundamentally wrong in the design when you feel the need to use an assembly on the service and use the same on the .net cl

  • TransactionScope in WCF service or in the client proxy? 2012-01-19

    Regarding transactions in WCF services, shall I use TransactionScope object in client side application that consumes the service or in the service code? Please explain why. --------------Solutions------------- Making a service transaction aware means

  • WCF Service Check for a Client Timeout 2012-03-07

    Is there a way in a WCF service to catch a client timeout I need to run some special logic on a client timeout. I have not found any sources indicating a WCF service can check if a client timeout through service side Error Handling, Etc... if you req

  • How to authenticate the WCF Services while Consuming by client 2010-01-11

    How to authenticate credentials of the WCF Services while Consuming by client? --------------Solutions------------- This is both a small and a large topic in my view. To understand this there's a fair bit of material to go through, once you know what

  • Host a Wcf Service Library in a Web Application 2010-08-11

    I would like to host a Wcf Service, create in a Wcf service Library, in a Web Application. I've already done the same thing with Web Service asmx : using System.Reflection; using System.Web; using System.Web.Services; using System.Web.Services.Protoc

  • Create WCF service for unmanaged C++ clients 2009-03-26

    I need to get unmanaged Windows C++ clients to talk to a WCF service. C++ clients could be running on Win2000 and later. I have a control over both WCF service and which C++ API is being used. Since it's for a proprietary application, it is preferabl

  • WCF Service 405 Method Not Allowed Exception 2010-02-04

    I'm writing a WCF service in Visual Studio 2008 to be hosted on a Windows 2008 Standard server. I've created a new Web Site in IIS7 with its own application targeted to ASP.NET 2.0. I added .NET 3.0 Framework features to the server role. I've already

  • calling a WCF service object method in another WCF service 2010-06-15

    I using two WCF services. WCF service A is hosted in my .NET Winform application and WCF Service B is hosted on a Windows Service. I am able to instantiate a client for WCF Service B and use the methods - i.e. call the WCF service hosted on Windows s

  • jQuery Ajax call to WCF service returning "Method not allowed (405)" 2010-06-16

    I created a WCF SOAP service using VS 2008 that works server side. I tacked on the code below to call the same service/contract client side using jQuery/json (no ASP.NET scriptmanager). When I put the service url into the browser, I get the correct s

  • Sharepoint 2010 wcf service. call method with jquery 2011-02-23

    i have wcf service hosed in sharepoint application. But when i try to call method from jquery it always fails. I have tested service with such string: ttp://localhost/_vti_bin/webservices/wcfservice.svc/**mex** and have normal response. WCF test clie

  • WCF Service (JSON) and Android client - message security 2011-11-22

    I have WCF service, that gets and returns JSON data. and Android mobile app, that calls this service. How do I encrypt messages between these two, if possible? If not, how to do custom encryption? Edit: Here is an additional information for server an

  • WCF Services show methods like LoginAsync(-) instead of Login(-) 2012-01-22

    So I made a simple service that allows Registrations and LogIns, so the only methods in my service contract are : Register(string username, string password) and LogIn(string username, string password). When starting the service in the Visual Studio s

  • Deploying WCF Service with ASP.NET Web Application 2012-02-01

    I am having some difficulty in deploying my WCF service alongside my ASP.NET web application. I have everything working on my local machine (defined my address, bindings, contract) and I can call the service from my ASP.NET (MVC) web application. (Ba

  • Consuming C# WCF service from Delphi 2010 client: Databinding and Entity Framework 2012-04-25

    I am migrating a win32 Delphi VCL application written in Delphi 2010 to a multi-tiered architecture. The application makes extensive use of ExpressGrids (TcxGrid) by devexpress for databinding. I have designed the data tier based on Entity framework,

  • WCF Service Returning "Method Not Allowed" 2008-09-03

    In the process of developing my first WCF service and when I try to use it I get "Method not Allowed" with no other explanation. I've got my interface set up with the ServiceContract and OperationContract: [OperationContract] void FileUpload(Uploaded

  • Identity of thread in self hosted WCF service when called from Web Application 2009-12-23

    I have a Windows Service that is self hosting a Wcf service, this Wcf service has a tcpBinding with default settings. The Windows service is running as LocalSystem. The Wcf Service is referenced (default settings) by a Web application that is running

  • WCF Service Layer in n-layered application: performance considerations 2010-04-10

    When I went to University, teachers used to say that in good structured application you have presentation layer, business layer and data layer. This is what I heard for more than 5 years. When I started working I discovered that this is true but some

Copyright (C), All Rights Reserved.

processed in 0.083 (s). 11 q(s)