次のように、構成ファイルのセットアップでjson形式のデータを返す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
そして最後に、ウェブサービスを呼び出すための私の道場ベースのウェブサイトの機能:
<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 アプリケーションにデータを流すことができないことです。まず、未定義のエラー コールバックを取得します。今、私はこのコールバックのことについて明確であるかどうか確信が持てません: それは私が上に持っている道場アプリケーションの関数の名前ですか、関数は名前が付けられていませんか、それとも json 応答を返す関数の名前ですか?ちなみに別のドメインにインストールされているWebサービス。