简体   繁体   中英

500 Interval Server Error while accessing WCF service from http and Google Chrome Extension Simple REST Client

THis is the service which I created for Android device to post data but this service doesn't work for me. I called this service through an Android but nothing happens just received an error message of -500 in LogCat . I also check this service on HTTP and SIMPLE REST Client (Google Chrome Extension) but received an error message. Error message is given below. and this service is also published on IIS.

Error Message

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)

These are the params which im passing to the service:

{"mycar":{"Name":"a","Make":"gfgfd ","Model":"web "}}

and here is the service source code

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; 
    }

}

}

You need to add a JSON endpoint to your web.config file.

<system.serviceModel>
    <domainServices>
      <endpoints>
        <add name="JSON" type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

      </endpoints>
    </domainServices>

make sure to link to the assembly Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory in your project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM