2013-01-02 40 views
0

WCF休息POST总是越来越空字符串。我花了一个多星期的时间多去探索,但至今没有运气...WCF休息POST方法越来越空的JSON字符串

我的服务代码:

[ServiceContract] 
public interface ISaveSurvey 
{ 
    [WebInvoke(Method = "POST", 
      ResponseFormat = WebMessageFormat.Json, 
      RequestFormat = WebMessageFormat.Json,    
      BodyStyle = WebMessageBodyStyle.Wrapped, 
      UriTemplate = "/SSS")]   
    bool InsertSiteSurveyInfo(string jsonString); 
} 

Web配置:

<compilation debug="false" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service name="Honeywell.HBS.SiteSurvey.SaveSurvey" behaviorConfiguration="SaveSurvey"> 
     <endpoint address="" binding="webHttpBinding" contract="Honeywell.HBS.SiteSurvey.ISaveSurvey" behaviorConfiguration="wcfRestBehavior"/> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="SaveSurvey"> 
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above 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> 
     <endpointBehaviors> 
     <behavior name="wcfRestBehavior"> 
      <webHttp /> 
     </behavior> 
     </endpointBehaviors> 
    </behaviors> 
     <bindings> 
      <!-- Customizations for REST service --> 
      <webHttpBinding> 
       <binding name="ApiExportBinding" maxReceivedMessageSize="10485760" 
           maxBufferPoolSize="10485760" maxBufferSize="10485760"> 
        <readerQuotas maxDepth="32" maxStringContentLength="10485760" 
            maxArrayLength="10485760" maxBytesPerRead="10485760" /> 
        <security mode="None" /> 
       </binding> 
      </webHttpBinding> 
     </bindings> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

客户端代码:

<script type="text/javascript" language="javascript"> 
    function testRest() { 

     $.ajax({ 
      type: "POST", 
      dataType: "json", 
      url: "http://ie22ltjpsd4bs/SSTest/SaveSurvey.svc/SSS", 
      contentType: "application/json", 
      data: "{\"siteInformation\":{\"siteName\":\"Malar\",\"siteNumber\":\"123344555\",\"siteContactPerson\":\"test\",\"siteAddress\":\"test\",\"siteCity\":\"test\",\"sitePostalZipCode\":\"test\",\"siteTelephone\":1234576788,\"siteContractNumber\":\"asdfasdf\",\"siteHoneywellBranch\":\"asdfasdf\",\"siteFieldSiteLeader\":\"asdfasdf\",\"siteTeamLead\":\"asdfasdf\",\"siteTechnician\":\"asdfasdf\",\"equipments\":[{\"equipmentID\":\"BRANCH TOOL INVENTORY\",\"equipSiteContactTelephone\":12345678,\"equipDescription\":\"asdfasdf\",\"equipLocation\":\"asdfasdf\",\"equipSupervisionOrFrontEnd\":\"asdfasdf\",\"equipNumberOfStations\":12,\"equipMakeOrTypePC\":\"asdfasdf\",\"equipWindowsVersion\":\"asdfasdf\",\"equipManufacturer\":\"A C MOTOR\",\"equipManufacturerDateOrAge\":\"1979-12-31T18:30:00.000Z\",\"equipProductNameOrVersion\":\"asdfasdf\",\"equipGraphicSoftwareIncl\":\"No\",\"equipExistingSaveBackup\":\"Yes\",\"equipBackupSaveFormat\":\"\",\"equipLocalAccess\":\"asdfasdf\",\"equipPassword\":\"asdfasdfasdf\",\"equipRemoteAccess\":\"Modem\",\"equipAccessInfo\":\"asdfasdf\",\"equipSystemArchitecture\":\"Yes\",\"equipArchivedInAdept\":\"Yes\",\"equipOtherInformation\":\"asdfasdf\",\"controllersInformation\":[{\"controllerName\":\"asdfasdf\",\"controllerQuantity\":\"121\",\"controllerManufacturer\":\"asdfasdf\",\"controllerSoftwareProgram\":\"Yes\",\"controllerProductNameOrVersion\":\"asdfasdf\",\"controllerTypeOfProgram\":\"Interpreted\",\"controllerExistingSaveBackup\":\"Yes\",\"controllerBackUpSaveFormat\":\"\",\"controllerLocalAccess\":\"asdf\",\"controllerPassword\":\"asdf\",\"controllerRemoteAccess\":\"Modem\",\"controllerAccessInfo\":\"asdf\",\"controllerControlDrawings\":\"Yes\",\"controllerOperatingSequence\":\"Yes\",\"controllerOtherInformation\":\"asdfasddf\"}]}]}}", 
      success: function(result) 
      { 
       alert("Sucess"); 
      }, 
      failure: function(result) 
      { 
       alert("Failure"); 
      } 
     }); 
    } 
    function (result) {  
    } 
</script> 

按钮点击:

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" OnClientClick="testRest()" Text="Button" /> 

我重视w3wp进程,并尝试调试服务和JSON字符串总是越来越空。但我用小提琴手拦截请求的json字符串越来越张贴bu服务执行代码总是变空。

回答

0

这是计划的行为。您的服务并不知道如何映射你传递数据。 如果你打算把你的json的东西作为一个字符串传递,你应该这样包装它:

data: JSON.stringify({ jsonString: "your_data" }) 
+0

Gr8 ...它的工作...非常感谢! –