c# - ProtocolException Unhandled/(405) Method not allowed with WCF; Bindings and Endpoints look right though -


i'm learning how use wcf , trying write little helloworld program scratch (both host , client sides). i've been getting protocolexception unhandled whenever client tries use service, , can't figure out why. i'm hosting service using iis.

regarding way have things set up: i'm doing best separate client, proxy, host, service, , contract detailed in video , outlined in article. i've got different projects within solution each of those.

here different files showing i'm talking about:

service

namespace helloworld {   public class helloworldservice : ihelloworldservice   {     public string getmessage(string name)     {         return "hello world " + name + "!";     }   } } 

contract

namespace helloworld {   [servicecontract]   public interface ihelloworldservice   {       [operationcontract]       string getmessage(string name);   } } 

proxy

namespace helloworld {   public class proxy : clientbase<ihelloworldservice>, ihelloworldservice   {     #region ihelloworldservice members      public string getmessage(string name)     {         return channel.getmessage(name);     }      #endregion    } 

}

client

namespace client {   public partial class form1 : form   {     public form1()     {         initializecomponent();     }      private void button1_click_1(object sender, eventargs e)     {         proxy proxy = new proxy();         messagebox.show(proxy.getmessage(textbox1.text));     }   } 

}

the client form textbox , button, , tries execute getmessage() using whatever in textbox parameter. there class creates instance of form.

here's web.config website:

web.config

<?xml version="1.0"?> <configuration>   <system.web>     <compilation debug="true" targetframework="4.0" />   </system.web>   <system.webserver>     <modules runallmanagedmodulesforallrequests="true"/>   </system.webserver>   <system.servicemodel>     <behaviors>       <servicebehaviors>         <behavior name="myservicetypebehaviors">           <servicemetadata httpgetenabled="true" />           <servicedebug includeexceptiondetailinfaults="false" />         </behavior>        </servicebehaviors>     </behaviors>     <services>       <service name="helloworld.helloworldservice" behaviorconfiguration="myservicetypebehaviors">         <endpoint address="http://localhost:8002/" binding="basichttpbinding" contract="helloworld.ihelloworldservice"/>         <endpoint contract="imetadataexchange" binding="mexhttpbinding" address="mex"/>       </service>     </services>   </system.servicemodel> </configuration> 

and here's app.config goes client:

app.config

<?xml version="1.0" encoding="utf-8" ?> <configuration>   <system.servicemodel>     <client>       <endpoint address="http://localhost:8002/" binding="basichttpbinding" contract="helloworld.ihelloworldservice" />     </client>   </system.servicemodel>  </configuration> 

my svc file short, just:

helloworldservice.svc

<%@servicehost service="helloworld.helloworldservice"%> 

i know service running, because when navigate http://localhost:8002/helloworldservice.svc in browser screen says

you have created service.

to test service, need create client , use call service.

so here's snag happens: service running using iis, start instance of client, window textbox , button come up, type in letters, hit button, , program crashes , protocolexception unhandled, (405) method not allowed. error happens on line of proxy class:

return channel.getmessage(name); 

i've been trying figure out hours , hours, , haven't made progress. if @ least point me in right direction, appreciative.

last thing: want write client , proxy scratch, without using svcutil.exe.

the reason works when go base address (.svc) http operation metadata service. when call method on service contract, you're doing post operation , more don't have feature enabled. depending on .net version you're targeting, 1 of these highlighted in red.

enter image description here


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -