我创建了一个通过 IIS 在本地托管的 WCF Web 服务。我已经使用 WCF 测试客户端来确认服务是否正常工作,现在我想通过手动 REST 调用进行测试。我正在使用RESTClient 3.1发送 REST 调用。我能够从方法中检索结果,但是我尝试将 JSON 作为参数发送总是会导致参数为空。我究竟做错了什么?我的请求的返回正文是“FAIL :(”提前谢谢!到目前为止,我已经花了一天多的时间来解决这个问题。
服务合约:
[OperationContract]
[WebInvoke(
Method = "POST",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
public string Route2(Position start)
{
if (start == null)
{
return "FAIL :(";
}
else
{
return "SUCCESS :)";
}
}
** web.config:**
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd"/>
</handlers>
<defaultDocument>
<files>
<add value="help" />
</files>
</defaultDocument>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service name="Primordial.GroundGuidance.Service.GroundGuidanceService">
<endpoint address="soap" binding="basicHttpBinding" contract="Primordial.GroundGuidance.Service.GroundGuidanceService" />
<endpoint address="" binding="webHttpBinding" bindingConfiguration=""
name="web" contract="Primordial.GroundGuidance.Service.GroundGuidanceService"
kind="webHttpEndpoint" endpointConfiguration="webEndpointWithHelp" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="webEndpointWithHelp" helpEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
因为我使用的是 RESTClient,所以调用不仅仅是一个字符串/文件,而是我拥有的标头值对: Accept: application/json contentType: application/json
正文类型设置为“application/json; charset=UTF-8”正文:
{
"elevation": 0,
"latitude": 35.31,
"longitude": -116.41
}