これは私のWCF契約です:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "{type}/sports")]
List<SportsList> GetSportsList(string type);
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "{type}/sports/{sport}/championships")]
ChampsCountries GetChampsBySport(string type, string sport);
WPFアプリケーションから呼び出そうとすると:
Service1Client client = new Service1Client();
SportsList[] sports = client.GetSportsList("line");
ご覧のとおり、私は最初の契約を呼び出していますが、2番目の契約に関してエラーが発生します。
Operation 'GetChampsBySport' of contract 'IService1' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped
。
私はすでにに変更BodyStyle
しましたWrapped
、そして私は他に何をすべきですか?そのコントラクトをブラウザから問題なく呼び出すことができます。多分私の設定と関係がありますか?これは私のWPFアプリケーション構成です:
<client>
<endpoint address="http://localhost:1001/Services/Service1.svc" behaviorConfiguration="webBehavior"
binding="webHttpBinding" contract="MainService.IService1" />
</client>
Visual StudioプロジェクトにWCF参照を追加すると、すべてのWCFRESTメソッドが完全にサポートされるわけではありません。Reference.cs
ファイルを開いて、「GetChampsBySport」操作を見つけることをお勧めします。次に、以下を追加します。
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]
追加できない場合はWebInvoke
、参照からSystem.ServiceModel.Web
拡張機能への参照を追加します。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加