In WCF 4.0, there is better support for creating restful APIs for us. By defining Uritemplate,webinvoke, you can quickly develop API interfaces.
Here I record how to receive the post data when the HTTP POST data.
1, method One: stream InputStream input stream method (take a look at the method
For example, my Code
" POST ", Responseformat = Webmessageformat.json, bodystyle ="json/ui/{projectname}/{ entityname}?q={querystring}&id={indentity}")] Updateorinsertentityresponse Updateorinsertentityresponse (String projectName, String entityname, String querystring,string indentity,stream Pstream);
UriTemplate defines a parameter matching relationship.
"Json/ui/{projectname}/{entityname}?q={querystring}&id={indentity}"
The corresponding parameters
String ProjectName, String entityname, String querystring,string indentity
The names must be the same, otherwise they cannot be matched. All fields must be of type string.
How to get Post data information.
Defines the stream pstream parameter.
If you run the application now, you will get an error message on the page:
is Stream.
How to resolve.
The first step is to modify your own service.svc file.
The original
<%@ ServiceHost language= "C #" debug= "true" service= "Vine.DataMan.RestfulService.EntityService"
Codebehind= "EntityService.svc.cs"%>
Add a new property:
factory= "System.ServiceModel.Activation.WebServiceHostFactory"
The final result is:
<%@ ServiceHost language= "C #" debug= "true" service= "Vine.DataMan.RestfulService.EntityService"
Codebehind= "EntityService.svc.cs" factory= "System.ServiceModel.Activation.WebServiceHostFactory"%>
Modify the configuration file Web. config
<system.serviceModel>
<services>
<service name= "Vine.DataMan.RestfulService.EntityService" >
<endpoint binding= "WebHttpBinding"
contract= "Vine.DataMan.RestfulService.ServiceContracts.IEntityCommonService"
behaviorconfiguration= "webhttp"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name= "webhttp" >
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<!--to avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above BEFO Re Deployment--
<servicemetadata httpgetenabled= "true"/>
<!--to receive exception details on faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information-
<servicedebug includeexceptiondetailinfaults= "true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<servicehostingenvironment aspnetcompatibilityenabled= "true"/>
</system.serviceModel>
Note the bold text. The behavior of the webhttp must be defined.
WCF Usage Summary: (1) WCF receives HTTP POST data processing method