将 RIA 服务公开为 SOAP、Json 等时出现问题
我正在尝试使用 SOAP 和 JSON 公开现有的 RIA 服务。
在 web.config 的 serviceModel 部分中,我放置了:
<system.serviceModel>
<domainServices>
<endpoints>
<add name="OData" type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="Soap" type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="Json" type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</endpoints>
</domainServices>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
在 MyDomainService 中有:
[Query(IsDefault=true)]
public IEnumerable<UserItem> GetUsers()
{
return this.ObjectContext.Users;
}
我尝试过以下 URL:
http://10.0.0.191:27070/Manager-Web-MyDomainService。 svc/GetUsers
http://10.0.0.191:27070/Manager-Web- MyDomainService.svc/Soap/GetUsers
http://10.0.0.191:27070/Manager-Web- MyDomainService.svc/Json/GetUsers
http://10.0.0.191:27070/Manager-Web- MyDomainService.svc/OData/GetUsers
我只得到空白页面。
我已启用跟踪,并在日志中看到警告“未找到配置评估上下文”。
有人可以帮我解决这个问题吗?
提前致谢, 干杯, 吉安卢卡.
I'm trying to expose an existing RIA service with SOAP and JSON.
In the web.config, serviceModel section, I've put:
<system.serviceModel>
<domainServices>
<endpoints>
<add name="OData" type="System.ServiceModel.DomainServices.Hosting.ODataEndpointFactory, System.ServiceModel.DomainServices.Hosting.OData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="Soap" type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="Json" type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</endpoints>
</domainServices>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
In MyDomainService there is:
[Query(IsDefault=true)]
public IEnumerable<UserItem> GetUsers()
{
return this.ObjectContext.Users;
}
I've tried the following URLs:
http://10.0.0.191:27070/Manager-Web-MyDomainService.svc/GetUsers
http://10.0.0.191:27070/Manager-Web-MyDomainService.svc/Soap/GetUsers
http://10.0.0.191:27070/Manager-Web-MyDomainService.svc/Json/GetUsers
http://10.0.0.191:27070/Manager-Web-MyDomainService.svc/OData/GetUsers
and I get just blank pages.
I've enabled tracing and in the log I see the warning "Configuration evaluation context not found".
Anybody who can help me with this?
Thanks in advance,
Cheers,
Gianluca.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我已经整理了几乎所有内容。我的配置是正确的。问题出在其他地方。让我分享一下我的发现:
首先,我发现 OData 需要在 URL 末尾添加“/”。另外,我错误地认为有必要调用末尾带有方法名称的服务 URL。类似于:http:///oData/。事实证明,通过调用 http:///oData/ 我就获得了所有预期的数据。
相反,Json 不想要尾随的“/”。正确的 URL 类似于:http:///Json/。这次有必要指出方法。我也开始更好地理解 Query、Invoke 等属性的含义。仅当 INVOKE 修饰的方法具有 HasSideEffect=false 属性时,该方法才会以 JSON 形式公开。
我仍然无法通过 SOAP 公开相同的方法。如果有人想贡献并帮助我,请随时在此处添加更多信息。一旦得到进一步的结果,我会发布更多信息。
干杯,
吉安卢卡.
Ok, I've sorted out almost everything. My configuration was correct. Problems were elsewhere. Let me share my findings:
First of all, I've found out that OData requires a '/' at the end of the URL. Also, I was wrongly thinking that it is necessary to recall the service URL with at the end the name of the method. Something like: http:///oData/. It turned out that by calling just http:///oData/ I was getting all the expected data.
At the contrary, Json does not want the trailing '/'. A correct URL is like: http:///Json/. This time it's been necessary to indicate the method. I'm also starting to understand better the meaning of the attributes Query, Invoke, etc. An INVOKE-decorated method is exposed as JSON only if it has the property HasSideEffect=false.
I am still having trouble exposing the same methods via SOAP. If someone wants to contribute and help me out, please feel free to add more info here. I'll post more information as soon as I get further results.
Cheers,
Gianluca.