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