我已經寫了一個服務,我想通過休息和肥皂公開。我所讀到的關於WCF 4.0的一切都表明,我只需要公開具有不同行爲的兩個端點來執行此操作。但我無法讓它工作。主持WCF肥皂和休息端點並排
這裏是我的服務合同:
[ServiceContract]
public interface MyService
{
[OperationContract]
[WebGet(UriTemplate="data/{value}")]
string GetData(string value);
}
這裏是我的web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="MyService">
<endpoint name="mex" address="mex" binding="mexHttpBinding" contract="MyService"/>
<endpoint address="rest" behaviorConfiguration="restBehavior" binding="webHttpBinding" contract="MyService" />
<endpoint address="soap" behaviorConfiguration="soapBehavior" binding="basicHttpBinding" contract="MyService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="restBehavior">
<webHttp automaticFormatSelectionEnabled="true" helpEnabled="true" />
</behavior>
<behavior name="soapBehavior" />
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
我使用的路由來定義我的服務網址:
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add(new ServiceRoute("dns", new ServiceHostFactory(), typeof(MyService)));
}
}
有我在這裏做錯了什麼?我真的可以用一些幫助。
我也發現這個其他[提問/回答(http://stackoverflow.com/questions/186631/rest-soap-endpoints-for-a-wcf - 服務)有幫助。 – SMB 2011-09-14 23:46:10