我有一个作为服务角色的项目库。它包括:
- 一个接口:
public interface IManageApplicationServiceInterface : IProcessQ<IManageApplicationServiceEntity>
{
void createMyApp(IManageApplicationServiceEntity serviceEntity);
}
- 实现上述接口的服务类:
[Export(typeof(IProcessQ))]
[ProcessMetaData("My API Service Interface", "F756B100-5B85-4877-9EF6-BB53727371BB",PluginType.ServiceInterface, typeof(IManageApplicationServiceEntity))]
public class ManageApplicationServiceInterface : IManageApplicationServiceInterface
{
public void Execute(IEntity entity)
{
throw new NotImplementedException();
}
public void Execute(IManageApplicationServiceEntity serviceEntity)
{
throw new NotImplementedException();
}
public void createMyApp(IManageApplicationServiceEntity applicationData)
{
try
{
Logger.Debug("Create may app method - Starts");
//build something to make an api call
//apiURL
//create a JObject with adding 2 properties
//prepare a httpContent
var content = new StringContent(jsonCreateApp.ToString(Newtonsoft.Json.Formatting.None), Encoding.UTF8, "application/json");
//add default request headers for httpClient object
//get client response
var clientResponse = httpClient.PostAsync(apiURL, content).Result;
//If the API call is success then read the response otherwise throw exception
if (clientResponse.IsSuccessStatusCode)
{
var apiResult = Newtonsoft.Json.Linq.JObject.Parse(clientResponse.Content.ReadAsStringAsync().Result);
Logger.Debug("Create App method - Reading response");
response.Add("id", apiResult["id"].ToString());
response.Add("createMyAppETagID", removeDoubleQuote(clientResponse.Headers.ETag.ToString()));
response.Add("responseMyApp", apiResult.ToString());
}
else
{
Logger.Debug("Create App method Error - Status Code" + clientResponse.StatusCode + "ReasonPhrase - " + clientResponse.ReasonPhrase);
throw new ArgumentException("Create App method Error - Status Code" + clientResponse.StatusCode + "ReasonPhrase - " + clientResponse.ReasonPhrase);
}
Logger.Debug("Create My App method - Ends");
return response;
Logger.Debug("Create create My App - Ends");
}
catch (Exception ex)
{
Logger.Error("Expection in Create My App method - " + ex);
throw ex;
}
}
}
我将从 Web 控制台或 Web 应用程序调用 createMyApp Web 服务方法。我使用 Web 应用程序在 Page_Load 中调用它
IManageApplicationServiceEntity manageApplicationServiceInterface;
ds.createMyApp(manageApplicationServiceInterface);
当悬停在 ds.createMyApp Visual Studio 上时说:“前端应该提供输入 json”。它是否需要一个 JObject 并在传递之前将对象转换为 IManageApplicationServiceEntity 类型?当悬停在接口变量上时,它会显示:“使用未分配的局部变量 manageApplicationServiceInterface”
如何准备接口参数传递给服务方法 createMyApp 来调用它?希望得到帮助。很多人欣赏!