WCF RestサービスをIISに公開すると、問題が発生します。すべてVSで正常に機能しますが、IISを実行すると、不正な要求が発生し続けます。
いくつかのサンプルコード、私のサービスはこれと同じくらい簡単です:
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class Admin
{
[WebGet(UriTemplate = "Field/GetAll")]
public IList<EntityFields> GetFields() ...
global.asaxにルートを追加しました。
RouteTable.Routes.Add(new ServiceRoute("Admin", new WebServiceHostFactory(), typeof(Admin)));
そして、私のweb.configは次のようになります。私はこれが私が何か間違ったことをしているところだと思います。これは、ここやMSフォーラムなどを読んでから何度も変更され、変形していることに注意してください。
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule"
type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler"
preCondition="integratedMode"
verb="*"
path="UrlRouting.axd"
type="System.Web.HttpForbiddenHandler, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>
</system.webServer>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
それらが有用であるかどうかの注記:
- IIS 7.5
- Windows Server 2008 R2
- 私はAJAX呼び出しを介してJSONPを使用して多くのメソッドを呼び出しています。
- JSONPを使用しているため、JSONPを機能させる唯一の方法は、必要なすべてのメソッドをGETに変換し、ストリームを使用してコールバックを呼び出すことでした。
- Visual Studio経由で起動すると、すべて正常に動作します。IISでホストすると、問題が発生します。
どんな考えでも大歓迎です。