【发布时间】:2016-09-25 15:26:32
【问题描述】:
我创建了一个服务作为共享点的主机
下面是 svc 代码:
[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService: IMyService
{
public bool AddNewItem(string id, string msg)
{
return true;
}
public string GetAllItems(string id)
{
return "test";
}
}
界面如下
[ServiceContract]
interface IMyService
{
[OperationContract]
[WebGet(UriTemplate = "/GetAllItems/{id}",
ResponseFormat = WebMessageFormat.Json)]
string GetAllItems(string id);
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "/AddNewItem",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
bool AddNewItem(string id, string msg);
}
这是 svc 的 web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="MyService.ISAPI.ServiceBehaviour" name ="MyService.MyService">
<endpoint address="" binding="webHttpBinding"
contract="MyService.ISAPI.IMyService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name ="MyService.ISAPI.ServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
这是 app.config 文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="MyService.MyService">
<endpoint address="" binding="webHttpBinding" contract="MyService.ISAPI.IMyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/MyService/MyService/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
当我尝试通过此链接www.mySharepoint.com/_vti_bin/MyService.svc/GetAllItems/1中的浏览器访问svc时,出现以下错误:
接收方无法处理带有 Action '' 的消息,因为 EndpointDispatcher 的 ContractFilter 不匹配。这可能是 因为合同不匹配(不匹配的操作之间 发送方和接收方)或发送方之间的绑定/安全不匹配 和接收器。检查发送方和接收方是否相同 合同和相同的约束力(包括安全要求,例如 消息,传输,无)。
有什么问题?
我觉得同时拥有 app.config 和 web.config 很奇怪,我应该将配置合并为一个吗?
【问题讨论】:
标签: c# wcf sharepoint sharepoint-2013