我想構建一個公開基本HTTP端點和WebHTTP端點的服務。如果我在運行模式下用VS2010測試下面的項目,一切都很好;但我想在IIS(本地或遠程)託管服務並通過測試。在IIS上託管的WCF服務不起作用
Service.svc:
<%@ ServiceHost Language="C#" Debug="true" Service="ContactLibrary.ContactLibraryService"%>
我主持我的網站到本地IIS。當我嘗試:http://localhost/ContactLibrary2.0/Service.svc我得到:
類型「ContactLibrary.ContactLibraryService」,作爲服務提供了ServiceHost的指令屬性值,或在配置元素system.serviceModel/serviceHostingEnvironment/serviceActivations提供找不到。
Web.config文件看起來像:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="ContactLibraryNamespace.ContactLibraryService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
name="soap" contract="ContactLibraryNamespace.IContact" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
name="mex" contract="IMetadataExchange" />
<endpoint address="rest" behaviorConfiguration="web" binding="webHttpBinding"
bindingConfiguration="" name="rest" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/ContactLibrary2.0" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
IContact接口的樣子:
[ServiceContract]
public interface IContact
{
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "GetContact/{idContact}", ResponseFormat = WebMessageFormat.Json)]
Contact GetContact(string idContact);
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "AddContact", RequestFormat = WebMessageFormat.Json)]
string AddContact(Contact contact);
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "EditContact", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
string EditContact(string idContact, Contact Contact);
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "DeleteContact", RequestFormat = WebMessageFormat.Json)]
string DeleteContact(string idContact);
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "GetAllContacts/{start}/{end}", RequestFormat = WebMessageFormat.Json)]
List<Contact> GetAllContacts(string start, string end);
}
你可以發佈你的IContact接口嗎? – 2012-03-28 07:59:36
一切看起來不錯。但是我沒有看到ContactLibraryJSONService的端點。你有沒有定義這樣的端點?如果不是,則應添加它。 – paramosh 2012-03-28 08:29:16
我沒有添加一個,因爲我想看到這部分工作。我想看看我的服務對WCFStorm有反應。 – 2012-03-28 08:32:14