我已从Visual Studio中的在线模板下载了WCFRestServiceWithKey模板。虽然WebGet方法工作正常,但WebInvoke方法根本不起作用。
例如:
[WebInvoke(UriTemplate = "/AddCustomer", Method = "POST", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)]
public Boolean AddCustomer(string firstname)
{
return true;
}
不允许简单调用此方法返回方法。我认为这可能与clientaccesspolicy.xml有关,但无论我做什么,我都无法理解。
这是我的clientaccesspolicy.xml:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
我没有触摸web.config,因为它配置了模板文件。
任何人都有任何想法?
我从Silverlight中调用这样的服务:
http://localhost:6423/PredraWebservice/AddCustomer?apikey=bda11d91-7ade-4da1-855d-24adfe39d174
我称之为:
String send = "<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">String content</string>";
Uri url = new Uri("http://localhost:6423/PredraWebservice/AddCustomer?apikey=bda11d91-7ade-4da1-855d-24adfe39d174", UriKind.Absolute);
WebClient client = new WebClient();
client.UploadStringCompleted += new UploadStringCompletedEventHandler(client_UploadStringCompleted);
client.UploadStringAsync(url, send);