Mvc 5似乎依赖于Owin,如果你想自己托管或在Mac上运行,那就太棒了.但是我们假设我只想在IIS下运行,就像以前的版本一样,我对Owin提供的东西不感兴趣.默认的"空白"mvc5模板使用owin和其他15个依赖项.我已经尝试逐个删除软件包,但似乎网站不知道如何在不使用Owin的属性的情况下启动.那么,如何在没有Owin的iis下获得ASP.net,mvc 5?
我正在尝试找到一种配置AutoMapper的方法,以通过其源父对象的引用在目标对象中设置属性.下面的代码显示了我想要实现的目标.我正在从数据对象将数据移动到Parent&Child实例中.映射可以正常创建具有正确数据的List集合,但我需要有一个ForEach来分配父实例引用.
public class ParentChildMapper
{
public void MapData(ParentData parentData)
{
Mapper.CreateMap<ParentData, Parent>();
Mapper.CreateMap<ChildData, Child>();
//Populates both the Parent & List of Child objects:
var parent = Mapper.Map<ParentData, Parent>(parentData);
//Is there a way of doing this in AutoMapper?
foreach (var child in parent.Children)
{
child.Parent = parent;
}
//do other stuff with parent
}
}
public class Parent
{
public virtual string FamilyName { get; set; }
public virtual IList<Child> Children { get; set; }
}
public class Child
{
public …Run Code Online (Sandbox Code Playgroud) 我有一个在IIS7.5中托管的简单WCF服务,使用消息安全性和InstanceContextMode.PerCall通过wsHttp绑定公开
我有一个简单的UI,可以旋转可配置数量的线程,每个线程都调用该服务.
我添加了perfmon计数器ServiceModel4.Instances.无论创建的线程数和调用服务的数量如何,perfmon都会显示该服务最多可创建10个实例.
我的客户端配置如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService3">
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/NGCInstancing/Service3.svc/~/Service3.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService3"
contract="NGCSecPerCall.IService3" name="WSHttpBinding_IService3">
<identity>
<servicePrincipalName value="host/RB-T510" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我的服务配置如下:
<?xml version="1.0"?>
<system.serviceModel>
<configuration>
<behaviors>
<serviceBehaviors>
<behavior name="SecPerCallBehaviour">
<serviceThrottling maxConcurrentCalls="30" maxConcurrentSessions="1000"
maxConcurrentInstances="30" />
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding> …Run Code Online (Sandbox Code Playgroud) 我知道任何init ...方法都会初始化一个新对象,并且NSString stringWithString会将参数字符串的副本作为新对象.我也理解作为对象的所有者,我可以控制我分配的任何对象的释放/释放.我不明白的是什么时候我会使用stringWithString方法,因为任何以这种方式分配的局部变量都会让它的内存由NSString而不是本地类"拥有".
Kochan的"Objective in Objective C"一书(第1版)使用以下代码(参见第342-344页)来解释initWithString比stringWithString更可取,因为AddressCard类将拥有名称变量contents.另外,使用stringWithString方法重复调用setName版本时,我没有任何错误.TIA!
//header file has appropriate declarations but not included here:
#import "AddressCard.h"
@implementation AddressCard;
-(NSString *) name
{
return name;
}
//Recommended code:
-(void) setName: (NSString *) theName
{
[name release]
name = [[NSString alloc] initWthString: theName];
}
//Incorrect code according to Kochan:
-(void) setName: (NSString *) theName
{
[name release]
name = [NSString stringWthString: theName];
}
//rest of class implementation code snipped
@end
Run Code Online (Sandbox Code Playgroud) 在C#中,内存效率更高:选项#1还是选项#2?
public void TestStringBuilder()
{
//potentially a collection with several hundred items:
string[] outputStrings = new string[] { "test1", "test2", "test3" };
//Option #1
StringBuilder formattedOutput = new StringBuilder();
foreach (string outputString in outputStrings)
{
formattedOutput.Append("prefix ");
formattedOutput.Append(outputString);
formattedOutput.Append(" postfix");
string output = formattedOutput.ToString();
ExistingOutputMethodThatOnlyTakesAString(output);
//Clear existing string to make ready for next iteration:
formattedOutput.Remove(0, output.Length);
}
//Option #2
foreach (string outputString in outputStrings)
{
StringBuilder formattedOutputInsideALoop = new StringBuilder();
formattedOutputInsideALoop.Append("prefix ");
formattedOutputInsideALoop.Append(outputString);
formattedOutputInsideALoop.Append(" postfix");
ExistingOutputMethodThatOnlyTakesAString(
formattedOutputInsideALoop.ToString());
}
}
private …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用此签名为ExpandoObject分配方法(函数):
public List<string> CreateList(string input1, out bool processingStatus)
{
//method code...
}
Run Code Online (Sandbox Code Playgroud)
我尝试过这样的代码,下面的代码不能编译:
dynamic runtimeListMaker = new ExpandoObject();
runtimeListMaker.CreateList =
new Func<string, bool, List<string>>(
(input1, out processingStatus) =>
{
var newList = new List<string>();
//processing code...
processingStatus = true;
return newList;
});
Run Code Online (Sandbox Code Playgroud)
不幸的是我无法更改CreateList签名,因为它会破坏向后兼容性,因此重写它不是一个选项.我试图通过使用委托解决这个问题,但在运行时,我得到了"无法调用非委托类型"异常.我想这意味着我没有正确分配代表.我需要帮助使语法正确(委托示例也可以).谢谢!!
我需要将一个存在的 DI容器作为参数传递给WCF服务构造函数为了做到这一点,我正在使用IInstanceProvider WCF服务应该托管在自托管中.
public class CustomInstanceProvider : IInstanceProvider, IContractBehavior
{
private readonly IUnityContainer UnityContainer;
public CustomInstanceProvider(IUnityContainer unityContainer)
{
if (unityContainer == null)
{
throw new ArgumentNullException("unityContainer");
}
UnityContainer = unityContainer;
}
#region Implementation of IInstanceProvider
public object GetInstance(InstanceContext instanceContext)
{
return new Service(UnityContainer);
}
public object GetInstance(InstanceContext instanceContext, Message message)
{
return this.GetInstance(instanceContext);
}
public void ReleaseInstance(InstanceContext instanceContext, object instance)
{
}
#endregion
#region Implementation of IContractBehavior
public void Validate(ContractDescription contractDescription, ServiceEndpoint endpoint)
{
}
public void ApplyDispatchBehavior(ContractDescription contractDescription, …Run Code Online (Sandbox Code Playgroud) c# ×4
wcf ×2
automapper ×1
c#-4.0 ×1
cocoa ×1
iis ×1
iis-7.5 ×1
memory-leaks ×1
objective-c ×1
owin ×1
self-hosting ×1