Visual Studio のオンライン テンプレートから WCFRestServiceWithKey テンプレートをダウンロードしました。WebGet メソッドは正常に機能しますが、WebInvoke メソッドはまったく機能しません。
例えば:
[WebInvoke(UriTemplate = "/AddCustomer", Method = "POST", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml)]
public Boolean AddCustomer(string firstname)
{
return true;
}
このメソッド return メソッドへの単純な呼び出しは許可されていません。これは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);