我正在使用一个在php页面中使用SoapClient类的方法来调用asp.net站点中的Web服务.
这是php代码.
$client = new SoapClient("http://testurl/Test.asmx?WSDL");
$params = array( 'Param1' => 'Hello',
'Param2' => 'World!');
$result = $client->TestMethod($params)->TestMethodResult;
echo $result;
Run Code Online (Sandbox Code Playgroud)
问题是,我只得到第一个参数(Param1)"Hello",看起来Param2存在问题.这是asp.net方法.
[WebMethod]
public string TestMethod(string Param1, string Param2)
{
return Param1 + " " + Param2;
}
Run Code Online (Sandbox Code Playgroud)
我Hello World!
在回复中错过了什么?
我正在为asp.net MVC布局页面设置共享内容(导航).
这是我的部分视图"_LayoutPartial.cshtml",其中包含从模型中提取导航数据的代码.
@model MyApp.Models.ViewModel.LayoutViewModel
<p>
@foreach (var item in Model.navHeader)
{
//Test dump of navigation data
@Html.Encode(item.Name);
@Html.Encode(item.URL);
}
</p>
Run Code Online (Sandbox Code Playgroud)
以下是我的控制器"LayoutController.cs"的代码.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyApp.Models.ViewModel;
namespace MyApp.Controllers
{
public class LayoutController : Controller
{
//
// GET: /Layout/
LayoutViewModel layout = new LayoutViewModel();
public ActionResult Index()
{
return View(layout);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是"_Layout.cshtml"页面的代码.我试图使用Html.RenderAction(Action,Controller)方法在这里调用局部视图.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<p>
@{Html.RenderAction("Index","Layout");}
</p>
@RenderBody()
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当布局页面执行@ {Html.RenderAction("索引","布局");}行时,它会抛出一条错误消息"错误执行处理程序的子请求'System.Web.Mvc.HttpHandlerUtil + …
在.NET Core Console应用程序上,我正在尝试将自定义appsettings.json文件中的设置映射到自定义配置类.
我在线查看了几个资源,但无法使.Bind扩展方法有效(我认为它适用于asp.net应用程序或以前版本的.Net Core,因为大多数示例都表明了这一点).
这是代码:
static void Main(string[] args)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
IConfigurationRoot configuration = builder.Build();
//this is a custom configuration object
Configuration settings = new Configuration();
//Bind the result of GetSection to the Configuration object
//unable to use .Bind extension
configuration.GetSection("MySection");//.Bind(settings);
//I can map each item from MySection manually like this
settings.APIBaseUrl = configuration.GetSection("MySection")["APIBaseUrl"];
//what I wish to accomplish is to map the section to my Configuration object
//But …
Run Code Online (Sandbox Code Playgroud)