我使用 WCF 创建 Web 服务,但无法从 PHP 或 Mozilla Client Rest API 访问 POST 方法。我尝试更改 bodyStyle 并且不声明它,但我无法完成它。我总是收到 400 错误请求。GET 方法正在工作。这是我的定义:
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "/InsertMember",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
InsertMemberResponse InsertMember(string city, string address, string state, string zipcode, string country_code, string email, string firtname, string lastname, string password, string national_document_id, string phone, string restaurant_id, string birthday,bool email_checked, bool want_adverts, bool want_notifications, bool want_offers, bool want_thidparty_offers, bool want_newletter, string company_name,string auth );
我的服务模式:
<system.serviceModel>
<services>
<service name="Mellizos.Fidelidad.Services.RestService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/Mellizos.Fidelidad.Services/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="basicHttpBinding" contract="Mellizos.Fidelidad.Services.IRestService">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false before deployment -->
<serviceMetadata httpGetEnabled="True" />
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>