我用C#编写了一个WCF Web服务.我最初是自托管它,然后决定在我的PC上本地运行的IIS上托管它.虽然服务正在运行,但我不了解部署过程的几个方面:
首先,在IIS中托管时此服务的URL与我在web.config中指定的URL不对应.我在那里指定了" http:// localhost:8000/MyServices/OrderService ",这是我自我托管时使用的.现在我已经部署到IIS,URL已变为" http:// localhost/MyServices/OrderService ".为什么没有从我的配置文件中提取URL?
其次,为了托管Web服务,我在IIS中创建了一个新的网站(除了现有的"默认网站").我将物理路径设置为c:\ inetpub\wwwroot(不知道这是否正确)并将其他参数保留为默认值.然后我将我的/ bin文件夹,我的.svc文件和我的web.config复制到此文件夹中.这相当于"虚拟目录"吗?
最后,直到(在IIS中)我选择"转换为应用程序"之前,该服务才起作用.为什么有必要选择"转换为应用程序"?
任何人都可以解释将Visual Studio中的简单Web服务发布到IIS中的正确步骤,或者指出一些好的文档以便我能理解这个过程吗?
****编辑原创*****花了更多时间研究这个,我发现了以下内容:
您可以手动执行复制到相同的效果.
答案是在IIS上托管时完全忽略baseAddress.
我有一个托管在IIS上的WCF Web服务,它公开了一个带有三个整数参数的方法.我有一个简单的,基于控制台的客户端,可以调用此方法.
int InsertNewOrder(short quantity, int custID, int productID);
Run Code Online (Sandbox Code Playgroud)
如果我的理解是正确的,我需要为JMeter提供一个SOAP信封,其中包含要调用的方法和要传递的参数的详细信息.我见过很多类似下面的例子:
<soapenv:Envelope xmlns:soapenv="schemas.xmlsoap.org/soap/envelope/">;
<soapenv:Body>
<ns2:InsertNewOrder xmlns:ns2="?????">
<ns2:Param1>${1}</ns2:Param1>
<ns2:Param1>${1}</ns2:Param1>
<ns2:Param1>${1}</ns2:Param1>
</ns2:InsertNewOrder>
</soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)
但是,通过查看我的WSDL文档,我没有看到它引用传递给方法所需的任何参数.我还使用Fiddler检查客户端的SOAP消息到服务.同样,我没有看到它传递参数的位置.因此,我不知道如何创建一个简单的SOAP信封,我可以使用它与JMeter一起测试这项服务.
任何人都可以建议为什么WSDL文档不提供方法参数的任何细节,或者解释我如何创建必要的SOAP信封以用于JMeter?
我使用VS 2010,JMeter 2.4,IIS v6,wsHttpBinding在C#中编码.
使用工作单元/存储库模式构建了一个小应用程序后,我很难理解如何在我的业务层中正确使用它.我的应用程序有一个数据访问层,可以是NHibernate或实体框架.我可以轻松地在这些之间切换.
我有许多存储库,例如,客户,订单等.我的工作单元将是一个ISession或一个对象上下文,具体取决于我想要测试的DAL.
我的业务层包含一个业务方法 - CreateOrder().我正在努力理解的是,在业务层中我应该初始化我的工作单元和我的存储库.
专注于Nhibernate,我的DAL看起来像:
public class NHibernateDAL : IUnitOfWork
{
log4net.ILog log = log4net.LogManager.GetLogger(typeof(NHibernateDAL));
ISession context;
public NHibernateDAL()
{
context = SessionProvider.OpenSession();
this.Context.BeginTransaction();
CurrentSessionContext.Bind(context);
}
public ISession Context
{
get { return context; }
}
public void Commit()
{
this.Context.Transaction.Commit();
context.Close();
}
public void Dispose()
{
ISession session = CurrentSessionContext.Unbind(SessionProvider.SessionFactory);
session.Close();
}
}
Run Code Online (Sandbox Code Playgroud)
在我的业务层中,我想知道我应该在哪里声明我的工作单元和存储库.它们是在类级别还是在CreateOrder方法中声明的?
例如:
public class BusinessLogic
{
UnitOfWork _unitOfWork = new UnitOfWork(NHibernateDAL);
NhRepository<Order> _orderRepository = new NhRepository<Order>(_unitOfWork);
NhRepository<Customer> _customerRepository = new NhRepository<Customer>(_unitOfWork);
....
public void CreateOrder(.....) …Run Code Online (Sandbox Code Playgroud) 我在C#中有一个标准的存储库接口,它包括以下方法:
IEnumerable<T> GetAll();
T GetById(int id);
void Delete(T entity);
void Add(T entity);
Run Code Online (Sandbox Code Playgroud)
在我的域层,我实例化的是一个新的工作单元包装器并将其传递给存储库.工作单元包装类隐藏我是使用NHibernate还是实体框架并公开Commit()方法.
在我的域层中,如何查询仅满足特定条件的对象?
我认为我现在正在做的事情是非常低效的.我目前正在这样做:
var results = myRepository.GetAll().Where......
Run Code Online (Sandbox Code Playgroud)
如果我有大量的对象,GetAll()会在过滤掉我不需要的对象之前返回它们中的每一个吗?如何防止不需要的对象被退回?
显然我可以在接口上添加更多方法,但这似乎与仅通过接口公开CRUD操作一致.
即 - 我不认为我应该添加像(但也许我错了):
IList<T> GetAllWhereMeetsMyCriteria();
Run Code Online (Sandbox Code Playgroud) nhibernate orm entity-framework unit-of-work repository-pattern
下面的程序是我在C#中反序列化XML时发现的一个问题的例子.我有两个单独的程序集,它们声明一个具有相同名称的类型,在下面的示例中为"Country".这些类型由XML命名空间区分.当我反序列化包含单个"Country"元素的配置文件时,将解析正确的"Country"类型.但是,如果我反序列化"Country"元素的"List",则反序列化错误的"Country"类型.
class Program
{
static void Main(string[] args)
{
XDocument gbConfig = XDocument.Parse(@"<TradingBlocConfiguration>
<GreatBritain>
<Country/>
<Countries>
<Country/>
<Country/>
</Countries>
</GreatBritain> </TradingBlocConfiguration>");
XDocument euConfig = XDocument.Parse(@"<TradingBlocConfiguration>
<EuropeanUnion>
<Country/>
<Countries>
<Country/>
<Country/>
</Countries>
</EuropeanUnion> </TradingBlocConfiguration>");
var greatBritainConfiguration = BuildConfig<TradingBlocConfiguration>(gbConfig);
// A single 'Country' is always deserialized correctly..
Console.WriteLine("Great Britain Country Type " + greatBritainConfiguration.TradingBlocConfig.MemberCountry.GetType());
// A List of 'Country' is deserialized to the wrong type, depending on what '[XmlElement]' tag is listed first.
Console.WriteLine("Great Britain Countries Type " + greatBritainConfiguration.TradingBlocConfig.MemberCountries[0].GetType());
var euConfiguration …Run Code Online (Sandbox Code Playgroud) 我正在使用NHibernate创建大量实体,将它们附加到我的ISession,然后使用事务将我的更改提交到数据库.代码示例如下:
ISession _context = SessionProvider.OpenSession();
//Create new entities
for(int i=0; i<100; i++)
{
MyEntity entity = new MyEntity(i);
//Attach new entity to the context
_context.Save(entity);
}
//Persist all changes to the database
using(var tx = _context.BeginTransaction())
{
//Flush the session
tx.Commit();
}
Run Code Online (Sandbox Code Playgroud)
我的印象是_context.Save()行只是让ISession知道新实体,但是在我通过tx.Commit()行刷新会话之前,没有任何更改持久存储到数据库.
我观察到的是,每次调用_context.Save()时数据库都会获得一个新实体.因此,我最终会对数据库进行过多的单独调用.
有谁知道为什么ISession.Save()会自动持久更改?我是否误解了NHibernate的行为方式?谢谢.
***编辑 - 只是为了澄清(根据两个建议的答案) - 我的问题是,一旦我调用_context.Save(),数据库就会更新.我不指望这会发生.我希望在调用tx.Commit()之前不要将任何内容插入到数据库中.到目前为止,两个建议的答案都没有帮助解决这个问题.
可在此处找到有关身份生成器的一些有用信息
我正在使用 C# 中的 .NET 的 RX 库。谁能向我解释为什么“observer.OnCompleted()”方法在以下代码中不执行任何操作:
var observableStream = Observable.Create<CustomMessage>(
(observer) =>
{
CustomMessage cm = new CustomMessage();
CustomMessage.Subscribe(observer.OnNext);
return Disposable.Create(
() =>
{
Console.WriteLine("Disposing...");
CustomMessage.Unsubscribe(observer.OnNext);
observer.OnCompleted(); //***Nothing happens here***
}
);
});
//IObserver.OnException()
public override void OnException(Exception e)
{
Console.WriteLine("Exception occurred - " + e.Message);
}
//IObserver.OnComplete()
public override void OnUnsubscribe()
{
Console.WriteLine("Unsubscribed...");
}
//IObserver.OnNext()
public override void HandleNextMsg(IRVMessage msg)
{
Console.WriteLine("Instance received a message");
}
IDisposable myDisposable = observableStream.Subscribe(HandleNextMsg, OnException, OnUnsubscribe);
//At some later point....
myDisposable.Dispose();
Run Code Online (Sandbox Code Playgroud)
该代码旨在订阅 …
c# ×3
isession ×2
nhibernate ×2
unit-of-work ×2
web-services ×2
iis ×1
iis-7 ×1
jmeter ×1
layer ×1
observable ×1
orm ×1
publish ×1
repository ×1
soap ×1
transactions ×1
xml ×1