小编New*_*bee的帖子

如何安全地将字节数组转换为字符串并返回?

我不关心编码和东西,只要我找回完全相同的字节数组.

总结一下:如何将字节数组转换为字符串,然后将该字符串转换回我开始使用的相同字节数组?

c# string bytearray

86
推荐指数
2
解决办法
6万
查看次数

TeamCity,如何获取编辑文件的名称

我正在使用TeamCity,我是新手.我已经向TeamCity添加了一个Build Configuration,我创建了一个VCS root来附加到它.

但是,我的项目有一个特殊要求,即检测在VCS根位置中更改的特定文件,并在构建步骤中使用该文件.我相信这可以在TeamCity中完成,我无法弄清楚如何.

有帮助吗?谢谢,

version-control teamcity

10
推荐指数
2
解决办法
4827
查看次数

c#WCF的跨源资源共享作为Windows服务托管的Restful Web服务

我有一个WCF Restful服务,我作为Windows服务托管.我想为我的服务添加跨域支持.但是,当我使用global.asax文件时,我可以轻松地做到这一点.但我想将我的服务作为Windows服务托管.

我创建了一个项目,将我的服务托管为Windows服务.现在我面临的问题是,我不能够立即添加跨域支持.我尝试了通过app.config文件找到的所有可能的解决方案,但都没有.我在这些链接上尝试了解决方案:

dotnet技巧

enable-cors.org

我试图通过调用它在每个服务合同方法设置在使用下面的函数的代码首部.

private static void SetResponseHeader()
{
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Cache-Control", "no-cache, no-store");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Request-Methods", "GET, POST, PUT, DELETE, OPTIONS");
WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Headers", "Content-Type, Accept");
}
Run Code Online (Sandbox Code Playgroud)

接口:

namespace ReaderService
{
[ServiceContract]
public interface INFCReader
{
    [OperationContract]
    [WebInvoke(UriTemplate = "GetLogin", Method = "POST")]
    GetLoginResults GetLogin(DisplayRequest dispRequest);
}
Run Code Online (Sandbox Code Playgroud)

这里DisplayRequest是一个类.

请帮帮我们 如果有人想查看任何其他代码,请告诉我.

非常感谢.

编辑:::::::

非常感谢托马斯的回复.我创建了一个类MessageInspector其实现IDispactchMessageInspector.我在MessageInspector类中有以下代码.

public class MessageInspector : IDispatchMessageInspector
{
    public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
    {
        HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
        if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
        {
            HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST"); …
Run Code Online (Sandbox Code Playgroud)

asp.net rest wcf cors c#-4.0

7
推荐指数
1
解决办法
1万
查看次数

多个绑定的WCF Mex端点

我正在构建一个WCF服务,它将公开BasicHttp和NetTcp绑定.我还添加了两个相应的Mex端点,即

<service name="WCFTest.CalculatorService" behaviorConfiguration="WCFTest.CalculatorBehavior">
  <host>
    <baseAddresses>
      <add baseAddress = "http://localhost:8000/WCFTest/CalculatorService/" />
      <add baseAddress = "net.tcp://localhost:9000/WCFTest/CalculatorService/" />
    </baseAddresses>
  </host>

  <endpoint address ="basicHttpEP" binding="basicHttpBinding" contract="WCFTest.ICalculatorService"/>
  <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

  <endpoint address ="netTcpEP" binding="netTcpBinding" contract="WCFTest.ICalculatorService"/>
  <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>        
</service>
Run Code Online (Sandbox Code Playgroud)

我真的需要添加NetTcp Mex端点以及BasicHttp Mex端点吗?客户不仅会总是使用Http mex端点进行元数据解析,而不管他们是否要使用tcp进行通信?

谢谢

c# wcf mex

6
推荐指数
1
解决办法
5573
查看次数

使用多个跟踪侦听器

我有2个WCF服务,我从一个Windows主机托管.我使用跟踪侦听器将数据记录到应用程序日志中.我在配置文件中添加了以下代码.

<system.diagnostics>
<switches>
  <add name="ReaderService.Switch" value="4"/>
  <add name="InfoService.Switch" value="4"/>
</switches>
<trace autoflush="false" indentsize="4">
  <listeners>
    <add name="EventLogTraceListener"
      type="System.Diagnostics.EventLogTraceListener"
      initializeData="ReaderServiceLog" />
  </listeners>
</trace>
</system.diagnostics>
Run Code Online (Sandbox Code Playgroud)

来自两个服务的所有日志都显示在源ReaderServiceLog名称下.我想要做的是,来自每个服务的日志应该出现在不同的源名称下.

例如,来自ReaderService的日志应显示在名称ReaderServiceLog下,InfoService中的日志应显示在InfoServiceLog下.我修改了我的配置,如下所示.

<system.diagnostics>
<switches>
  <add name="ReaderService.Switch" value="4"/>
  <add name="InfoService.Switch" value="4"/>
</switches>
<sources>
  <source name="EventLogTraceListener">
    <listeners>
      <add name="EventLogTraceListener"
      type="System.Diagnostics.EventLogTraceListener"
      initializeData="ReaderServiceLog" />
    </listeners>
  </source>
  <source name="InfoService">
    <listeners>
      <add name="EventLogTraceListener"
      type="System.Diagnostics.EventLogTraceListener"
      initializeData="InfoServiceLog" />
    </listeners>
  </source>
</sources>
</system.diagnostics>
Run Code Online (Sandbox Code Playgroud)

并使用此代码:

private TraceSource ts = new TraceSource("InfoService");
ts.TraceInformation(outputMessage, aslErrorText);
ts.Flush();
Run Code Online (Sandbox Code Playgroud)

但它不起作用.它根本不记录任何内容.

我也尝试过这个.但它不起作用.

<system.diagnostics>
<switches>
  <add name="ReaderService.Switch" value="4"/>
  <add name="InfoService.Switch" value="4"/>
</switches>
<sources> …
Run Code Online (Sandbox Code Playgroud)

c# asp.net wcf logging visual-studio-2010

6
推荐指数
1
解决办法
4962
查看次数

当没有为MSBuild指定平台参数时的差异

我有一个VS10项目文件(.csproj).我正在使用命令行中的MSBuild构建此项目.我有一个简单的问题,我一直试图弄清楚.这些命令行参数之间有什么区别: -

1. >MSBuild MyProg.csproj /p:Configuration="Release"
2. >MSBuild MyProg.csproj /p:Platform="AnyCPU" /p:Configuration="Release"   
3. >MSBuild MyProg.csproj /p:Platform="x86" /p:Configuration="Release"
Run Code Online (Sandbox Code Playgroud)

在csproj文件中,我有这个PropertyGroup标记

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  <DebugSymbols>true</DebugSymbols>
  <DebugType>full</DebugType>
  <Optimize>false</Optimize>
  <OutputPath>..\..\bin\Debug\</OutputPath>
  <DefineConstants>DEBUG;TRACE</DefineConstants>
  <ErrorReport>prompt</ErrorReport>
  <WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  <DebugType>pdbonly</DebugType>
  <Optimize>true</Optimize>
  <OutputPath>..\..\bin\Release\</OutputPath>
  <DefineConstants>TRACE</DefineConstants>
  <ErrorReport>prompt</ErrorReport>
  <WarningLevel>4</WarningLevel>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

我想知道当您在命令行参数中指定平台时,以及何时不这样做时,它会有什么不同.我一直在尝试使用命令行中的verbosity参数/ v:d来调查这一点,但除了每个构建的平台不同之外我找不到任何区别.

当我没有在命令行中传递平台时,平台会是什么?当我通过x86而不是AnyCPU时会发生什么?

谢谢

c# msbuild command-line visual-studio-2010

6
推荐指数
1
解决办法
6033
查看次数

一般字符串加密

我在.NET中寻找一般的字符串加密类.(不要与'SecureString'类混淆.)

我已经开始提出自己的类,但是认为必须有一个.NET类,它已经允许你使用任何加密服务提供程序加密/解密任何编码的字符串.

Public Class SecureString

        Private key() As Byte
        Private iv() As Byte
        Private m_SecureString As String

        Public ReadOnly Property Encrypted() As String
            Get
                Return m_SecureString
            End Get
        End Property

        Public ReadOnly Property Decrypted() As String
            Get
                Return Decrypt(m_SecureString)
            End Get
        End Property

        Public Sub New(ByVal StringToSecure As String)
            If StringToSecure Is Nothing Then StringToSecure = ""
            m_SecureString = Encrypt(StringToSecure)
        End Sub

        Private Function Encrypt(ByVal StringToEncrypt As String) As String

            Dim result As String = ""
            Dim bytes() As Byte …
Run Code Online (Sandbox Code Playgroud)

.net cryptography

5
推荐指数
1
解决办法
1570
查看次数

Inno Setup运行setup.exe时修改app.config文件

我有一个WCF服务,我作为Windows服务托管.我通常会转到VS命令提示符并使用installutil.exe安装该服务,然后根据我安装它的机器名修改app.config中服务的基地址并运行该服务.

基地址如下:

<endpoint address="http://MACHINE_NAME/NFCReader/" binding="webHttpBinding"/>
Run Code Online (Sandbox Code Playgroud)

我在app.config文件中修改了MACHINE_NAME.

我想使用inno设置为我做同样的事情.

我想要的是当用户运行setup.exe文件来安装服务时,我想提示用户提供服务的基地址并使用该地址来托管它.我无法弄清楚它是否可能或如何做到这一点.

有什么帮助吗?提前致谢.:)

.net wcf web-services inno-setup c#-4.0

5
推荐指数
1
解决办法
4762
查看次数

Inno Setup 循环遍历文件并注册每个 .NET dll

我正在使用 Inno Setup 创建一个安装文件,我需要使用 regasm.exe 文件注册未知数量的 .net dll。我知道我可以使用以下代码来注册 .net dll。

[Run]
Filename: "{dotnet20}\RegAsm.exe"; Parameters: /codebase MyDLL.dll; WorkingDir: {app}; StatusMsg: "Registering Controls."; Flags: runminimized
Run Code Online (Sandbox Code Playgroud)

我的问题是,文件夹中有多个 dll,我不知道要注册的每个 dll 的名称。有没有一种方法可以遍历文件夹中的文件并在不知道文件数量及其名称的情况下注册每个文件?

请帮忙,谢谢

.net c# dll inno-setup visual-studio-2010

4
推荐指数
1
解决办法
2174
查看次数

什么是有效的 RFC1123 日期格式

我正在开发一项返回 expires 标头的服务。该服务将跨不同时区工作。所以我们需要一种方法来返回 GMT 以外的其他时区。

我知道 http 标头必须遵循 RFC1123 标准日期格式。所以服务返回日期如下 -

2019 年 3 月 1 日星期五 15:00:00 GMT

我需要的是以以下格式返回日期。

2019 年 3 月 1 日星期五 15:00:00 +0530

这是 RFC1123 日期格式的有效日期吗?

datetime http datetimeoffset datetime-format rfc1123

3
推荐指数
1
解决办法
8794
查看次数