我是RESTful WCF服务的新手,所以请耐心等待.我正在尝试构建一个简单的RESTful WCF服务,该服务返回一个学生列表作为json响应.一切正常,直到我尝试将json字符串转换回客户端上的Student对象列表.
这是我的运营合同:
[OperationContract]
[WebGet(UriTemplate = "Students/", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
public List<Student> FetchStudents()
{
//Fetch and return students list
}
Run Code Online (Sandbox Code Playgroud)
客户代码:
static void Main(string[] args)
{
HttpClient client = new HttpClient("http://localhost/StudentManagementService/StudentManagement.svc/");
response = client.Get("Students/");
response.EnsureStatusIsSuccessful();
JavaScriptSerializer json_serializer = new JavaScriptSerializer();
string str = response.Content.ReadAsString();
List<Student> st = json_serializer.Deserialize<List<Student>>(str);
}
Run Code Online (Sandbox Code Playgroud)
此代码显然失败,因为服务返回的json字符串如下所示:
{"FetchStudentsResult":[{"Course":"BE","Department":"IS","EmailID":"b@gmail.com","ID":1,"Name":"Vinod"}]}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,json响应被包装在FetchStudentsResult中.现在处于调试模式,如果我强行删除这个FetchStudentsResult包装,我的反序列化工作完全正常.
我试过DataContractJsonSerializer但结果完全一样.有人能告诉我我错过了什么吗?
我有一个测试数据库,其中1个表有大约5000万条记录.该表最初有50列.该表没有索引.当我执行"sp_spaceused"过程时,我得到"24733.88 MB".现在为了减小这个数据库的大小,我删除了15列(主要是int列)并运行"sp_spaceused",结果我仍然得到"24733.88 MB".
删除这么多列后,为什么数据库大小没有减少?我在这里错过了什么吗?
编辑:我已经尝试过数据库收缩,但它也没有帮助
我正在尝试使用一个.aspx,.asmx和.svc文件来托管一个简单的应用程序.我按照下面的指南来实现托管(因为我是linux世界的新手,需要一段时间来理解它!):
http://www.mono-project.com/Mod_mono#Manual_Mod_Mono_Configuration
完成所有托管后,我可以访问aspx和asmx文件.但是当我尝试访问svc文件时,我收到以下错误:
ServiceHost必须至少有一个由配置,行为或对AddServiceEndpoint方法的调用定义的应用程序端点(不包括元数据交换端点).
要么
HttpListenerContext与任何已注册的频道都不匹配
我在web.config中定义了一个非常简单的服务端点,如下所示:
<system.serviceModel>
<services>
<service name="TestWCFService">
<endpoint address="http://localhost/MonoTest/TestWCFService.svc" binding="basicHttpBinding"
contract="MonoTest.ITestWCFService"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
Run Code Online (Sandbox Code Playgroud)
你能告诉我我做错了什么吗?
注意:我使用MS VS 2010创建此项目,然后发布它.已发布的目录将复制到Apache/Linux环境中.WCF不使用任何复杂类型.我使用的是Mono版本2.8.2
更新 更新:我尝试使用2.10.2 Mono.这个错误消失了,我现在面临一个新错误:
XmlSchema error: Named item http://tempuri.org/:DoWork was already contained in the schema object table. Consider setting MONO_STRICT_MS_COMPLIANT to 'yes' to mimic MS implementation. Related schema item SourceUri: , Line 0, Position 0.
Run Code Online (Sandbox Code Playgroud)