1
我創建了一個WCF Web服務,該服務通過IIS在本地託管。我已經使用WCF測試客戶端來確認服務工作正常,現在我想通過手動REST調用進行測試。我正在使用RESTClient 3.1來發送REST呼叫。我能夠從方法中檢索結果,但是我嘗試在參數中發送JSON總是導致null參數。我究竟做錯了什麼? !從我要求退貨的身體是「FAIL :(」在此先感謝我花了一天就這個問題至今測試帶有WCF服務參數的POST請求
服務合同:
[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實現呼叫不是隻是一個字符串/文件,但頭值對我有: 接受:應用/ JSON 的contentType:應用程序/ JSON
正文類型設置爲「application/json;字符集= UTF-8" 體:
{
"elevation": 0,
"latitude": 35.31,
"longitude": -116.41
}