私WebScriptEnablingBehavior
の WCF REST サービスを利用して、javascript クライアント プロキシ (およびそれに付随する厳密に型指定されたオブジェクト) を生成する機能を提供したいと考えています。andメソッド (クエリ文字列として渡されるパラメーター)
で正常に動作しますが、 andで動作させるのに苦労しています。 GET
client.DownloadData()
POST
client.UploadData(...)
問題は、パラメーターがサービスメソッドで両方とも null になることです (エラー/例外はありません。問題なくデバッグできます...それらは null です)。
web.config
ファイル_
<services>
<service behaviorConfiguration="ServiceBehavior" name="ServWS_Main_2.WS_Main_2">
<endpoint address="" behaviorConfiguration="JSONOnly" binding="webHttpBinding"
bindingConfiguration="StreamedRequestWebBinding" contract="ServWS_Main_2.IServWS" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="JSONOnly">
<enableWebScript/>
</behavior>
</endpointBehaviors>
</behaviors>
サービス契約
[ServiceContract]
public interface IServWS
{
[OperationContract]
[WebInvoke(Method = "POST")]
ProviderInfo AddTo(string serviceName, BubbleInfo bubble);
}
実装
public class WS_Main_2 : IServWS
{
public ProviderInfo AddTo(string serviceName, BubbleInfo bubble)
{
// at this point both serviceName and bubble are null
}
}
パラメータとして渡される複合型の定義
[DataContract]
public class BubbleInfo
{
[DataMember(EmitDefaultValue = false)]
public string Text { get; set; }
[DataMember(EmitDefaultValue = false)]
public string Caption { get; set; }
}
お客様からのお電話
BubbleInfo bub = new BubbleInfo() { Text = "test2" };
MemoryStream stream = new MemoryStream();
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(BubbleInfo));
serializer.WriteObject(stream, bub);
var url = GetURL() + "/addto?serviceName=MyService";
byte[] data = client.UploadData(url, "POST", stream.ToArray());
WebScriptEnablingBehavior
but webHttp
andURITemplate
代わりに使用しなくても問題なく動作することに注意してください。
Visual Studio のビルトイン Web サーバーと IIS Express 7.5 でテスト済み。
ありがとう。