我有一个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
我收到错误消息:“找不到端点。”
我该如何解决? 预先感谢,
答案 0 :(得分:1)
答案 1 :(得分:1)
如您所发布的,如果操作仅接受ContentType
,我们应该更改String
。但是,如果您想通过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);