【发布时间】:2014-02-08 09:06:57
【问题描述】:
这是我为 Android 设备创建的用于发布数据的服务,但该服务对我不起作用。我通过 Android 调用了该服务,但没有任何反应,只是在 LogCat 中收到 -500 的错误消息。我还在 HTTP 和 SIMPLE REST Client(Google Chrome 扩展程序)上检查了此服务,但收到了一条错误消息。错误信息如下。而且这个服务也在IIS上发布。
错误信息
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)
这些是我传递给服务的参数:
{"mycar":{"Name":"a","Make":"gfgfd ","Model":"web "}}
这里是服务源代码
namespace CarSercive
{
[ServiceBehavior(AddressFilterMode=AddressFilterMode.Any)]
public class Service1 : IService1
{
// myCar test = new myCar();
public void UpdateMyCar(myCar mycar) {
string strConnectionString = ConfigurationManager.ConnectionStrings["Database1"].ConnectionString;
SqlConnection conn = new SqlConnection(strConnectionString);
conn.Open();
using (SqlCommand cmd = new SqlCommand("Insert into TestingTable (Name,Make,Model) Values (@Name,@Make,@Model)", conn)) {
cmd.Parameters.AddWithValue("@Name", mycar.Name);
cmd.Parameters.AddWithValue("@Make", mycar.Make);
cmd.Parameters.AddWithValue("@Model", mycar.Model);
int queryResult = cmd.ExecuteNonQuery();
} conn.Close();
}
}
}
web.config
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<compilation debug="true" targetFramework="4.0">
</compilation>
<authentication mode="Windows"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/></system.web>
<system.serviceModel>
<services>
<service name="CarSercive.Service1" behaviorConfiguration="web">
<!-- Service Endpoints -->
<endpoint address="" binding="webHttpBinding" contract="CarSercive.IService1"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="web">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
IService1.cs
namespace CarSercive
{
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebInvoke(
Method = "POST",
UriTemplate = "MyCar",
//BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
void UpdateMyCar(myCar mycar);
}
[DataContract]
public class myCar
{
[DataMember(Name = "Name")]
public string Name
{
get;
set;
}
[DataMember(Name="Model")]
public string Model
{
get;
set;
}
[DataMember(Name="Make")]
public string Make
{
get;
set;
}
}
}
【问题讨论】:
标签: c# android wcf web-services wcf-rest