我有一个Apex类(SalesForce中的一个类),它调用一个REST web服务。
public class WebServiceCallout
{
@future (callout=true)
public static void sendNotification(String aStr)
{
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
req.setEndpoint('http://xx.xxx.xxx.xx:41000/TestService/web/test');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json');
req.setBody(aStr); // I want to read this in the web service
try
{
res = http.send(req);
}
catch(System.CalloutException e)
{
System.debug('Callout error: '+ e);
System.debug(res.toString());
}
}
}
REST Web服务(C#,WCF)如下所示:
public interface ITestService
{
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/test")]
string Test(string aStr);
}
Test()
方法执行基本操作。
当我运行时
WebServiceCallout.sendNotification("a test message")
POST请求发送到Web服务,但是我如何读取在sendNotification()
方法中设置的req.setBody(aStr);
的HttpRequest的body中设置的内容呢?
也就是说,string Test(string aStr);
方法的参数应该是什么?
我需要指定其他任何配置/属性吗,在我的WebInvoke
或App.config
中(例如,binding
)?
var body = "msg:\"a test message\"";
- David R Tribble