<system.serviceModel> <bindings> <webHttpBinding > <binding> <security mode="None"> </security> </binding> </webHttpBinding> <customBinding> <binding name="JsonMapper"> <!--此处配置相当重要,使用了我们编写的JsonContentTypeMapper类,约定返回值类型是Json--> <webMessageEncoding webContentTypeMapperType="TenantPlatform.WCF.Tools.JsonContentTypeMapper, JsonContentTypeMapper"> </webMessageEncoding> <httpTransport manualAddressing="true"/> </binding> </customBinding> </bindings> <services> <service behaviorConfiguration="TenantPlatform.WCF.MobileDataServiceBehavior" name="TenantPlatform.WCF.MobileDataService"> <endpoint address="" binding="webHttpBinding" behaviorConfiguration="httpBehavior" contract="TenantPlatform.WCF.IMobileDataService" > <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> <service behaviorConfiguration="TenantPlatform.WCF.TemporyTaskDataService" name="TenantPlatform.WCF.TemporyTaskDataService"> <endpoint address="" binding="webHttpBinding" kind="webHttpEndpoint" behaviorConfiguration="httpBehavior" contract="TenantPlatform.WCF.IMobileDataService" > <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> <behaviors> <endpointBehaviors> <behavior name="httpBehavior"> <webHttp /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="TenantPlatform.WCF.MobileDataServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> <behavior name="TenantPlatform.WCF.TemporyTaskDataService"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <!--<standardEndpoints> <webHttpEndpoint> <standardEndpoint contentTypeMapper="TenantPlatform.WCF.Tools.JsonContentTypeMapper, JsonContentTypeMapper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> </webHttpEndpoint> </standardEndpoints>--> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> </system.serviceModel> <system.diagnostics> <sources> <source name="System.ServiceModel" switchValue="Warning" propagateActivity="true"> <listeners> <add name="xml" /> </listeners> </source> <source name="System.ServiceModel.Web" switchValue="Warning" propagateActivity="true"> <listeners> <add name="xml2" /> </listeners> </source> </sources> <sharedListeners> <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="d:\temp\wcf_sm.svclog" /> <add name="xml2" type="System.Diagnostics.XmlWriterTraceListener" initializeData="d:\temp\wcf_smw.svclog" /> </sharedListeners> </system.diagnostics> </configuration>
[OperationContract] [WebInvoke(Method = "POST", UriTemplate = "GetOrdersList2", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)] string GetOrdersList2(OrdersListRequest pOrdersListRequest);
使用 Http Post请求时 接收到的参数 一直为 null。
http://localhost:60613/Impls/MobileDataService.svc/GetOrdersList2
User-Agent: Fiddler
Content-Type: json; charset=UTF-8
Host: localhost:60613
Content-Length: 182
请求字符串:{"ClientName":"WTS","UserName":"021-120001","Password":"cf79ae6addba60ad018347359bd144d2","ConditionOr": "","ConditonAnd": "{\"OrdersType\":1,\"Status\":1}","Page": 1,"PageSize": 15}
传入消息的消息格式不应为“Raw”。此操作的消息格式应为 'Xml', 'Json'。这可能是因为绑定尚未配置 WebContentTypeMapper。有关详细信息,请参见 WebContentTypeMapper 文档。
{"pOrdersListRequest":{"ConditionAnd":[{"Key":"OrdersNo","Value":"1"},{"Key":"StoreName","Value":"2"}],"ConditionOr":[{"Key":"OrdersNo","Value":"1"}],"ClientName":"999999","UserName":"021-0001","PageIndex":1,"PageSize":20,"Password":"6deb0810219263d5b82e664e72b03c75"}}
字符串格式:{“参数名”:{参数Json实体}}
contentType: "application/json; charset=utf-8"