标签: wcf-configuration

服务没有应用程序(非基础结构)端点

我最近创建了一个WCF服务(dll)和一个服务主机(exe).我知道我的WCF服务正常工作,因为我能够成功地将服务添加到WcfTestClient.

但是,当我从服务主机(exe)使用我的WCF时,我似乎遇到了一个问题.我可以向我的服务主机(exe)添加对WCF(dll)的引用,并为exe创建必要的组件; 例如服务安装程序,服务主机和app.config,编译然后最后使用InstallUtil安装exe.但是,当我尝试在Microsoft管理控制台中启动该服务时,该服务在启动后立即停止.

所以我开始调查可能导致此问题的原因是从事件查看器中的应用程序日志中得出此错误.

描述:

服务无法启动.System.InvalidOperationException:服务"服务"具有零应用程序(非基础结构)端点.这可能是因为没有为您的应用程序找到配置文件,或者因为在配置文件中找不到与服务名称匹配的服务元素,或者因为在service元素中没有定义端点.

这个错误实际上是在OnStart; 当我执行此调用时,我的exe ServiceHost.Open().我看过很多其他人遇到过这个问题的帖子,但是大多数(如果不是全部的话)声称服务名称或合同; 命名空间和类名,未指定.我在配置文件中检查了这两个条目; 在exe和dll中,它们完美匹配.我已经让办公室里的其他人仔细检查我,以确保我不会在某一点上失明,但当然他们得出了与我相同的结论,即一切看起来都是正确的.对于此时发生的事情,我真的很迷茫.任何人都可以帮我解决这个问题吗?

另一件可能导致这种情况发生的原因是app.config永远不会被读取; 至少不是我认为应该阅读的那个.这可能是问题吗?如果是这样,我该如何解决这个问题.再次,任何帮助将不胜感激.

.net wcf exception-handling wcf-configuration wcf-endpoint

88
推荐指数
6
解决办法
11万
查看次数

如何以编程方式配置WCF已知类型?

我的客户端/服务器应用程序正在使用WCF进行通信,这非常棒.然而,当前架构的一个缺点是我必须对某些传输类型使用已知类型配置.我正在使用内部的Pub/Sub机制,这个要求是不可避免的.

问题是很容易忘记添加已知类型,如果你这样做,WCF会无声地失败,只有很少的线索可以解决出错的问题.

在我的应用程序中,我知道将要发送的类型集.我想以编程方式执行配置,而不是声明性地通过App.config当前包含这样的内容的文件:

<system.runtime.serialization>
  <dataContractSerializer>
    <declaredTypes>
      <add type="MyProject.MyParent, MyProjectAssembly">
        <knownType type="MyProject.MyChild1, MyProjectAssembly"/>
        <knownType type="MyProject.MyChild2, MyProjectAssembly"/>
        <knownType type="MyProject.MyChild3, MyProjectAssembly"/>
        <knownType type="MyProject.MyChild4, MyProjectAssembly"/>
        <knownType type="MyProject.MyChild5, MyProjectAssembly"/>
      </add>
    </declaredTypes>
  </dataContractSerializer>
</system.runtime.serialization>
Run Code Online (Sandbox Code Playgroud)

相反,我想做这样的事情:

foreach (Type type in _transmittedTypes)
{
    // How would I write this method?
    AddKnownType(typeof(MyParent), type);
}
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下我怎么做这个吗?

编辑请理解我正在尝试在运行时动态设置已知类型,而不是在配置中使用声明或使用源代码中的属性.

这基本上是关于WCF API的问题,而不是样式问题.

编辑2 此MSDN页面指​​出:

您还可以向ReadOnlyCollection添加类型,通过DataContractSerializer的KnownTypes属性访问.

不幸的是,只要KnownTypes是一个只读属性,并且属性的值是a,它就会说并且它没有多大意义ReadOnlyCollection.

.net wcf wcf-configuration known-types

52
推荐指数
3
解决办法
2万
查看次数

WCF:使用流式传输与消息合同

我正在尝试使用带有消息合同的WCF流,因为我需要在流本身旁边添加其他参数.

基本上我正在创建一个文件上传和下载服务,顶部还有一些额外的逻辑.

不幸的是,当我尝试从浏览器点击服务以检查一切正常时,我收到以下错误:

'/'应用程序中的服务器错误.合同'IFileTransferService'中的"UploadFile"操作使用具有SOAP头的MessageContract.None MessageVersion不支持SOAP标头.

不幸的是谷歌搜索它并没有产生任何帮助我的重要结果.你们能帮助我吗?这里是服务的细节(我已经删除了下载部分,因为空间的原因).

[ServiceContract(Namespace = "http://www.acme.org/2009/04")]
public interface IFileTransferService
{
    [OperationContract(Action = "UploadFile")]
    void UploadFile(FileUploadMessage request);
}

[MessageContract]
public class FileUploadMessage
{
    [MessageHeader(MustUnderstand = true)]
    public FileMetaData Metadata { get; set; }

    [MessageBodyMember(Order = 1)]
    public Stream FileByteStream { get; set; }
}

[DataContract(Namespace = "http://schemas.acme.org/2009/04")]
public class FileMetaData
{
    [DataMember(Name="FileType", Order=0, IsRequired=true)]
    public FileTypeEnum fileType;

    [DataMember(Name="localFilename", Order=1, IsRequired=false)]
    public string localFileName;

    [DataMember(Name = "remoteFilename", Order = 2, IsRequired = false)]
    public string remoteFileName;
}
Run Code Online (Sandbox Code Playgroud)

我试图使用basichttpbinding和customhttp绑定,但效果不佳:

<customBinding> …
Run Code Online (Sandbox Code Playgroud)

.net c# wcf wcf-binding wcf-configuration

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

WCF ConcurrencyMode Single和InstanceContextMode PerCall

我的wcf服务配置有问题.我希望每次调用我的服务都会创建一个新的服务实例.对于并发性,我希望一次调用在另一次启动之前完成.

因此,如果我有这样的服务:

[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Single,
InstanceContextMode=InstanceContextMode.PerCall)]
public class MyService: IMyService
{
    public bool MyServiceOp()
    {
        Debug.WriteLine("thread "+ 
            Thread.CurrentThread.ManagedThreadId.ToString());
        Debug.WriteLine("start operation ");
        Do_work()
        Debug.WriteLine("end operation");
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

当我在循环中调用多个调用时,跟踪给出:

thread 1
thread 2
start operation
start operation
end operation
end operation
Run Code Online (Sandbox Code Playgroud)

虽然我想这样:

thread 1 start operation end operation
thread 2 start operation end operation
Run Code Online (Sandbox Code Playgroud)

这可能吗?谢谢

c# wcf wcf-configuration servicebehavior

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

netsh http add urlacl:为组添加预留

本文介绍如何使用netsh.exe以下方式为用户配置命名空间预留:

netsh http add urlacl url = http:// +:80/MyUri user = DOMAIN\user

该参数user=被称为用户或用户组.
它的工作方式与我为单个用户配置时所描述的相同,但如果我替换DOMAN\userDOMAIN\Administrators或者DOMAIN\Users我收到错误(1332).

问:为什么它适用于用户,但不适用于组?组的语法是否不同?

操作系统:Vista 32位

注意:如果重要,计算机不属于域.

http wcf-configuration windows-vista netsh

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

netTCP绑定Soap安全协商失败

我正在写一个WCF服务需要模拟和会话.

我尝试在我的本地计算机上调用它时没关系,但是在远程计算机上它总是失败并出现这样的错误:

安全支持提供程序接口(SSPI)身份验证失败.服务器可能未在标识为"host/hostname"的帐户中运行.如果服务器正在服务帐户(例如,网络服务)中运行,请将该帐户的ServicePrincipalName指定为服务器的EndpointAddress中的标识.如果服务器在用户帐户中运行,请将该帐户的UserPrincipalName指定为服务器的EndpointAddress中的标识.

如果我提供了upn,它会抛出一个身份失败的异常.

这是我的配置:

服务器配置(APP):

<system.serviceModel>    
    <behaviors>
      <serviceBehaviors>
        <behavior name="default">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceAuthorization impersonateCallerForAllOperations="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <netTcpBinding>
        <binding name="DataService.netTcpBinding">
          <readerQuotas maxArrayLength="65535" maxBytesPerRead="2147483647" maxStringContentLength="2147483647"/>
          <reliableSession enabled="true" inactivityTimeout="24:00:00" ordered="true"/>          
          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="Windows" />
            <transport clientCredentialType="Windows"/>          
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    <services>
      <service behaviorConfiguration="default" name="DataService.DataService">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="DataService.netTcpBinding" 
          name="DataService.DataService" contract="DataService.IDataService"/>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://address:4504/"/>
            <add baseAddress="net.tcp://address:4503/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

客户端配置:

<?xml version="1.0" encoding="utf-8" ?> …
Run Code Online (Sandbox Code Playgroud)

c# wcf exception-handling wcf-security wcf-configuration

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

Silverlight + WCF异常:期待application/soap + xml,收到text/xml

我有一个Silverlight应用程序,我想在其中调用WCF服务.在调用服务时,我从服务器收到以下响应:

415无法处理消息,因为内容类型为'text/xml; charset = utf-8'不是预期的类型'application/soap + xml; 字符集= utf-8的

以前有没有人遇到过这个问题?有谁知道我需要调整哪些配置设置?任何有关如何解决这个问题的信息将不胜感激.

.net silverlight wcf exception-handling wcf-configuration

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

WCF客户端配置:如何检查端点是否在配置文件中,如果没有则回退到代码?

希望使客户端通过WCF将序列化的Message对象发送回服务器.

为了让最终开发人员(不同部门)更容易,他们不需要知道如何编辑他们的配置文件来设置客户端端点数据.

也就是说,端点也没有嵌入/硬编码到客户端也很棒.

在我看来,混合方案是推出的最简单的解决方案:

IF(在config中描述)USE配置文件ELSE回退到硬编码端点.

我发现的是:

  1. new Client(); 如果找不到配置文件定义,则会失败
  2. new Client(binding,endpoint); 作品

因此:

Client client;
try {
  client = new Client();
}catch {
  //Guess not defined in config file...
  //fall back to hard coded solution:
  client(binding, endpoint)
}
Run Code Online (Sandbox Code Playgroud)

但有没有办法检查(除了try/catch)以查看配置文件是否有一个端点声明?

如果在配置文件中定义,但上述配置是否也会失败,但配置不正确?区分这两个条件会好吗?

wcf wcf-client wcf-configuration

11
推荐指数
2
解决办法
5037
查看次数

servicePrincipalName应该有什么价值?

我正在尝试在我的服务上设置客户端模拟.

我需要为我的服务endPoint的servicePrincipalName设置一个值

我正在看这篇MSDN文章,但仍然无法弄明白

我的服务托管在服务器上的控制台应用程序中,我们称之为ServerName1.
Uri是:net.tcp://ServerName1:9990/TestService1/.

具体应该是我的servicePrincipalName是什么?

我试过了,没有任何喜悦:

<identity>
    <servicePrincipalName value="ServerName1" />
</identity>
Run Code Online (Sandbox Code Playgroud)

.net c# wcf wcf-configuration

11
推荐指数
2
解决办法
3万
查看次数

在服务实现的合同列表中找不到IMetaDataExchange

我已经在网上搜索了这个错误的解决方法,但我发现的一切都表明我所拥有的是正确的.

也许有人可以看一看并发现一个我看不见的明显错误.

我有一个Windows服务,托管两个合同:

  1. IConfigurationService
  2. IConfigurationAdminService

管理服务继承自标准服务,因为我希望两个合同都实现基本方法.

问题是我可以很好地托管服务,直到我尝试添加MEX.

然后我得到以下异常:

在服务'ConfigurationWCFService'实现的合同列表中找不到合同名称'IMetaDataExchange'.

这是我的配置,一切都是由配置配置,没有通过代码完成.

<system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="tcpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
          <security mode="None" />
        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="serviceBehavior" name="BrightsideGroup.Repa.Configuration.ConfigurationWCFService">
        <endpoint address="ConfigurationService" binding="netTcpBinding"
          bindingConfiguration="tcpBinding" name="tcpConfiguration" contract="BrightsideGroup.Repa.Configuration.IConfigurationWCFService" />
        <endpoint binding="mexHttpBinding" address="mex" name="mex" contract="IMetaDataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://GD01316:9123/Repa" />
            <add baseAddress="http://GD01316:8123/Repa" />
          </baseAddresses>
        </host>
      </service>
      <service behaviorConfiguration="serviceBehavior" name="BrightsideGroup.Repa.Configuration.ConfigurationWCFAdminService">
        <endpoint address="ConfigurationAdminService" binding="netTcpBinding"
          bindingConfiguration="tcpBinding" name="tcpConfigurationAdmin"
          contract="BrightsideGroup.Repa.Configuration.IConfigurationAdminWCFService" />
        <endpoint binding="mexHttpBinding" address="mex" name="mex" contract="IMetaDataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://GD01316:9124/Repa" />
            <add baseAddress="http://GD01316:8124/Repa" />
          </baseAddresses> …
Run Code Online (Sandbox Code Playgroud)

.net wcf exception-handling metadata wcf-configuration

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