Reputation: 4919
I created a service to be host in sharepoint
Here's the svc code behind:
[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";
}
}
Here's the interface
[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);
}
And here's the web.config of the svc:
<?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>
Here's the app.config file:
<?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>
When I tried accessing the svc through the browser in this link www.mySharepoint.com/_vti_bin/MyService.svc/GetAllItems/1
, the below error occurs:
The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).
What is the problem?
I think it's weird to have app.config and web.config at the same time, should I merge the config into one?
Upvotes: 0
Views: 8480
Reputation: 4919
I found the answer, I was because I have to modify the sharepoint's web.config instead of creating one in the project.
In the sharepoint's web.config, I specified the endpoint
<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>
Now the problem is solved
Upvotes: 1
Reputation: 43
Assign the same value as in endpoint to the "Namespace" parameter of ServiceContract attribute of the Service Class/interface
Upvotes: 0