Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF POST方法_C#_Wcf - Fatal编程技术网

C# WCF POST方法

C# WCF POST方法,c#,wcf,C#,Wcf,{“远程服务器返回错误:(405)方法不正确 允许的}System.InvalidOperationException{System.Net.WebException} Web配置: <service name="Service" behaviorConfiguration="RestService"> <endpoint address="web" binding="webHttpBinding" c

{“远程服务器返回错误:(405)方法不正确 允许的}System.InvalidOperationException{System.Net.WebException}

Web配置:

      <service name="Service" behaviorConfiguration="RestService">      
        <endpoint address="web" binding="webHttpBinding"
                  contract="IService" behaviorConfiguration="ServiceBehavior">
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="RestService">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="ServiceBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <!--<protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>-->
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>
使用小提琴手:

POST /RESTfulService/Service.svc/web/TestPost/ HTTP/1.1
User-Agent: Fiddler
Host: localhost:50458
Content-Length: 43

HTTP/1.1 400 Bad Request
Server: ASP.NET Development Server/11.0.0.0
Date: Thu, 19 Dec 2013 07:19:44 GMT
X-AspNet-Version: 4.0.30319
Content-Length: 1647
Cache-Control: private
Content-Type: text/html
Connection: Close

GET方法工作正常,当我尝试使用POST方法时,我遇到了错误

我在本地尝试了上述示例,发现您缺少一个名为

Content-Type: application/json
还要确保在请求正文中传递了正确的json字符串

{"Name" : "test", "Address" : "test"}

上述技巧将帮助您摆脱400个错误的请求。

显示您发布的实际XML请求…问题似乎出在请求中,其他一切似乎都很好。我使用的是Json格式。格式是{“Name”=“test”,“Address”=“test”}Ops,我错过了。好吧,看看这个问题:,看起来是一样的。它不应该是
{“Name”吗“:”测试“,”地址“:”测试“}
?i、 e.
代替
=
。只需将内容类型设置为
application/json
。在给出的fiddler示例中,没有传递任何内容类型。这就是问题所在。
{"Name" : "test", "Address" : "test"}