我在sharepoint中创建了一个托管服务
这是背后的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是很奇怪的,我应该将配置合并为一个吗?
答案 0 :(得分:1)
我找到了答案,因为我必须修改sharepoint的web.config,而不是在项目中创建一个。
在sharepoint的web.config中,我指定了端点
<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>
现在问题解决了
答案 1 :(得分:0)
将与端点中相同的值分配给Service Class / interface的ServiceContract属性的“Namespace”参数