ASP.NETでRESTサーバーを作成しましたが、サービスを呼び出すためのURLがわかりません。私はそれがWebサーバーに組み込まれているVS 2010の下で実行されています。私はそれが実際に実行されていると信じています(VS 2010は正常に起動します)。しかし、私がURLのために考えることができるすべての組み合わせは、それをもたらすものではありません。ASP.NETでRESTサービスを実行しようとしています
更新:ファイルhttp://www.windward.net/temp/RestUnderAspDotNet.zipを見てください。そこには2つの解決策があります。 src \ updateにあるものは、RESTサーバーとして正常に動作します。私はinetpub \ wwwroot \ updateでほとんど同じコードを持っていますが、実行中はそのURLにアクセスできません。私はhttp://localhost:56469/update/App_Code/RestServiceImpl.svc/testのすべてのバリエーションを試してみました。私は403や404のいずれかを考えて取得することができました。
なぜか? (私はこの上の任意のセキュリティはしたくない - それは最高だ後、誰もがそれを打つことができるようになります。)
にApp_Code \ IRestServiceImpl.cs:
[ServiceContract]
public interface IRestServiceImpl
{
[OperationContract]
[WebInvoke(UriTemplate = "/version", Method = "POST")]
XmlElement GetVersion(XmlElement stats);
[OperationContract]
[WebInvoke(UriTemplate = "/test", Method = "GET")]
string GetTest();
}
にApp_Code \ RestServiceImpl.svc:
<%@ ServiceHost Language="C#" Debug="true" Service="RestServiceImpl" CodeBehind="RestServiceImpl.svc.cs" %>
にApp_Code \ RestServiceImpl.cs:
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Xml;
[AspNetCompatibilityRequirements
(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class RestServiceImpl : IRestServiceImpl
{
public XmlElement GetVersion(XmlElement stats)
{
XmlDocument doc = new XmlDocument();
XmlElement root = doc.CreateElement("update");
root.SetAttribute("version", "11.0.13.0");
doc.AppendChild(root);
return doc.DocumentElement;
}
public string GetTest()
{
return "update server is running";
}
}
web.configファイルの関連部分:
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="RestServiceImpl">
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address ="" binding="webHttpBinding" contract="IRestServiceImpl" behaviorConfiguration="webBinding">
</endpoint>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="RestServiceImpl">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="webBinding">
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
/テストGETを行うためのURLは何ですか?
感謝 - デイブ
またはローカルホスト:ポート/にApp_Code/blah.svc /テスト –
両方のhttp:// localhostを:56469 /更新/ RestServiceImpl.svc /テスト(ウェブサイトが更新され)て、http:// localhostを:56469/RestServiceImpl .svc/testは404エラーを返します。私はどのようにURLを追跡する必要があります上の任意の提案? –
プロジェクトの作成ウィザードがコードをApp_Codeの下に置き、IISがそのフォルダ内のコードの直接呼び出しを許可しないという問題が出ています。 –