双工服务引用将接口类型转换为system.object类型(Duplex service reference converts interface type to system.object type)
这是我的wcf双工服务回调接口:
public interface ICallback { [OperationContract(IsOneWay = true)] void SendClientCallback(CallbackMessage callbackMessage); [OperationContract] void GetTemplateList(ref List<ISpecimenTemplateDescriptor> templateDescriptors, IDrawerLayout drawerLayout); }
我配置我的服务引用以使用System.Collections.Generic.List类型。 我通过右键单击服务引用,选择配置服务选项以及更改集合类型来完成此操作。 这将服务引用配置为使用List的集合类型,而不是默认的Array类型。
当我编译并更新我的服务引用时,我的接口类型“ISpecimenTemplateDescriptor”和“IDrawerLayout”将转换为“System.Object”,如下所示:
void GetTemplateList(ref System.Collections.Generic.List<object> templateDescriptors, object drawerLayout);
为什么我的接口对象在服务引用中转换为System.Object?
这是我的服务合同:
[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(ICallback))] public interface IWcfService { ..... }
以下是我的服务行为:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Reentrant, UseSynchronizationContext = false)] public class WcfService : IWcfService { ...... }
感谢您的帮助!
Here is my wcf duplex service callback interface:
public interface ICallback { [OperationContract(IsOneWay = true)] void SendClientCallback(CallbackMessage callbackMessage); [OperationContract] void GetTemplateList(ref List<ISpecimenTemplateDescriptor> templateDescriptors, IDrawerLayout drawerLayout); }
I configured my service reference to use the System.Collections.Generic.List type. I did this by right clicking on the service reference, selecting the configure service option, and changing the Collection type. This configured the service reference to use a collection type of List, instead of the default Array type.
When I compile and update my service reference, my interface type "ISpecimenTemplateDescriptor" and "IDrawerLayout" are converted to "System.Object" as shown below:
void GetTemplateList(ref System.Collections.Generic.List<object> templateDescriptors, object drawerLayout);
Why are my interface objects converted to System.Object in the service reference?
Here is my service contract:
[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(ICallback))] public interface IWcfService { ..... }
Here are my service behaviors:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Reentrant, UseSynchronizationContext = false)] public class WcfService : IWcfService { ...... }
Thanks for your help in advance!
原文:https://stackoverflow.com/questions/13634297
最满意答案
考虑使用默认参数:
public function createBalance($CustomerID=null) { if ($CustomerID==null) return view('customer.balance'); else // show balance of the the defined customer }
并将您的路线更改为:
Route::get('Customer/Balance/{CustomerID?}', 'CustomerController@createBalance');
添加“?” 参数后,Laravel明白你正在传递一个可选参数。
Consider use default parameters:
public function createBalance($CustomerID=null) { if ($CustomerID==null) return view('customer.balance'); else // show balance of the the defined customer }
And change your route to:
Route::get('Customer/Balance/{CustomerID?}', 'CustomerController@createBalance');
Adding a "?" after the argument, Laravel understands you're passing an optional parameter.
相关问答
更多-
当您从Controller调用方法到另一个 Controller时,这意味着您做错了。 为此,您应该 使用服务。 在app \ Services Utility.php中创建一个类 use Elasticsearch\Client; class Utility { public function selectRandom(Client $es, $numRows) { # ...search params here $results = $es->search($ ...
-
在Laravel中的控制器模型中使用scopePublished()方法?(Use scopePublished() method in model from a controller in Laravel?)[2023-06-06]
如果我正确理解您的问题,您想要对已发布的文章进行分页。 所以你可以做到这一点。 $query = Article::published()->paginate(8) 有关更多信息,请查看“ 查询范围”下的“ Local Scopes 范围” If I understand your question correctly you want to paginate published articles. So you can do this. $query = Article::published()->pa ... -
在Laravel 4呼叫控制器(Call a controller in Laravel 4)[2023-09-01]
如果我明白的是,您正在尝试构建以API为中心的应用程序,并希望在Web应用程序中内部访问API,以避免发出额外的HTTP请求(例如使用cURL)。 那是对的吗? 您可以执行以下操作: $request = Request::create('api/items', 'GET', $params); return Route::dispatch($request)->getContent(); 请注意,不需要指定控制器@方法目标,您将需要使用通常用于从外部访问API的uri路由。 更好的是,您现在可以指定请求 ... -
您可以访问您的控制器方法,如下所示: app('App\Http\Controllers\PrintReportController')->getPrintReport(); 这将工作,但这在代码组织方面是不好的(记住要为您的PrintReportController放置正确的命名空间,如果它是不同的)。 您可以扩展PrintReportController使您的SubmitPerformanceController将继承此方法 class SubmitPerformanceController exte ...
-
考虑使用默认参数: public function createBalance($CustomerID=null) { if ($CustomerID==null) return view('customer.balance'); else // show balance of the the defined customer } 并将您的路线更改为: Route::get('Customer/Balance/{CustomerID?}', 'Custo ...
-
试着这样做 定义路线 Route :: resource('customer / {id}','Customer'); 在您的客户控制器中 use Route; public function __construct() { $id = Route::current()->getParameter('id'); dd($id); } Try to do like this Define route Route::resource('customer/{id}', 'Customer'); In y ...
-
问题是你使用UrlParameter.Optional (这是一个ASP.NET MVC特定类型)而不是RouteParameter.Optional 。 改变你的路线如下,然后它应该工作: GlobalConfiguration.Configuration.Routes.MapHttpRoute( "Api", "api/{controller}/{id}", new { id = RouteParameter.Optional } ); The problem is that ...
-
Laravel不会以controller/method方式自动映射路径。 您尚未发布routes.php文件中的内容,但最简单的方法之一是执行此操作: Route::get('users/login', array('as' => 'login', 'uses' => 'User@getLogin')); 但是,有多种方法。 您可以考虑阅读有关路由的文档 Laravel does not automatically map routes in controller/method fashion. You ...
-
是的,但您必须处理null参数,如下所示: public function bar($id=null, $date=null) { .... 但在这一点上,最好用可选参数声明单一路径: Route::get('foo/bar/{id?}/{date?}', 'FooController@bar'); Yes but you have to handle null parameters, like that: public function bar($id=null, $date=nu ...
-
您无法为每条路线创建相同的网址。 对于每个路由,您需要具有不同的URL,例如: Route::get('/staff', 'controllerstaff@index'); Route::get('/students', 'controllerstudent@index'); 您还应该将控制器命名为StudentController而不是controllerstudent 。 在创建代码之前,您可能还会考虑查看路由文档 - 我相信它可能是正确的方法;) You cannot create same url ...