我已經創建了一個Rest WCF服務。使用Wcf Rest服務問題
服務合同
[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這在客戶端這是給我的錯誤。
The HTML document does not contain Web service discovery information.
元數據包含無法解析的引用:'http://mydomain:1121/Rest/RestServiceImpl.svc
'。 內容類型application/soap + xml;服務http://mydomain:1121/Rest/RestServiceImpl.svc
不支持charset = utf-8。客戶端和服務綁定可能不匹配。 遠程服務器返回錯誤:(415)由於內容類型'application/soap + xml; charset = utf-8'不是預期的類型'text/xml; charset = utf-8'.. 如果服務在當前解決方案中定義,請嘗試構建解決方案並再次添加服務引用。
那麼它將如何解決。
你重命名你的服務和接口文件? – Sajeetharan 2013-02-27 04:03:54
是的,我已經改名 – user1006544 2013-02-27 11:38:25