私は、WCFサービス契約があります。POSTメソッドが機能しないのはなぜですか?
[ServiceContract]
public interface IVLSContentService
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "GetCategoriesGET/{userIdArg}", BodyStyle = WebMessageBodyStyle.Bare)]
List<Video> GetVideosGET(string userIdArg);
[WebInvoke(Method = "POST",BodyStyle=WebMessageBodyStyle.Wrapped, UriTemplate = "submit")]
[OperationContract]
void SubmitVideoPOST(Video videoArg, string userId);
}
をそして私は契約実装するサービスがあります。
public class VLSContentService : IVLSContentService
{
List<Video> catsForUser1 = new List<Video>();
List<Video> catsForUser2 = new List<Video>();
public List<Video> GetVideosGET(string userIdArg)
{
List<Video> catsToReturn = new List<Video>();
if (Int32.Parse(userIdArg) == 1)
{
catsToReturn = catsForUser1;
}
else if (Int32.Parse(userIdArg) == 2)
{
catsToReturn = catsForUser2;
}
return catsToReturn;
}
public void SubmitVideoPOST(Video videoArg, string userId)
{
int i = 0;
}
}
を私は設定があります。
<system.serviceModel>
<services>
<service behaviorConfiguration="VLSContentServiceBehaviour" name="VLSContentService">
<endpoint address="" behaviorConfiguration="VLSContentServiceEndpointBehaviour" binding="webHttpBinding" contract="IVLSContentService"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="VLSContentServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="VLSContentServiceEndpointBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
をそして私がしようとしています次のクライアントコードを使用してPOST WCF操作を呼び出します。
static void Main(string[] args)
{
WebChannelFactory<IVLSContentService> cs = new WebChannelFactory<IVLSContentService>(new Uri("http://localhost:52587/Api/Content/VLSContentService.svc/SubmitVideoPOST"));
IVLSContentService client = cs.CreateChannel();
Video videoToAdd = new Video("My First Video");
client.SubmitVideoPOST(videoToAdd,"1");
}
しかし、イムこのエラーを取得し、私がなぜうまくカント:
メッセージを受け入れることができる http://localhost:52587/Api/Content/VLSContentService.svc/SubmitVideoPOST/submit で聞いて何のエンドポイントがありませんでした。これはよく です。間違ったアドレス またはSOAPアクションによって引き起こされることがよくあります。詳細については、 が存在する場合はInnerExceptionを参照してください。
URLでGETメソッドを参照すると、正しいパラメータが渡されます。xmlが戻ってきていますが、POSTメソッドがうまく動作しません。 Iveはpluralsightからの例をコピーしました。唯一の違いはサービスホストアプリケーションの代わりに.svcファイルでサービスをホストしようとしていることです...
誰かが正しい方向に私を向けることができますか?
クライアントのapp.configに何か問題がありますか?あなたはその1つを掲示しなかった –