Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The remote server returned an error: "(405) Method Not Allowed"

Tags:

c#

After reading different answers against the same thread i tried almost all the options mentioned in their discussions however i am still getting error:

Error No1: The remote server returned an error: (404) Not Found. OR

Error No2:The remote server returned an error: (405) Method Not Allowed.

Below is my code:

var httpWebRequest = (HttpWebRequest)WebRequest.Create("URL?Paramter1=pc&user=u1&password=p1");
httpWebRequest.ContentType = "application/json; charset=utf-8";
httpWebRequest.Method = "POST";
httpWebRequest.Accept = "application/json";
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

I receive error on the last line i.e.

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

If i use httpWebRequest.Method="GET" i receive the error number 1 as mentioned above and if i use httpWebRequest.Method="Post" i receive the error number 2.

like image 444
amw Avatar asked Nov 22 '22 23:11

amw


1 Answers

I too face this issue. Root cause of this error is may be mistook endpoint address in web config file..

This is my mistaken web config

<services>
  <service behaviorConfiguration="mexBehavior" name="sample.sample">
    <endpoint address="http://xxx.xxx.x.xxx:9335" binding="basicHttpBinding" contract="sample.Isamplebase" />
    <host>
      <baseAddresses>
        <add baseAddress="http://xxx.xxx.x.xxx:9335" />
      </baseAddresses>
    </host>
  </service>
</services>

It should be like this

<services>
  <service behaviorConfiguration="mexBehavior" name="sample.sample">
    <endpoint address="http://xxx.xxx.x.xxx:9335/sample.svc" binding="basicHttpBinding" contract="sample.Isamplebase" />
    <host>
      <baseAddresses>
        <add baseAddress="http://xxx.xxx.x.xxx:9335" />
      </baseAddresses>
    </host>
  </service>
</services>

Now its working fine... Best is yours.. Good Luck.

like image 126
Madhu Mca Avatar answered Mar 23 '23 05:03

Madhu Mca