我在 IIS 7 上托管我的 WCF 服务,即使它在使用 WCF 测试客户端时工作正常,但我无法从简单的控制台应用程序使用我的服务。
我已经允许在我的 IIS 上处理 .svc 和 .wsdl 文件。我不确定我还缺少什么。
这是我的代码:
namespace EvalServiceLibrary {
[ServiceContract]
public interface IEvalService {
[OperationContract]
void SubmitEval(Eval eval);
[OperationContract]
List<Eval> GetEvals();
[OperationContract]
void RemoveEval(String id);
}
}
namespace EvalServiceLibrary {
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class EvalService : IEvalService {
#region
List<Eval> evals = new List<Eval>();
public void SubmitEval(Eval eval) {
eval.Id = Guid.NewGuid().ToString();
evals.Add(eval);
}
public List<Eval> GetEvals() {
return evals;
}
public void RemoveEval(String id) {
evals.Remove(evals.Find(e => e.Id.Equals(id)));
}
#endregion
}
}
还有我的 web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<services>
<service name="EvalServiceLibrary.EvalService">
<endpoint address="http://localhost/WebEvalService" binding="basicHttpBinding"
bindingConfiguration="" name="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
这是我的客户代码:
static void Main(string[] args) {
EvalServiceClient client = new EvalServiceClient();
client.SubmitEval(new Eval() { Comments = "Lorem Ipsum", Submitter = "egarcia", TimeSubmitted = DateTime.Now });
List<Eval> evalList = client.GetEvals().ToList();
foreach(var eval in evalList) {
Console.WriteLine(eval.Id);
}
client.Close();
}
我也可以在本地 IIS 上访问该服务。