1
単純なWCFサービスアプリケーションを作成し、クライアントブラウザから呼び出すことができるWCFコードを変更しようとしましたが、WCFクライアント。ブラウザからWCFメソッドを実行できない
ブラウザから実行しても、WCFサービスは呼び出されません(ブラウザでエラーメッセージは表示されません)。
コード:
契約:
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet]
string Test();
[OperationContract]
[WebGet]
string GetData(int value);
}
実装:
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
public string Test()
{
return "test success";
}
}
のWeb.config:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
プロジェクトURL:
http://localhost:1507/
ブラウザのURL行 - 試験方法:
http://localhost:1507/Service1.svc/Test
感謝。
「ブラウザから実行する」とはどういう意味ですか?何を実行? 'Test'は操作であり、URLではありません。 GETで呼び出すことはできません。これはWCFの制限ではなく、SOAPサービスの動作方法です。おそらくWebサービスとREST APIを混同していましたか? –
WCFサービスがlocalhostから実行されているため、ローカルブラウザから "http:// localhost:1507/Service1.svc/Test"という行を実行しました。 –
binding = "webHttpBinding"へのバインディングを変更しました。これはREST APIで実行されます。 –