嘿,这是我的Web.config文件。除Service1 / help外,一切都适用于我的服务。
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add
name="UrlRoutingHandler"
preCondition="integratedMode"
verb="*" path="UrlRouting.axd"
type="System.Web.HttpForbiddenHandler, System.Web, 
 Version=2.0.0.0, Culture=neutral, 
 PublicKeyToken=b03f5f7f11d50a3a"
/>
</handlers>
</system.webServer>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="SSLBinding">
<security mode="Transport">
<transport clientCredentialType="Certificate" proxyCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="sBehavior">
<routing routeOnHeadersOnly="true" />
<serviceMetadata httpsGetEnabled="true" httpsGetBinding="webHttpBinding" httpsGetBindingConfiguration="" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="Default" helpEnabled="true" automaticFormatSelectionEnabled="true">
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
</security>
</standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
</system.serviceModel>
</configuration>
服务:
namespace UserWebServices
{
// Start the service and browse to http://<machine_name>:<port>/Service1/help to view the service's generated help page
// NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
// a single instance of the service to process all calls.
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
// NOTE: If the service is renamed, remember to update the global.asax.cs file
public class Service1
{
// TODO: Implement the collection resource that will contain the SampleItem instances
[WebGet(UriTemplate = "")]
public List<SampleItem> GetCollection()
{
// TODO: Replace the current implementation to return a collection of SampleItem instances
return new List<SampleItem>() { new SampleItem() { Id = 1, StringValue = "Kader" },
new SampleItem() { Id = 2, StringValue = "Weber" }};
}
[WebGet(UriTemplate = "{id}")]
public SampleItem Get(string id)
{
int idConverted = Convert.ToInt32(id);
return new SampleItem() { Id = idConverted, StringValue = "SingleItem" };
}
[WebInvoke(UriTemplate = "", Method = "POST")]
public SampleItem Create(SampleItem instance)
{
if (instance == null)
throw new NoNullAllowedException();
return instance;
}
[WebInvoke(UriTemplate = "{id}", Method = "PUT")]
public SampleItem Update(string id, SampleItem instance)
{
int idConverted = Convert.ToInt32(id);
return new SampleItem() { Id = idConverted, StringValue = "Putted" };
}
[WebInvoke(UriTemplate = "{id}", Method = "DELETE")]
public void Delete(string id)
{
// TODO: Remove the instance of SampleItem with the given id from the collection
throw new NotImplementedException();
}
}
}
答案 0 :(得分:0)
启用跟踪,这将有助于识别使用WCF时遇到的任何可能的问题。请参阅http://msdn.microsoft.com/en-us/library/ms733025.aspx。
另外,使用:\ Program Files \ Microsoft SDKs \ Windows \ v6.0A \ Bin \ SvcTraceViewer.exe。