繁体   English   中英

从http和Google Chrome扩展程序简单REST客户端访问WCF服务时出现500间隔服务器错误

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

这是我为Android设备创建的用于发布数据的服务,但该服务不适用于我。 我通过Android调用了此服务,但在LogCat中仅收到-500的错误消息没有任何反应。 我还在HTTPSIMPLE 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; 
    }

}

}

您需要将JSON端点添加到web.config文件中。

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

确保链接到项目中的程序集Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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