我是 WCF 的新手,正在尝试启动并运行它。我什至不能得到一个没有任何错误的空白版本。
网络配置:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="ServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
<!--wcf-->
<behavior name="recordsWCF">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="recordsSWCF" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<!--end wcf-->
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<!--wcf-->
<service name="records.wcf" behaviorConfiguration="recordsSWCF" >
<!--<endpoint address="" binding="webHttpBinding" contract="IService" behaviorConfiguration="recordsWCF"/>-->
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
<!--end wcf-->
<service name="Service">
<endpoint address="" behaviorConfiguration="ServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="Service" />
</service>
</services>
</system.serviceModel>
就我的 wcf 代码而言,目前还没有什么可做的。我只是想学习如何设置 web.config 而不会出现任何错误。这是我的 wcf 定义:
[ServiceContract(Namespace = "records")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class wcf
{
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
[OperationContract]
[WebGet]
public string GetData()
{
Person p = new Person();
List<Person> test = new List<Person>();
p.Name = "Tom";
p.Age = 28;
test.Add(p);
p = new Person();
p.Name = "Dan";
p.Age = 22;
test.Add(p);
JavaScriptSerializer js = new JavaScriptSerializer();
string jsonString = js.Serialize(test);
return jsonString;
}
}