[英]How fix error Endpoint not found WCF REST POST
我有一個以字符串作為輸入的 WCF REST 服務,
IService.cs:
[ServiceContract]
public interface IServiceImportAutoLiasse
{
[OperationContract]
[WebInvoke(Method = "POST",BodyStyle = WebMessageBodyStyle.Bare)]
string PostJson(string request);
}
IService.svc.cs:
public string PostJson(string request)
{
//...
}
我驗證了 web.config ,它做得很好:
<services>
<!--SOAP-->
<service behaviorConfiguration="ServBehavior" name="SysLap.Services.Web.ImportAutoLiasse.Service">
<endpoint address="soap" binding="basicHttpBinding" bindingConfiguration="BindingCongHttp"
contract="SysLap.Services.Web.ImportAutoLiasse.IService" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<!--REST-->
<endpoint address="rest" behaviorConfiguration="webHttpBhavior" bindingConfiguration="BindingConfigWebHttp"
binding="webHttpBinding" contract="SysLap.Services.Web.ImportAutoLiasse.IService" />
</service>
</services>
我用郵遞員測試它:
https://localhost:44355/ServiceImportAutoLiasse.svc/rest/PostJson
使用 JSON 輸入:
{
"Headers": ["Header":"CA","Header":"Pe","Header":"RU","Header":"P_AMOUNT"],
"Values": ["value":"A;2019.12;S200;100","value":"A;2019.12;S000;1" ]
}
我有錯誤:
The server encountered an error processing the request. The exception message is 'There was an error
deserializing the object of type System.String. End element 'root' from namespace '' expected. Found element
'Headers' from namespace ''.'. See server logs for more details
我收到錯誤消息:“找不到端點。”
我該如何解決? 提前致謝,
正如您發布的那樣,如果操作只接受String
,我們應該更改ContentType
。 但是如果你想通過 JSON 數據傳遞一個強類型對象參數,你可以參考下面的代碼片段。
假設有以下數據契約,
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
和服務合同,
[OperationContract]
[WebInvoke(Method = "POST",BodyStyle = WebMessageBodyStyle.Bare)]
CompositeType GetDataUsingDataContract(CompositeType composite);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.