2011-03-25 13 views
2

ローカルではすべて正常に動作しますが、サーバーにwcfデータサービスをデプロイすると、レスポンスはatom + xmlになります。何か不足していますか? web.configファイルjquery wcfデータサービスは、jsonの代わりにatom + xmlを返します

<system.web> 
    <compilation debug="false" targetFramework="4.0" /> 

<authentication mode="None"/> 

</system.web> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
    </modules> 
</system.webServer> 
<system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
    <standardEndpoints> 
     <webHttpEndpoint> 
      <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" crossDomainScriptAccessEnabled="true" /> 
     </webHttpEndpoint> 
    </standardEndpoints> 

</system.serviceModel> 

シオマネキ

 HTTP/1.1 200 OK 
Cache-Control: no-cache 
Content-Length: 13483 
Content-Type: application/atom+xml;charset=utf-8 
Server: Microsoft-IIS/7.5 
DataServiceVersion: 2.0; 
X-AspNet-Version: 4.0.30319 
X-Powered-By: ASP.NET 
Date: Fri, 25 Mar 2011 17:46:37 GMT 

<?xml version="1.0" encoding="utf-8" standalone="yes"?> 
<feed xml:base="http://subdomain.domain.com/wcfdataservice.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom"> 
... 

答えて

2

WCF

jqueryの

 $(function() { 
       $.ajax({      
        contentType: "application/json; charset=utf-8", 
        url: "http://subdomain.domain.com/wcfdataservice.svc/surveys/", 
        dataType: "jsonp", 
        success: function (data, textStatus) { 

        }, 
        error: function (data, textStatus) { 

        } 
       });  

     }); 

私はパブロ・カストロのanswerこの質問には、あなたが探している解決策だと思います。

基本的には、リクエストに「application/json」の「accept」ヘッダーを指定する必要があります。また、オプションでサービスの[JSONPSupportBehavior]属性を使用することもできます。私はあなたが両端を制御しているので、受け入れヘッダが必要なものだと思います。

EDIT:あなたはフィドラーで、調べてみると、あなたの要求とあなたは「受け入れる]ヘッダが設定されているか、正しく設定されていない、あなたがこの記事では、この技術を使用することができるかもしれ表示されません。

http://snipplr.com/view/9869/set-jquery-ajax-header/

0

これはWCF WebApi(プレビュー6)を使用する方がずっと簡単です。 NuGetを使用してWCF WebApiをインストールする必要がありますが、それだけの価値があります。インストールが完了したら、hereを参照してください。

関連する問題