【发布时间】:2014-08-19 06:37:16
【问题描述】:
我有一个调用 REST Web 服务的 Apex 类(SalesForce 中的一个类)。
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 服务,但我如何才能读取 HttpRequest req 的 body 中设置的内容,而 sendNotification()方法——req.setBody(aStr);?
即string Test(string aStr);的参数应该是什么?
我是否需要在WebInvoke 或App.config(例如binding)中指定任何其他配置/属性?
【问题讨论】:
标签: c# web-services wcf rest salesforce