Http://www.cnblogs.com/dudu/archive/2011/01/19/1939094.html
WCF contract
Using system. servicemodel;
Using system. servicemodel. activation;
...
[Servicecontract]
[Aspnetcompatibilityrequirements (requirementsmode = aspnetcompatibilityrequirementsmode. Allowed)]
Public class helloservice
{
[Operationcontract]
Public String say (string word)
{
Return string. Format ("You say \" {0} \ ".", word );
}
}
It is worth noting that aspnetcompatibilityrequirements does not take ASP if this setting is not performed. net pipeline, Asp.. net, for example, httpcontext. current is null. The most common scenario is to obtain user logon information based on httpcontext and verify user permissions. Corresponding to this setting, in
<Servicehostingenvironment aspnetcompatibilityenabled = "true">
Web. config
<System. servicemodel>
<Servicehostingenvironment aspnetcompatibilityenabled = "true"> </servicehostingenvironment>
</System. servicemodel>
* Note: After the preceding settings are added to Web. config, The aspnetcompatibilityrequirements attribute must be set for all WCF Service implementations.
<System. servicemodel>
<Servicehostingenvironment aspnetcompatibilityenabled = "true">
<Serviceactivations>
<Add relativeaddress = "helloservice. SVC" service = "jquerywcfdemo. helloservice"
Factory = "system. servicemodel. Activation. webscriptservicehostfactory"/>
</Serviceactivations>
</Servicehostingenvironment>
</System. servicemodel>
System. servicemodel. Activation. webscriptservicehostfactory
In a hosting host environment where the service can be dynamically activated to respond to incoming messages, you can automatically add ASP. NET Ajax endpoints to the service without configuration.
Relativeaddress is the address name of the WCF Service, and the service is the helloservice class name created earlier. Factory is the key. It supports Ajax calling and relies on system. servicemodel. Activation. webscriptservicehostfactory.
Default. aspx
<SCRIPT type = "text/JavaScript">
Function submit_word (){
$. Ajaxsettings. url = 'helloservice. svc/write ';
$. Ajaxsettings. type = 'post ';
$. Ajaxsettings. datatype = 'json ';
$. Ajaxsettings. contenttype = 'application/json ';
$. Ajaxsettings. Data = '{"word": "Hello, word "}';
$. Ajaxsettings. Success = function (data ){
Alert (data. D );
};
$. Ajax ();
};
</SCRIPT>
<Input id = "showmsg" type = "button" value = "show" onclick = "submit_word ()"/>