RestWCFサービスを作成しました。
サービス契約
[ServiceContract]
public interface IPracticeService
{
[OperationContract]
int AddInt(int value1, int value2);
[OperationContract]
double AddDouble(double value1, double value2);
[OperationContract]
string Hello();
[OperationContract]
Person GetPerson();
}
クラス
public class PracticeService : IPracticeService
{
public int AddInt(int value1, int value2)
{
return value1 + value2;
}
[OperationBehavior]
public double AddDouble(double value1, double value2)
{
return value1 + value2;
}
public string Hello()
{
return "hello";
}
[WebInvoke(Method="GET",ResponseFormat=WebMessageFormat.Json)]
public Person GetPerson()
{
Person p = new Person();
p.Name = "Abc";
p.Age = 5;
return p;
}
Web Config
<system.serviceModel>
<services>
<service name="RestService.IRestServiceImpl" behaviorConfiguration="ServiceBehaviour">
<endpoint address="*" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web"></behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
したがって、ServiceRefrence Thisをクライアントに追加したい場合は、エラーが発生します。
The HTML document does not contain Web service discovery information.
メタデータに解決できない参照が含まれています:' http://mydomain:1121/Rest/RestServiceImpl.svc
'。コンテンツタイプapplication/soap + xml; charset=utf-8はサービスでサポートされていませんでしたhttp://mydomain:1121/Rest/RestServiceImpl.svc
。クライアントとサービスのバインディングが一致していない可能性があります。リモートサーバーがエラーを返しました:(415)コンテンツタイプ'application / soap + xml;のため、メッセージを処理できません。charset =utf-8'は予期されたタイプ'text/xmlではありませんでした。charset = utf-8'..サービスが現在のソリューションで定義されている場合は、ソリューションをビルドして、サービス参照を再度追加してみてください。
では、どうすれば解決できるのでしょうか。