如何修复错误 Endpoint not found WCF REST POST
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>
然后我用 POSTMAN 测试它:
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
我得到错误:"Endpoint not found."
我该如何解决?
提前致谢,
我找到了解决方案,实际上我必须在 POSTMAN 的 Headers 中停用 Content-Type:
现在效果很好,
如您所发,如果操作仅接受 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);
然后我们可以通过构建以下请求来测试操作。
如果有什么我可以帮忙的,请随时告诉我。
我有一个以字符串作为输入的 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>
然后我用 POSTMAN 测试它:
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
我得到错误:"Endpoint not found."
我该如何解决? 提前致谢,
我找到了解决方案,实际上我必须在 POSTMAN 的 Headers 中停用 Content-Type:
现在效果很好,
如您所发,如果操作仅接受 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);
然后我们可以通过构建以下请求来测试操作。
如果有什么我可以帮忙的,请随时告诉我。