‘WCF’ カテゴリーのアーカイブ

WCFを使ってXML-RPC通信を行うには

2010年6月10日 木曜日

Xml-Rpc With WCFから「XML-RPC for WCF」をダウンロード。

上記blogのコメントに従ってXmlRpcDataContractSerializationHelperクラスのDeserializeStructメソッドのループ           

while (reader.NodeType != XmlNodeType.EndElement)
 {

の最後に、下記を追加。(ホワイトスペースと改行(XmlNodeType.Text)をスキップするため)

while (reader.NodeType == XmlNodeType.Whitespace || reader.NodeType == XmlNodeType.Text)
 {
            reader.Skip();
 }

また、Desirializeメソッドでswitch (reader.LocalName)の case XmlRpcProtocol.DateTime:の日付の形式が、dateTime.iso8601の形式(下記例参照)でなかったため修正。

<dateTime.iso8601>19980717T14:08:55</dateTime.iso8601>

また、Desirializeメソッドで<value>の内側に型のタグがない場合stringにする処理がなかったため、メソッドの一番最後に

 else if (reader.NodeType == XmlNodeType.Text)
{
        returnValue = reader.ReadString(); 
}

を追加した。このモジュールの使う手順は下記。

  • 参照にMicrosoft.Samples.XmlRpcを追加。
  • 普通のWCFと同じようにServiceContract, OperationContract属性を追加したインターフェースを定義する。ただし、OperationContractは[OperationContract(Action = "metaWeblog.newPost")]のようにActionにXML-RPCのメソッド名を追加する。また、XML-RPCのstruct型の定義はWCF側ではクラスとして定義し、DataContract, DataMember属性を追加する。
  • Web.configのsystem.serviceModelセクションを下記のように定義する。

<system.serviceModel>
   <extensions>
     <behaviorExtensions>
       <add name=”xmlRpcEndpointBehavior”
            type=”Microsoft.Samples.XmlRpc.XmlRpcEndpointBehaviorSection, Microsoft.Samples.XmlRpc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null” />
     </behaviorExtensions>
   </extensions>
   <services>
     <service behaviorConfiguration=”debugBehavior” name=”実装したクラス名”>
       <host>
       </host>
       <endpoint address=”" behaviorConfiguration=”xmlRpcBehavior” binding=”webHttpBinding”
         contract=”定義したインタフェース名” />
     </service>
   </services>
   <behaviors>
     <endpointBehaviors>
       <behavior name=”xmlRpcBehavior”>
         <xmlRpcEndpointBehavior />
       </behavior>
     </endpointBehaviors>
     <serviceBehaviors>
       <behavior name=”debugBehavior”>
         <serviceMetadata httpGetEnabled=”true” />
         <serviceDebug includeExceptionDetailInFaults=”true” />
       </behavior>
     </serviceBehaviors>
   </behaviors>
   <serviceHostingEnvironment multipleSiteBindingsEnabled=”true” />
 </system.serviceModel>

ADO.NET Data Services でJSON形式でデータを受信するには

2009年9月1日 火曜日

JSONを取得する際、HTTPヘッダに下記を付加する。

Accept: application/json