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