我有一个WCF服务让我们称之为UserService.它UserService有一个类库的引用.我们称之为DoWork.dll.它DoWork.dll具有对我们将调用的不同服务的WCF服务引用CompanyService.
现在,当我第一次尝试调用时,UserService我会得到一个端点未配置的错误消息.各地的网络阅读后,我发现我需要在添加CompanyService绑定和客户信息进入UserService的web.config下<system.serviceModel>节点.
这里是:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IComapnyService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint name="BasicHttpBinding_ICompanyService"
address="http://it-dev.company.local:81/Project/Copmpany/CompanyService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IComapnyService"
contract="CompanyService.ICompanyService" />
</client>
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是contract="CompanyService.ICompanyService"向我显示错误:
'contract'属性无效 - 值'CompanyService.ICompanyService'根据其数据类型'clientContractType'无效 - Enumeration约束失败.
现在,如果我将CompanyService引用直接添加到UserServiceWCF项目,则错误消失(显然).但是,我不应该这样做.我已经尝试完全限定ICompanyService合同所在的命名空间,但也不起作用.我删除了.suo文件并重建项目,但也无法工作(在网络上的其他地方建议).此外,如果我输入contract=,我会得到下拉列表,但CompanyService.ICompanyService无处可寻(只有当我直接在UserService项目中引用服务时).
我已经尝试使用配置它Tools > WCF Service Configuration Editor,但没有帮助.
我应该注意到一切似乎工作正常,但我不喜欢intellisense给我蓝色波浪线下划线和错误信息的事实.我有一种感觉,我需要其他的东西,web.config以便让它工作,因为UserService引用DoWork.dll,反过来引用CompanyService谁的合同,我无法正确看到.
任何建议都非常感谢.提前致谢.
我们有一个核心库,可以进行复杂的计算,我们认为它很关键,我们希望在该库上有100%的代码覆盖率.我们现在有96%这是伟大的,但由于这个类我们不能得到100%:
public class IoCModule : Autofac.Module
{
protected override void Load(Autofac.ContainerBuilder builder)
{
builder.RegisterType<SomeMathServiceA>().As<ISomeMathServiceA>();
builder.RegisterType<SomeMathServiceB>().As<ISomeMathServiceB>();
//... more registrations
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何测试它,或者我们是否真的需要测试它.
我尝试过一个单元测试,它接受这个模块并创建IContainer并解析每个寄存器依赖项,但是有些服务访问DB和配置文件,这些文件在这种情况下非常复杂.
我试图在Windows窗体上获取一个UserControl(其上有一个网格)来调整大小.以下代码是我在表单中的内容.我得到的行为是,当我把它变大时,控件会被调整大小.但它并没有缩小.我做错了什么(或)我错过了什么?
private void AdjustGrid()
{
ZoomControl.Location = new Point(5, 5);
ZoomControl.Size = new Size(this.Width - 15, this.Height - 75);
}
void zoomform_Resize(object sender, EventArgs e)
{
AdjustGrid();
}
Run Code Online (Sandbox Code Playgroud)
现在用户控件具有以下代码:
//Resize the grid that the UserControl has on it
private void NameValuePropertyBag_Resize(object sender, EventArgs e)
{
grdNameValueProperties.Location = new Point(4,4);
grdNameValueProperties.Size = new Size(this.Width - 8, this.Height - 8);
}
Run Code Online (Sandbox Code Playgroud)
我试过了
grdNameValueProperties.Size.Width = this.Width - 8;
grdNameValueProperties.Size.Height = this.Height -8;
Run Code Online (Sandbox Code Playgroud)
它给了我"无法修改表达式,因为它不是变量"错误...我错过了什么?
附加信息:
我正在使用SetParent()Windows调用将UserControl移动/缩放到另一个窗体(ZoomForm).
Anchor似乎不适用于使用SetParent()移动的控件...更确切地说,它可能正在工作,但我重新绘制了问题.
我让Anchor/Dock对工作没有重新绘制问题[我删除了调整大小事件连线并调整了Dock to Fill]
ZoomForm最初没有控件.Usercontrol动态添加到ParentForm.
目前,我可以使用上面的代码使缩放形式更大 …
我有一个ContextMenuStrip控件,允许你执行一个动作是两种不同的风格:Sync和Async.
我试图用泛型覆盖所有内容所以我这样做:
public class BaseContextMenu<T> : IContextMenu
{
private T executor;
public void Exec(Action<T> action)
{
action.Invoke(this.executor);
}
public void ExecAsync(Action<T> asyncAction)
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
我如何编写异步方法以执行通用操作并同时使用菜单"执行某些操作"?我看到签名BeginInvoke是这样的:
asyncAction.BeginInvoke(this.executor, IAsyncCallback, object);
Run Code Online (Sandbox Code Playgroud) 如何从一个自定义路由事件中取消注册.
我有以下代码(自定义路由事件非常标准)
//Dispatch the Video Detection Movements
public delegate void MovementRoutedEventHandler( object sender
, MovementRoutedEventArgs e);
public class MovementRoutedEventArgs : RoutedEventArgs
{
private readonly DahuaDevice _device;
private readonly byte[] _canals;
private readonly DateTime _when;
public MovementRoutedEventArgs(DahuaDevice device, byte[] canals, DateTime when)
{
_device = device;
_canals = canals;
_when = when;
}
public DahuaDevice Device
{
get { return _device; }
}
public Byte[] Canals
{
get { return _canals; }
}
public DateTime When
{
get { return _when; …Run Code Online (Sandbox Code Playgroud) 在c#中有没有办法做这样的事情:
public void Foo<T>()
{
T[] arr = Goo() as T[];
}
Run Code Online (Sandbox Code Playgroud)
Goo返回的地方object[],使用反射或其他什么?
好吧,假设我有两个窗口.在第一个我有一个方法
public void Test()
{
Label.Content += " works";
}
Run Code Online (Sandbox Code Playgroud)
在第二个我称之为这个方法:
MainWindow mw = new MainWindow();
mw.Test();
Run Code Online (Sandbox Code Playgroud)
但没有任何反应.我究竟做错了什么?谢谢.
如果我有一个像这样的 if 语句,我无法在正文中if (currentShape is ITable table || currentShape is AutoShape autoShape)使用tableor ,因为我收到CS0165 编译器错误。autoShape
对于带有失败的 switch 语句也是如此:
void Foo(object o)
{
switch (o)
{
case int i:
case string s:
case Guid g:
string bar = i?.ToString() ?? s?.ToString() ?? g.ToString(); // cannot use i, s, or g.
break;
}
}
Run Code Online (Sandbox Code Playgroud)
我明白为什么,但我想知道,这是模式匹配的限制,即您不能在复合if语句中使用它,或者是否有正确的方法来构造语句,以便我可以使用任一变量(例如,通过将它们初始化为null 所以我至少可以做一个空检查)?
我不是在寻找两个返回bool的结构的比较,我想知道是否有办法获得两个结构的哪些字段(相同的结构,但可能是不同的值)是不同的.基本上我想要一个更简单的方法来执行以下操作:
public class Diff
{
public String VarName;
public object Val1;
public object Val2;
public Diff(String varName, object val1, object val2)
{
VarName = varName;
Val1 = val1;
Val2 = val2;
}
public override string ToString()
{
return VarName + " differs with values " + Val1 + " and " + Val2;
}
}
public struct TestStruct
{
public int ValueOne;
public int ValueTwo;
public int ValueThree;
public List Compare(TestStruct inTestStruct)
{
List diffs = new List();
if (ValueOne …Run Code Online (Sandbox Code Playgroud) 有什么方法可以获取发生的提交列表(比如说 09:00 到 17:00 之间)及其时间吗?
我唯一能想到的就是将输出发送到文件,然后尝试解析它......
c# ×7
.net ×1
asynchronous ×1
autofac ×1
class ×1
compare ×1
comparison ×1
events ×1
generics ×1
git ×1
methods ×1
reflection ×1
routed ×1
struct ×1
unit-testing ×1
wcf ×1
wcf-endpoint ×1
web-config ×1
winforms ×1
wpf ×1