0
我已經設置與我的配置文件設置如下返回JSON格式數據的WCF服務:道場Web應用程序請求WCF服務
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingJsonP" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="webHttpBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="webHttpBehavior" name="Services.Service1">
<endpoint address="mex"
binding="webHttpBinding" bindingConfiguration="webHttpBindingJsonP"
contract="Services.IService1" behaviorConfiguration="webHttpBehavior"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
我的服務WebInvoke功能:
<OperationContract()>
<WebInvoke(Method:="GET", BodyStyle:=WebMessageBodyStyle.WrappedRequest, Responseformat:=WebMessageFormat.Json)>
Function RetrieveData(ByVal screenName As String) As Stream
最後我基於dojo的網站的功能調用web服務:
<script type="text/javascript">
dojo.ready(function() {
dojo.io.script.get({ url:
"http://xxx.xxx.x.xxx/Services/Service/Service1.svc/GetData?item=Tweet",
callbackParamName: "callback",
content: { username: "me", password: "you" }
}).then(function (data){
return data.results;
})
});
</script>
問題是,我不能讓數據流向dojo應用程序。首先,我得到未定義的錯誤回調。現在我不確定在這個回調函數中我是否清楚:它是dojo應用程序中函數的名稱,就像我上面的那樣,但函數沒有被命名,或者它是函數的名稱,返回的是json響應Web服務順便安裝在不同的域上。
感謝您的迴應。但xhr不適用於跨域服務器應用程序 – user1585245 2012-08-09 17:05:23
請參閱此鏈接http://dojo-toolkit.33424.n3.nabble.com/Cross-domain-XMLHttpRequest-with-Dojo-td1864416.html並查看Kris Zyp's響應。 – eburgos 2012-08-10 13:40:54