掲題のとおりです。
【環境】
Visual Studio 2015
IIs8.0
Webブラウザにて下記を入力してサービスを呼んだところ添付した画像のような画面が表示されます。
http://localhost:ポート/~~/サービス名(POST)
いろいろ調べたところIISの設定で治せるという旨の記事が多々あり、参考にしてみたのですがダメでした。
というより、IISを直したとしてlocalhostで表示されるようになるだけであってアプリケーションをサーバにアップしたらまたエラーが発生しそうです。
なのでWeb.configによる解決が一番なのではないかと思います。
以下コードです。
Method="Get"のものは普通に動きます。GetをPostに変更するとやはり上記画像と同じものが表示されてしまいます。
◆IService1.cs
C#
1using System; 2using System.Collections.Generic; 3using System.Linq; 4using System.Runtime.Serialization; 5using System.ServiceModel; 6using System.ServiceModel.Web; 7using System.Text; 8 9namespace PjStatusApplication 10{ 11 [ServiceContract] 12 public interface IService1 13 { 14 [OperationContract] 15 [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "Greeting/{name}")] 16 string Greeting(string name); 17 } 18 19 [ServiceContract] 20 public interface ICreateTextService1 21 { 22 [OperationContract] 23 [WebInvoke(Method = "POST", 24 BodyStyle = WebMessageBodyStyle.Wrapped, 25 ResponseFormat = WebMessageFormat.Json, 26 UriTemplate = "CreateTextGreeting")] 27 string CreateTextGreeting(string name); 28 } 29} 30
◆web.config
XML
1<?xml version="1.0" encoding="utf-8"?> 2<configuration> 3 4 <system.web> 5 <compilation debug="true" targetFramework="4.0" /> 6 </system.web> 7 <system.serviceModel> 8 <behaviors> 9 <serviceBehaviors> 10 <behavior> 11 <!-- メタデータ情報の開示を避けるには、展開する前に、下の値を false に設定し、上のメタデータのエンドポイントを削除します --> 12 <serviceMetadata httpGetEnabled="true"/> 13 <!-- デバッグ目的で障害発生時の例外の詳細を受け取るには、下の値を true に設定します。例外情報の開示を避けるには、展開する前に false に設定します --> 14 <serviceDebug includeExceptionDetailInFaults="false"/> 15 </behavior> 16 </serviceBehaviors> 17 </behaviors> 18 <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /> 19 </system.serviceModel> 20 <system.webServer> 21 <modules runAllManagedModulesForAllRequests="true"/> 22 </system.webServer> 23 24</configuration>
あなたの回答
tips
プレビュー